/* Dark theme matching the desktop app: #151515 canvas, #1A1A1A chrome,
   #2A2A2A rows, blue #2B6CB0 accent, green/red status, orange auto-renew. */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #151515;
  --chrome: #1A1A1A;
  --row: #2A2A2A;
  --line: #333333;
  --text: #DDDDDD;
  --muted: #999999;
  --accent: #2B6CB0;
  --green: #4CAF50;
  --red: #E53935;
  --orange: #D97757;
  --danger: #8B0000;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  height: 100%;
}

button {
  font: inherit;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}
button.secondary { background: #444444; }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.45; cursor: default; }

input, select, textarea {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: #2B2B2B;
  border: 1px solid #3A3A3A;
  border-radius: 6px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }
textarea { min-height: 56px; resize: vertical; }

/* ---- login ---- */

#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#login-screen .card {
  background: var(--chrome);
  border-radius: 12px;
  padding: 28px 24px;
  width: min(340px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#login-screen h1 { font-size: 20px; }
#login-screen .hint { color: var(--muted); font-size: 13px; }
#login-error { color: var(--red); font-size: 13px; min-height: 1em; }

/* ---- app frame ---- */

#app { display: none; flex-direction: column; height: 100%; }

header {
  background: var(--chrome);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
header h1 { font-size: 17px; flex: 1; white-space: nowrap; }
header button { padding: 6px 12px; font-size: 14px; }

nav {
  background: var(--chrome);
  display: flex;
  gap: 6px;
  padding: 0 8px 10px;
  overflow-x: auto;
  scrollbar-width: thin;
}
nav button {
  background: transparent;
  color: var(--text);
  white-space: nowrap;
  font-size: 14px;
  padding: 6px 12px;
}
nav button.active { background: var(--accent); }

main { flex: 1; overflow-y: auto; padding: 12px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.section-head h2 { font-size: 16px; }

.segmented { display: flex; background: var(--row); border-radius: 8px; overflow: hidden; }
.segmented button { background: transparent; color: var(--muted); border-radius: 0; font-size: 13px; padding: 6px 12px; }
.segmented button.active { background: var(--accent); color: #fff; }

/* ---- subscription list ---- */

.sub-row {
  background: var(--row);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(140px, 2fr) repeat(6, minmax(70px, 1fr));
  gap: 4px 10px;
  align-items: center;
}
.sub-row:hover { outline: 1px solid #3E3E3E; }
.list-header {
  display: grid;
  grid-template-columns: minmax(140px, 2fr) repeat(6, minmax(70px, 1fr));
  gap: 4px 10px;
  padding: 0 12px 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.sub-row .name { font-weight: 600; }
.sub-row .active { color: var(--green); }
.sub-row .expired { color: var(--red); }
.sub-row .auto-yes { color: var(--orange); }
.cell-label { display: none; }

.grand-total {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  padding: 10px 12px;
}

.empty { color: #888888; text-align: center; padding: 28px 0; }

/* phone: rows become cards with labelled cells */
@media (max-width: 700px) {
  .list-header { display: none; }
  .sub-row { grid-template-columns: 1fr 1fr; }
  .sub-row .name { grid-column: 1 / -1; font-size: 16px; }
  .cell-label { display: block; color: var(--muted); font-size: 11px; }
}

/* ---- timeline chart ---- */

#chart-card {
  background: #1E1E1E;
  border-radius: 8px;
  margin-top: 14px;
  padding: 10px;
}
#chart-card h3 { font-size: 13px; margin-bottom: 8px; }
#chart-scroll { overflow-x: auto; }
#chart {
  position: relative;
  --label-w: 130px;
  --col-w: 64px;
  --row-h: 26px;
  --header-h: 24px;
  min-width: calc(var(--label-w) + 13 * var(--col-w));
}
.chart-month {
  position: absolute;
  top: 0;
  width: var(--col-w);
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}
.chart-grid-line { position: absolute; top: 0; width: 1px; background: var(--line); }
.chart-label {
  position: absolute;
  left: 0;
  width: var(--label-w);
  padding-right: 8px;
  font-size: 12px;
  line-height: var(--row-h);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-bar { position: absolute; height: calc(var(--row-h) - 4px); border-radius: 2px; }
.chart-dot { position: absolute; width: 8px; height: 8px; border-radius: 50%; }
.chart-arrow {
  position: absolute;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  height: calc(var(--row-h) - 4px);
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--col-w);
}
.chart-final {
  position: absolute;
  height: calc(var(--row-h) - 4px);
  width: var(--col-w);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.1;
  border-radius: 2px;
}
.chart-renew-bar { position: absolute; width: 8px; height: calc(var(--row-h) - 4px); background: var(--orange); }
.chart-renew-label {
  position: absolute;
  color: var(--orange);
  font-size: 10px;
  font-weight: 700;
  line-height: calc(var(--row-h) - 4px);
  white-space: nowrap;
}

/* ---- reports ---- */

.report-controls { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 14px; }
.report-controls .group h3 { font-size: 13px; margin-bottom: 6px; }
.report-controls label { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 14px; cursor: pointer; }
.report-controls input[type="radio"], .report-controls input[type="checkbox"],
#form-modal input[type="checkbox"] { width: auto; }
.report-buttons { display: flex; flex-direction: column; gap: 8px; justify-content: flex-start; }
#report-count { color: var(--muted); font-size: 13px; margin-bottom: 8px; }

.report-row, .report-header {
  display: grid;
  grid-template-columns: 1.2fr 1.6fr 0.7fr 1fr 0.8fr 0.8fr;
  gap: 4px 10px;
  padding: 8px 12px;
  align-items: center;
}
.report-header { color: var(--muted); font-size: 12px; font-weight: 600; padding-bottom: 4px; }
.report-row { background: var(--row); border-radius: 8px; margin-bottom: 4px; font-size: 14px; }
@media (max-width: 700px) {
  .report-header { display: none; }
  .report-row { grid-template-columns: 1fr 1fr; }
  .report-row .name { grid-column: 1 / -1; font-weight: 600; }
}

/* ---- add/edit modal ---- */

#form-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
}
#form-modal .sheet {
  background: var(--chrome);
  width: min(480px, 100vw);
  max-height: 100vh;
  overflow-y: auto;
  border-radius: 12px;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@media (max-width: 700px) {
  #form-modal { align-items: stretch; }
  #form-modal .sheet { border-radius: 0; max-height: none; }
}
#form-modal h2 { font-size: 17px; }
#form-modal label.field { display: block; font-size: 13px; color: var(--muted); }
#form-modal label.field > span { display: block; margin-bottom: 4px; }
.date-row { display: flex; gap: 6px; }
.date-row input[type="text"] { flex: 1; }
.date-row input[type="date"] { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.date-row button { padding: 6px 10px; background: #444444; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
#form-status { font-weight: 700; }
#form-error { color: var(--red); font-size: 13px; min-height: 1em; }
.form-buttons { display: flex; gap: 8px; }
.form-buttons button { flex: 1; }

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 60;
  max-width: 90vw;
}
#toast.show { opacity: 1; }
