/* ============================================================
   Charity Control Center — styles
   ============================================================ */

:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #e3e8e6;
  --border-strong: #cdd6d2;
  --text: #16211e;
  --text-muted: #62716c;
  --primary: #1f6f54;
  --primary-600: #195c46;
  --primary-tint: #e7f1ec;
  --accent: #e0a13a;

  --danger: #c8341f;
  --danger-tint: #fbe9e6;
  --warn: #b8730a;
  --warn-tint: #fbf0dc;
  --ok: #1f8a4c;
  --ok-tint: #e4f4ea;
  --info: #2563eb;
  --info-tint: #e7eefe;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 33, 30, .06), 0 6px 20px rgba(16, 33, 30, .06);
  --shadow-sm: 0 1px 2px rgba(16, 33, 30, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over elements that set their
   own display (e.g. #app and .auth-screen use display:grid). Without this,
   `el.hidden = true` would not actually hide them. */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--font); color: var(--text); background: var(--bg);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
button { font-family: inherit; }
a { color: var(--primary-600); }
.muted { color: var(--text-muted); }

/* ---------- auth screen ---------- */
.auth-screen {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #1f6f54 0%, #11352a 60%, #0c241c 100%);
}
.auth-card {
  width: min(420px, 100%); background: var(--surface); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); padding: 30px 28px;
}
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--primary); font-size: 14px; letter-spacing: .01em; }
.auth-mark { font-size: 18px; }
.auth-card h1 { font-size: 22px; margin: 16px 0 6px; }
.auth-card .muted { font-size: 13.5px; margin-bottom: 18px; }
.auth-card form { display: grid; gap: 14px; }
.auth-submit { width: 100%; justify-content: center; padding: 11px; font-size: 15px; margin-top: 2px; }
.auth-error { background: var(--danger-tint); color: var(--danger); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; font-weight: 500; }
.auth-foot { font-size: 12.5px; margin-top: 14px; }
/* password field with an inline reveal (eye) button */
.pw-wrap { position: relative; width: 100%; }
.pw-wrap input { width: 100%; padding-right: 42px; }
.pw-toggle { position: absolute; top: 0; right: 0; height: 100%; width: 40px; display: grid; place-items: center; background: transparent; border: 0; padding: 0; margin: 0; color: var(--text-muted); cursor: pointer; }
.pw-toggle:hover { color: var(--primary); }
.inline-form .pw-wrap { flex: 1; min-width: 160px; }

/* paste-import */
.import-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.import-dialog { width: min(640px, 94vw); }
.dialog-body.import-body { display: block; }
.import-cols { font-weight: 650; font-size: 13px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; margin: 8px 0; }
.import-text { width: 100%; min-height: 220px; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; line-height: 1.5; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px 12px; resize: vertical; margin: 8px 0; color: var(--text); }
.import-text:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.import-status { font-size: 13px; color: var(--text); min-height: 20px; }

/* ---------- layout ---------- */
#app { display: grid; grid-template-columns: 252px 1fr; height: 100vh; overflow: hidden; }
.sidebar { background: #11352a; color: #dfeae5; display: flex; flex-direction: column; padding: 18px 14px; gap: 6px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 16px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: rgba(255,255,255,.12); display: grid; place-items: center; font-size: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 13px; letter-spacing: .02em; text-transform: uppercase; color: #9fc4b6; font-weight: 700; }
.brand-text span { font-size: 16px; font-weight: 650; color: #fff; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-btn { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-radius: var(--radius-sm); background: transparent; color: #c5d6cf; cursor: pointer; font-size: 14.5px; font-weight: 500; transition: background .12s, color .12s; }
.nav-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-btn.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-btn .nav-ico { width: 20px; text-align: center; font-size: 16px; }
.nav-btn .nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; min-width: 19px; height: 19px; border-radius: 10px; padding: 0 6px; display: grid; place-items: center; }
.nav-btn.active .nav-badge { background: rgba(255,255,255,.25); }

.sidebar-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.1); }
.backup-status { grid-column: 1 / -1; font-size: 12px; color: #9fc4b6; padding: 0 4px 4px; }
.backup-status.stale { color: var(--accent); }
.whoami { grid-column: 1 / -1; font-size: 12px; color: #9fc4b6; padding: 8px 4px 4px; border-top: 1px solid rgba(255,255,255,.08); margin-top: 4px; }
.signout { grid-column: 1 / -1; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 16px 26px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 21px; }
.topbar-title p { font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.menu-toggle { display: none; }
.search { border: 1px solid var(--border-strong); border-radius: 20px; padding: 7px 14px; font-size: 14px; width: 210px; background: var(--surface-2); outline: none; transition: border-color .12s, box-shadow .12s; }
.search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); background: #fff; }
.content { flex: 1; overflow-y: auto; padding: 24px 26px 60px; }

/* ---------- buttons ---------- */
.btn { border: 1px solid transparent; border-radius: var(--radius-sm); padding: 9px 15px; font-size: 14px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: background .12s, border-color .12s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text-muted); }
.btn-sm { padding: 7px 11px; font-size: 13px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 18px; width: 36px; height: 36px; border-radius: 8px; color: var(--text-muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.sidebar-foot .btn-ghost { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.12); color: #dfeae5; }
.sidebar-foot .btn-ghost:hover { background: rgba(255,255,255,.16); }

/* ---------- dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat .stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .stat-value { font-size: 30px; font-weight: 700; margin-top: 6px; line-height: 1; }
.stat .stat-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }
.stat.alert .stat-value { color: var(--danger); }
.stat.warn .stat-value { color: var(--warn); }
.stat.ok .stat-value { color: var(--ok); }

.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 22px; overflow: hidden; }
.section-card > .sc-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.sc-head h2 { font-size: 16px; }
.sc-head .sc-count { font-size: 13px; color: var(--text-muted); margin-left: auto; }
.section-card > .sc-body { padding: 6px 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { display: flex; align-items: center; gap: 14px; padding: 13px 18px; border-bottom: 1px solid var(--border); cursor: pointer; }
.timeline-item:last-child { border-bottom: 0; }
.timeline-item:hover { background: var(--surface-2); }
.due-pill { flex-shrink: 0; min-width: 92px; text-align: center; font-size: 12px; font-weight: 700; padding: 5px 8px; border-radius: 7px; }
.due-overdue { background: var(--danger-tint); color: var(--danger); }
.due-soon { background: var(--warn-tint); color: var(--warn); }
.due-ok { background: var(--ok-tint); color: var(--ok); }
.due-info { background: var(--info-tint); color: var(--info); }
.timeline-main { flex: 1; min-width: 0; }
.timeline-main .t-title { font-weight: 600; }
.timeline-main .t-meta { font-size: 12.5px; color: var(--text-muted); }
.timeline-tag { font-size: 11px; font-weight: 600; color: var(--text-muted); background: var(--surface-2); border: 1px solid var(--border); padding: 3px 9px; border-radius: 20px; white-space: nowrap; }

.flag-list { list-style: none; margin: 0; padding: 0; }
.flag-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.flag-item:last-child { border-bottom: 0; }
.flag-item.clickable { cursor: pointer; }
.flag-item.clickable:hover { background: var(--surface-2); }
.flag-ico { font-size: 16px; line-height: 1.4; }
.flag-text { flex: 1; }
.flag-text strong { font-weight: 650; }
.flag-text .flag-sub { font-size: 12.5px; color: var(--text-muted); }

.empty-good { padding: 26px 18px; text-align: center; color: var(--ok); font-weight: 600; }
.empty-good span { display: block; font-size: 26px; margin-bottom: 6px; }

.seed-note { display: flex; align-items: center; gap: 10px; background: var(--info-tint); color: #1c3d80; border: 1px solid #c7d8fb; border-radius: var(--radius-sm); padding: 11px 14px; margin-bottom: 18px; font-size: 13.5px; }
.seed-note button { margin-left: auto; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--surface); z-index: 1; }
table.grid td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid tr:hover td { background: var(--surface-2); }
table.grid tr:last-child td { border-bottom: 0; }
.cell-primary { font-weight: 600; }
.cell-muted { color: var(--text-muted); }
.cell-center { text-align: center; padding: 30px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; }
.row-actions .icon-btn { width: 30px; height: 30px; font-size: 14px; }
td .link { word-break: break-all; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.chip-ok { background: var(--ok-tint); color: var(--ok); }
.chip-no { background: var(--danger-tint); color: var(--danger); }
.chip-warn { background: var(--warn-tint); color: var(--warn); }
.chip-neutral { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.chip-info { background: var(--info-tint); color: var(--info); }
.chip-link { background: var(--info-tint); color: var(--info); border: 0; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 3px; }
.chip-link:hover { background: #d7e3fd; }

/* password / secret cells */
.secret-cell { white-space: nowrap; }
.secret-val { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; letter-spacing: .5px; vertical-align: middle; }
.secret-btn { width: 26px; height: 26px; font-size: 13px; vertical-align: middle; }

/* domain lookup row in the editor */
.lookup-row { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 11px 12px; gap: 8px; }
.lookup-row .btn { align-self: flex-start; }

.date-cell { white-space: nowrap; }
.date-cell .days { display: block; font-size: 11.5px; margin-top: 2px; }
.days.overdue { color: var(--danger); font-weight: 600; }
.days.soon { color: var(--warn); font-weight: 600; }
.days.ok { color: var(--text-muted); }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty .empty-ico { font-size: 40px; margin-bottom: 12px; }
.empty h3 { font-size: 17px; color: var(--text); margin-bottom: 6px; }
.empty p { max-width: 380px; margin: 0 auto 16px; }

/* ---------- settings ---------- */
.settings-body { padding: 16px 18px; }
.settings-body p { font-size: 13.5px; color: var(--text-muted); margin-bottom: 14px; max-width: 560px; }
.settings-body .stack { display: grid; gap: 12px; max-width: 360px; }
.btn-row, .inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline-form { margin-top: 14px; }
.inline-form input, .inline-form select { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px; font-size: 14px; font-family: inherit; }
.inline-form input { flex: 1; min-width: 140px; }

/* ---------- dialog ---------- */
.dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--text); }
.dialog::backdrop { background: rgba(16, 33, 30, .45); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 17px; flex: 1; }
.dialog-body { padding: 18px 20px; max-height: 64vh; overflow-y: auto; display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px; font-size: 14px; font-family: inherit; color: var(--text); background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.field textarea { resize: vertical; min-height: 60px; }
.field .hint { font-size: 11.5px; color: var(--text-muted); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #11352a; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 252px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-toggle { display: grid; }
  .dialog-body { grid-template-columns: 1fr; }
  .search { width: 150px; }
  .content { padding: 18px 16px 60px; }
}

/* ---------- print ---------- */
@media print {
  .sidebar, .topbar-actions, .menu-toggle, .row-actions, .seed-note, .toast, .auth-screen { display: none !important; }
  #app { display: block; height: auto; }
  .content { overflow: visible; padding: 0; }
  .topbar { border: 0; padding: 0 0 12px; }
  body { background: #fff; font-size: 12px; }
  .section-card, .stat { box-shadow: none; break-inside: avoid; }
  table.grid th { position: static; }
  .print-header { display: block !important; margin-bottom: 16px; }
}
.print-header { display: none; }
