/* The Calm Tech — calm, senior-friendly, high-contrast, large-tap.
   Single stylesheet, no build step. Responsive: phone (tabbar) → iPad/Mac (sidebar). */

:root {
  --bg:        #f3f6f8;
  --card:      #ffffff;
  --ink:       #1d2b32;
  --muted:     #5b6b73;
  --line:      #e2e8ec;
  --brand:     #2c6e7f;   /* calm teal */
  --brand-2:   #3d8a9c;
  --accent:    #c2772b;   /* warm amber for calls-to-action */
  --good:      #2f8a5b;
  --warn:      #c2772b;
  --bad:       #c0492f;
  --lead:      #b8860b;
  --shadow:    0 1px 3px rgba(20,40,50,.08), 0 6px 18px rgba(20,40,50,.06);
  --radius:    14px;
  --tap:       48px;
  --maxw:      1100px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
/* The HTML `hidden` attribute must beat author display rules (.lock/.app set display). */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
a { color: var(--brand); text-decoration: none; }

/* ---------- Lock screen ---------- */
.lock { position: fixed; inset: 0; display: grid; place-items: center;
        background: linear-gradient(160deg, #e8f0f2, #f3f6f8); padding: 24px; z-index: 50; }
.lock-card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
             padding: 32px 28px; width: min(360px, 92vw); text-align: center; }
.lock-input { width: 100%; font-size: 1.6rem; letter-spacing: .4em; text-align: center;
              padding: 14px; margin: 14px 0; border: 1px solid var(--line); border-radius: 12px; }
.lock-err { color: var(--bad); margin: 8px 0 0; }
.brand-mark { color: var(--brand); }

/* ---------- App frame ---------- */
.app { min-height: 100%; }
.main { padding: 16px; max-width: var(--maxw); margin: 0 auto;
        padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.main:focus { outline: none; }

/* Sidebar hidden on phone */
.sidebar { display: none; }
.sidebar-brand { font-weight: 700; font-size: 1.2rem; padding: 4px 12px 16px; display: flex; gap: 8px; align-items: center; }

/* Bottom tab bar (phone) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px;
       padding: 8px 2px; color: var(--muted); font-size: .68rem; min-height: var(--tap); }
.tab .ico { font-size: 1.25rem; }
.tab.active { color: var(--brand); font-weight: 600; }

/* ---------- Cards & lists ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
        box-shadow: var(--shadow); padding: 16px; margin: 0 0 14px; }
.card.tight { padding: 12px 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.grid { display: grid; gap: 12px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 2px 8px; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px;
             min-height: var(--tap); border: 1px solid transparent; }
.list-item:active { background: #eef3f5; }
.list-item + .list-item { border-top: 1px solid var(--line); border-radius: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-2); color: #fff;
          display: grid; place-items: center; font-weight: 700; flex: none; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
       min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
       background: var(--card); color: var(--ink); font-size: 1rem; font-weight: 600; cursor: pointer; }
.btn:active { transform: translateY(1px); }
.btn:disabled, button:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: .9rem; }

/* ---------- Badges / pills ---------- */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill.lead { background: #fbf0d6; color: #8a6400; }
.pill.active { background: #def0e6; color: #1f6b45; }
.pill.ongoing { background: #dde9f5; color: #2b5a86; }
.pill.subscription { background: #e8def5; color: #5a368a; }
.pill.inactive { background: #eceff1; color: #5b6b73; }
.pill.churned { background: #f6ded9; color: #8a3322; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 8px; background: #eef3f5;
       color: var(--muted); font-size: .75rem; margin: 2px 4px 2px 0; }

/* ---------- Forms ---------- */
label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 12px; border: 1px solid var(--line);
                          border-radius: 10px; background: #fff; color: var(--ink); }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border: 1px solid var(--line);
         border-radius: 12px; margin: 0 0 8px; min-height: var(--tap); }
.check input { width: 24px; height: 24px; flex: none; margin-top: 2px; }
.check .branch { color: var(--warn); font-size: .85rem; margin-top: 4px; }

/* ---------- Stepper (visit flow) ---------- */
.stepper { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; }
.step { flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
        background: #fff; font-size: .85rem; color: var(--muted); }
.step.done { background: #def0e6; border-color: #bfe3cf; color: #1f6b45; }
.step.current { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 14px; box-shadow: var(--shadow); }
.tile .n { font-size: 1.7rem; font-weight: 700; }
.tile .l { color: var(--muted); font-size: .82rem; }

/* ---------- Sync dot ---------- */
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.sync-dot.ok { background: var(--good); }
.sync-dot.off { background: var(--muted); }
.sync-dot.err { background: var(--bad); }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.back { font-size: 1.4rem; line-height: 1; padding: 4px 8px; }

/* ---------- Tablet / desktop ---------- */
@media (min-width: 760px) {
  .tabbar { display: none; }
  .app { display: grid; grid-template-columns: 232px 1fr; }
  .sidebar { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0;
             height: 100vh; padding: 18px 12px; border-right: 1px solid var(--line); background: var(--card); }
  .nav-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
              color: var(--ink); min-height: var(--tap); }
  .nav-link .ico { font-size: 1.2rem; }
  .nav-link.active { background: #e7f0f2; color: var(--brand); font-weight: 600; }
  .sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px 14px; }
  .main { padding: 28px; padding-bottom: 28px; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
}

/* Master–detail for clients on wide screens */
@media (min-width: 980px) {
  .split { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }
}
