/* ---- Theme tokens ---- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #e3e6ea;
  --text: #1c2127;
  --muted: #6b7480;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  --radius: 10px;

  --ok: #16a34a; --ok-bg: #e7f6ec;
  --upcoming: #ca8a04; --upcoming-bg: #fbf3d5;
  --due: #ea580c; --due-bg: #fdece0;
  --overdue: #dc2626; --overdue-bg: #fde4e4;
  --none: #6b7480; --none-bg: #eef0f2;
  --cancel: #94a3b8; --cancel-bg: #eef0f2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1e242c; --border: #2a313a;
    --text: #e6e9ee; --muted: #9aa4b0; --primary: #3b82f6; --shadow: none;
    --ok-bg:#132a1c; --upcoming-bg:#2c2510; --due-bg:#2e1c10; --overdue-bg:#2e1414;
    --none-bg:#1e242c; --cancel-bg:#1e242c;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 1.25rem;
  padding: .6rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .35rem; flex: 1; flex-wrap: wrap; }
.nav a {
  padding: .35rem .7rem; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--primary); color: var(--primary-ink); }
.logout { margin: 0; }

/* ---- Layout ---- */
.container { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.container-wide { max-width: 1400px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.section-title { margin: 1.5rem 0 .75rem; }
.toolbar { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar .btn { margin-left: auto; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; cursor: pointer;
  border: 1px solid transparent; border-radius: 8px; padding: .5rem .9rem;
  font-size: .92rem; font-weight: 600; font-family: inherit; line-height: 1;
  background: var(--surface-2); color: var(--text);
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--overdue-bg); }
.btn-sm { padding: .38rem .65rem; font-size: .85rem; }
.btn-xs { padding: .25rem .5rem; font-size: .78rem; }
.inline { display: inline; margin: 0; }

/* ---- Cards / forms ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}
.stack { display: flex; flex-direction: column; gap: .9rem; }
.stack > .btn { align-self: flex-start; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
input, select, textarea {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text); font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type=color] { padding: .2rem; height: 2.4rem; width: 3.5rem; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid .col-2 { grid-column: 1 / -1; }
.checkbox { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
.checkbox input { width: auto; }
.color-field { display: flex; align-items: center; gap: .6rem; }
.form-actions { display: flex; gap: .6rem; align-items: center; }

/* ---- Flash / notes ---- */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-weight: 500; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--overdue-bg); color: var(--overdue); }
.note-box { background: var(--surface-2); border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1rem; white-space: pre-wrap; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.data th, table.data td { padding: .7rem .85rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); cursor: pointer; user-select: none; }
table.data thead th:not([data-sort]) { cursor: default; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions-col { text-align: right; white-space: nowrap; }
.row-muted { opacity: .55; }
.row-accent td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

/* ---- Chips / tags / badges ---- */
.chip { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; vertical-align: middle; margin-right: .5rem; }
.chip.lg { width: 1.1rem; height: 1.1rem; }
.client-cell { display: inline-flex; align-items: center; color: var(--text); font-weight: 600; }
.tag { display: inline-block; padding: .1rem .45rem; border-radius: 6px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); color: var(--muted); margin-left: .4rem; }
.tag-hosting { background: #dbeafe; color: #1e40af; }
.tag-domain { background: #dcfce7; color: #166534; }
.tag-plugin { background: #f3e8ff; color: #6b21a8; }
.tag-service { background: #fef9c3; color: #854d0e; }
@media (prefers-color-scheme: dark) {
  .tag-hosting { background: #1e3a5f; color: #93c5fd; }
  .tag-domain { background: #14401f; color: #86efac; }
  .tag-plugin { background: #3b1f5f; color: #d8b4fe; }
  .tag-service { background: #3f3410; color: #fde047; }
}

.badge { display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge .dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.badge-sub { opacity: .7; font-weight: 500; }
.st-ok { color: var(--ok); background: var(--ok-bg); }
.st-upcoming { color: var(--upcoming); background: var(--upcoming-bg); }
.st-due-soon { color: var(--due); background: var(--due-bg); }
.st-overdue { color: var(--overdue); background: var(--overdue-bg); }
.st-none { color: var(--none); background: var(--none-bg); }
.st-cancelled { color: var(--cancel); background: var(--cancel-bg); }

/* ---- Summary grand totals ---- */
.grand-totals { display: flex; gap: 1rem; }
.gt { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem 1rem; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.gt strong { font-size: 1.15rem; }
.gt-combined { border-color: var(--primary); }
.gt-combined strong { color: var(--primary); }

/* ---- Client cards ---- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem; }
.client-card { display: flex; gap: .8rem; align-items: flex-start; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); }
.client-card:hover { text-decoration: none; border-color: var(--primary); }
.cc-name { font-weight: 700; }
.cc-meta { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: .4rem; font-size: .85rem; color: var(--muted); }

/* ---- Client detail ---- */
.client-title { display: flex; gap: .8rem; align-items: center; }
.head-actions { display: flex; gap: .5rem; }
.totals-row { display: flex; gap: .8rem; flex-wrap: wrap; margin-bottom: .5rem; }
.total-pill { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .55rem 1rem; display: flex; flex-direction: column; box-shadow: var(--shadow); min-width: 120px; }
.total-pill strong { font-size: 1.1rem; }

.sub-list { display: flex; flex-direction: column; gap: .5rem; }
.sub-item { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); flex-wrap: wrap; }
.sub-item.is-cancelled { opacity: .6; }
.sub-name { font-size: 1rem; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.sub-meta { margin-top: .25rem; }
.sub-side { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.sub-actions { display: flex; gap: .3rem; }
.edit-slot { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: -.25rem 0 .25rem; }

.sub-form .sub-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; }
.sub-form .col-span { grid-column: 1 / -1; }
.sub-form .form-actions { margin-top: .8rem; }
.add-service { margin-top: 1.25rem; }
.add-service > summary { display: inline-flex; list-style: none; }
.add-service > summary::-webkit-details-marker { display: none; }
.add-service-body { margin-top: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }

/* ---- Filter chips (renewals) ---- */
.filter-chips { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip-link { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: .88rem; }
.chip-link:hover { text-decoration: none; border-color: var(--primary); }
.chip-link.active { outline: 2px solid var(--primary); }
.chip-link .c { font-variant-numeric: tabular-nums; opacity: .8; margin-left: .2rem; }

/* ---- Misc ---- */
.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); display: flex; flex-direction: column; gap: 1rem; align-items: center; }
.input-search { min-width: 240px; }
.filter-select { min-width: 150px; }
.toolbar #r-count { margin-left: auto; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.email-settings { margin-top: 1rem; }
.email-settings code { background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; font-size: .9em; }
.reminder-groups { display: flex; flex-direction: column; gap: .8rem; }
.reminder-group { padding: 1rem 1.25rem; }
.rg-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.rg-client { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.rg-client a { color: var(--text); display: inline-flex; align-items: center; }
.rg-action { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.rg-lines { list-style: none; margin: .75rem 0 0; padding: .75rem 0 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .4rem; }
.rg-lines li { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.rg-svc { font-weight: 600; }

.inactive-section { margin-top: 1.25rem; }
.inactive-section > summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: .5rem 0; }
.inactive-section > summary:hover { color: var(--text); }
.inactive-section .table-wrap { margin-top: .5rem; }

/* ---- Auth ---- */
.auth-card { max-width: 380px; margin: 8vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); text-align: center; }
.auth-card h1 { margin-bottom: .25rem; }
.auth-card form { text-align: left; margin-top: 1.25rem; }
.auth-card .btn-primary { width: 100%; justify-content: center; }

@media (max-width: 720px) {
  .form-grid, .settings-grid { grid-template-columns: 1fr; }
  .sub-form .sub-grid { grid-template-columns: 1fr 1fr; }
  .nav { order: 3; width: 100%; }
}
