:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #e6e3dc;
  --text: #1c1b19;
  --muted: #6d6a63;
  --accent: #0f766e;
  --accent-soft: #e0f2ef;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --warn: #a15c07;
  --warn-soft: #fdf3e2;
  --bday: #9d3c8c;
  --bday-soft: #f8e9f5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 18, 14, 0.05), 0 4px 16px rgba(20, 18, 14, 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1d1c1a;
    --surface-2: #232220;
    --line: #34322e;
    --text: #efede8;
    --muted: #a19d94;
    --accent: #2dd4bf;
    --accent-soft: #13332f;
    --danger: #f97066;
    --danger-soft: #3a1b18;
    --warn: #fdb022;
    --warn-soft: #36290f;
    --bday: #f0a3e2;
    --bday-soft: #3a1f36;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 4px; }
h3 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; margin: 0; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack { display: grid; gap: 12px; }

/* Buttons & inputs */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 500; padding: 8px 14px;
  border-radius: 9px; cursor: pointer; white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062320; } }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-weight: 500; font-size: 13px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
textarea { min-height: 80px; resize: vertical; }

/* Boot & auth */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.portal { min-height: 100%; display: grid; grid-template-columns: 1.1fr 0.9fr; }
.portal-story { display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 48px 56px; background: #0f766e; color: #f4fffc; }
.portal-story h1 { font-size: 42px; letter-spacing: -0.03em; }
.portal-kicker { margin: 0; text-transform: uppercase; letter-spacing: 0.12em; font-size: 12px; font-weight: 600; color: #b7ebe3; }
.portal-story p { margin: 0; max-width: 440px; font-size: 16px; line-height: 1.55; }
.portal-logo { width: 72px; height: 72px; border-radius: 18px; object-fit: cover; }
.portal .auth-card { margin: auto; }
.logo-img { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
@media (max-width: 800px) {
  .portal { grid-template-columns: 1fr; }
  .portal-story { padding: 32px 24px; }
  .portal-story h1 { font-size: 32px; }
  .portal .auth-card { margin: 24px 16px 32px; }
}
.auth-links { display: flex; justify-content: flex-end; font-size: 13px; }
.portal-contact { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.portal-contact a { font-weight: 600; }
.btn.google { width: 100%; }

/* Shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 0 8px; }
.brand.big { font-size: 20px; padding: 0; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 16px; }
#nav { display: grid; gap: 2px; }
#nav button { display: flex; align-items: center; gap: 10px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 500; padding: 9px 10px; border-radius: 9px; cursor: pointer; text-align: left; }
#nav button:hover { background: var(--surface-2); color: var(--text); }
#nav button.active { background: var(--accent-soft); color: var(--accent); }
#nav .ico { width: 18px; text-align: center; }
.badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.me { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.me-name { font-weight: 600; }
.me-role { color: var(--muted); text-transform: capitalize; margin-bottom: 4px; }
main { padding: 28px 32px 60px; min-width: 0; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* Cards & lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; }
.card-body { padding: 4px 16px 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stat-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.stat b { display: block; font-size: 32px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.missed b { color: #b91c1c; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: none; font: inherit; font-weight: 500; color: var(--muted); padding: 5px 11px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.list { display: grid; }
.item { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 11px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface-2); }
.item .title { font-weight: 600; display: flex; align-items: center; gap: 6px; min-width: 0; }
.item .title .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.item .title .tag { flex: none; }
.item .sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .right { text-align: right; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; background: var(--surface-2); border: 1px solid var(--line); }
.dot.missed { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.dot.in { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot.bday { background: var(--bday-soft); color: var(--bday); border-color: transparent; }
.dot.cb { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.tag.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag.amber { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.teal { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag.pink { background: var(--bday-soft); color: var(--bday); border-color: transparent; }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); }
.group-label { padding: 12px 16px 4px; }

/* Notes */
.note { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.note + .note { margin-top: 8px; }
.note-text { white-space: pre-wrap; word-break: break-word; }
.note-meta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Modal */
dialog { border: 0; padding: 0; border-radius: 16px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
dialog::backdrop { background: rgba(15, 14, 12, 0.45); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 22px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 16px 22px 22px; display: grid; gap: 18px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kv div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.kv b { display: block; font-size: 11.5px; color: var(--muted); font-weight: 500; }
.section { display: grid; gap: 10px; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal .dow { padding: 8px; font-size: 12px; font-weight: 600; color: var(--muted); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface-2); }
.cal .day { min-height: 104px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal .day.other { background: var(--surface-2); color: var(--muted); }
.cal .day.today .num { background: var(--accent); color: #fff; }
.cal .num { font-size: 12px; font-weight: 600; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.chip { font-size: 11.5px; border-radius: 6px; padding: 2px 6px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; text-align: left; font-family: inherit; }
.chip.bday { background: var(--bday-soft); color: var(--bday); }
.chip.cb { background: var(--warn-soft); color: var(--warn); }
.cal-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; border-top: 0; }
td select, td input { min-width: 120px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); color: #fff; }

/* Responsive */
.mobile-signout { display: none !important; }
@media (max-width: 1100px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .cal-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; padding: 6px; border-right: 0; border-top: 1px solid var(--line); z-index: 20; }
  .sidebar .brand, .sidebar .me { display: none; }
  #nav { display: flex; width: 100%; justify-content: space-around; }
  #nav button { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; position: relative; }
  #nav .badge { position: absolute; top: 0; right: 0; margin: 0; }
  main { padding: 18px 16px 90px; }
  .grid3, .grid2 { grid-template-columns: 1fr; }
  .cal .day { min-height: 64px; }
  .cal .chip span { display: none; }
  .item { grid-template-columns: 30px 1fr auto; padding: 10px 12px; }
  .toolbar input[type=search] { max-width: none; }
  .mobile-signout { display: inline-flex !important; }
}
