/* Client Visits — mobile-first styles.
   Light palette defined on :root; dark redefines only the tokens. */

/* Palette taken from the CareMatrix logo: a navy-to-teal-to-green gradient.
   Every value below clears 4.5:1 against its own surface in both modes. */
:root {
  color-scheme: light;
  --bg:        #f2f5f9;
  --surface:   #ffffff;
  --surface-2: #eef2f7;
  --border:    #dde5ee;
  --text:      #0d1424;
  --text-2:    #4a5568;
  --text-3:    #8592a6;

  --navy:      #0a2a6e;   /* logo wordmark blue  */
  --accent:    #12559e;   /* primary action      */
  --teal:      #0e7c7b;   /* logo mid-gradient   */
  --brand-green:#0b7a3c;  /* logo M              */
  --accent-ink:#ffffff;
  --gradient:  linear-gradient(118deg, #0a2a6e 0%, #12559e 42%, #0e7c7b 78%, #0b7a3c 100%);

  --good:      #0b7a3c;
  --warn:      #a45b00;
  --danger:    #c1362f;
  --violet:    #4a3aa7;

  --shadow:    0 1px 2px rgba(10,42,110,.05), 0 4px 14px rgba(10,42,110,.06);
  --shadow-lg: 0 2px 6px rgba(10,42,110,.07), 0 12px 30px rgba(10,42,110,.10);
  --r:         14px;
  --tab-h:     64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg:        #0f1216;
    --surface:   #16191d;
    --surface-2: #1e232a;
    --border:    #2b323b;
    --text:      #eef2f7;
    --text-2:    #aab6c6;
    --text-3:    #7c8899;

    --navy:      #7ea6e8;
    --accent:    #5b96e0;
    --teal:      #2fae9e;
    --brand-green:#3fae67;
    --accent-ink:#0b0f14;
    --gradient:  linear-gradient(118deg, #123a86 0%, #175ba8 42%, #12807c 78%, #128046 100%);

    --good:      #3fae67;
    --warn:      #e0a33c;
    --danger:    #ef6b64;
    --violet:    #9085e9;

    --shadow:    0 1px 2px rgba(0,0,0,.45);
    --shadow-lg: 0 8px 28px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.muted { color: var(--text-2); }
.error { color: var(--danger); font-size: .9rem; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ setup */
.setup { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.setup-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 22px; box-shadow: var(--shadow);
}
.setup-card h1 { font-size: 1.25rem; margin-bottom: 6px; color: var(--navy); }
.setup-card p { margin: 0 0 18px; font-size: .92rem; }
.setup-card label { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: 14px; }

/* ----------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; flex: 1; }
.brand-mark { flex: none; width: 28px; height: 28px; object-fit: contain; }

.sync {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 6px 4px; cursor: pointer;
  color: var(--text-3); font-size: .78rem; font-family: inherit;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.dot.pending { background: var(--warn); }
.dot.offline { background: var(--text-3); }
.dot.busy    { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

.banner {
  margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px;
  font-size: .88rem; border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 10%, transparent); color: var(--text);
}
.banner.bad { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ------------------------------------------------------------- main */
main { padding: 12px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px); max-width: 640px; margin: 0 auto; }
.view > * + * { margin-top: 14px; }

/* ------------------------------------------------------ alert strips */
.alert-strip {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-radius: var(--r); margin-bottom: 10px;
  font-size: .92rem; border: 1px solid transparent;
}
.alert-strip b { font-weight: 700; }
.alert-strip.demo {
  background: var(--gradient); color: #fff; box-shadow: var(--shadow);
}
.alert-strip.due {
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn);
}
.alert-strip.late {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger);
}

/* ------------------------------------------------------------ tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px 10px; text-align: center;
}
.tile { box-shadow: var(--shadow); }
.tile b {
  display: block; font-size: 1.75rem; line-height: 1.1; font-weight: 700;
  letter-spacing: -.03em; color: var(--navy);
}
.tile span { font-size: .72rem; color: var(--text-2); }
.tile.alert b { color: var(--danger); }
.tile.due b   { color: var(--warn); }

/* ------------------------------------------------------------ cards */
.group-title {
  font-size: .76rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); margin: 22px 0 9px; font-weight: 700;
}
.group-title.accent { color: var(--teal); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 14px; box-shadow: var(--shadow); margin-bottom: 10px;
}
.card { transition: box-shadow .18s ease, transform .18s ease; }
.card.late { border-left: 3px solid var(--danger); }
.card.now  { border-left: 3px solid var(--warn); }
/* border-image paints all four sides, so use a pseudo-element for a clean
   left-edge accent instead. */
.card.demo-row {
  position: relative; overflow: hidden; padding-left: 18px;
  border-color: color-mix(in srgb, var(--navy) 22%, var(--border));
  box-shadow: var(--shadow-lg);
}
.card.demo-row::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--gradient);
}
.card.demo .card-name { color: var(--navy); }

.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-name { font-weight: 650; font-size: 1.02rem; }
.card-when { font-size: .76rem; color: var(--text-3); white-space: nowrap; }
.card-when.late { color: var(--danger); font-weight: 600; }
.card-meta { font-size: .84rem; color: var(--text-2); margin-top: 3px; }
.card-note {
  font-size: .88rem; color: var(--text-2); margin-top: 8px;
  padding-left: 10px; border-left: 2px solid var(--border);
}
.card-actions { display: flex; gap: 8px; margin-top: 12px; }
.card-actions .btn { flex: 1; }

.empty { text-align: center; color: var(--text-3); padding: 34px 16px; font-size: .92rem; }

/* -------------------------------------------------------- badges/chips */
.badge { display: inline-block; font-size: .7rem; padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.badge { letter-spacing: .01em; }
.badge.action {
  background: color-mix(in srgb, var(--teal) 14%, transparent); color: var(--teal);
}
.badge.action.is-demo { background: var(--gradient); color: #fff; }
.badge.New          { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.badge.Contacted    { background: color-mix(in srgb, var(--warn) 15%, transparent);   color: var(--warn); }
.badge.Followup     { background: color-mix(in srgb, #eda100 20%, transparent);        color: #a06d00; }
.badge.Proposalsent { background: color-mix(in srgb, var(--violet) 15%, transparent); color: var(--violet); }
.badge.Won          { background: color-mix(in srgb, var(--good) 15%, transparent);   color: var(--good); }
.badge.Lost         { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
@media (prefers-color-scheme: dark) { .badge.Followup { color: #eda100; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-size: .85rem;
  font-family: inherit; cursor: pointer;
}
.chip.on { background: var(--gradient); border-color: transparent; color: #fff; font-weight: 600; }

/* ------------------------------------------------------------ forms */
label { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: 14px; font-weight: 500; }
input, select, textarea {
  width: 100%; margin-top: 5px; padding: 12px; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  /* Date and time inputs have a minimum intrinsic width set by the browser,
     which is wider than a narrow grid column. Without min-width:0 they refuse
     to shrink and spill over the field beside them. */
  min-width: 0; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 96px; resize: vertical; }
/* minmax(0, 1fr) rather than 1fr: a bare 1fr track has an implicit min of
   auto, which lets a wide date input force the column open. */
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.row > label { min-width: 0; }

/* On very narrow phones two date-ish fields never fit side by side. Stack. */
@media (max-width: 370px) {
  .row { grid-template-columns: 1fr; gap: 0; }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: .92rem;
  font-weight: 550; cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn:active { transform: scale(.985); }
.btn-primary {
  background: var(--gradient); border-color: transparent; color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--navy) 28%, transparent);
  font-weight: 600;
}
.btn-primary:active { box-shadow: none; }
.btn-danger  { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-block   { width: 100%; }
.btn-icon {
  background: none; border: 0; color: var(--text-2); font-size: 1.2rem;
  padding: 8px 10px; cursor: pointer; line-height: 1;
}

.searchbar input { margin-top: 0; }

label.check {
  display: flex; align-items: center; gap: 10px; margin: 4px 0 16px;
  font-size: .9rem; color: var(--text-2);
}
label.check input {
  width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent);
}

/* Quick-log hint under the name field */
.hint { font-size: .8rem; margin: -8px 0 14px; min-height: 1.15em; font-weight: 500; }
.hint.known { color: var(--good); }
.hint.new   { color: var(--accent); }

/* "Just logged" strip */
.mini {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
}
.mini b { display: block; font-size: .95rem; }
.mini span { font-size: .8rem; color: var(--text-2); }

/* While a field is focused the on-screen keyboard covers the bottom of the
   viewport, and a position:fixed tab bar ends up sitting on top of whatever
   you are typing into. Take it out of the way until the field is done. */
body.editing .tabbar { display: none; }
body.editing main    { padding-bottom: 32px; }

/* Leave room when the browser scrolls a focused field into view. */
input, select, textarea { scroll-margin-bottom: 140px; scroll-margin-top: 76px; }

/* ------------------------------------------------------------ sheet */
.sheet {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: flex; flex-direction: column; animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateY(14px); opacity: .4 } to { transform: none; opacity: 1 } }
.sheet-head {
  display: flex; align-items: center; gap: 6px; padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex: none;
}
.sheet-head h2 { font-size: 1.05rem; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 28px); max-width: 640px; width: 100%; margin: 0 auto; }

/* --------------------------------------------------------- timeline */
.entry { border-left: 2px solid var(--border); padding: 0 0 16px 14px; position: relative; }
.entry::before {
  content: ""; position: absolute; left: -5px; top: 5px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}
.entry-head { font-size: .82rem; color: var(--text-3); }
.entry-body { font-size: .92rem; margin-top: 2px; white-space: pre-wrap; }

/* ------------------------------------------------------------ chart */
.bar-row { display: grid; grid-template-columns: 96px 1fr 28px; align-items: center; gap: 10px; margin-bottom: 8px; font-size: .84rem; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-val { text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }

.build { text-align: center; color: var(--text-3); font-size: .72rem; margin: 18px 0 0; }

/* ----------------------------------------------------------- tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 0; padding: 9px 0 8px; height: var(--tab-h);
  color: var(--text-3); font: inherit; font-size: .68rem; cursor: pointer;
}
.tab .ico { font-size: 1.25rem; line-height: 1; }
.tab.is-active { color: var(--accent); font-weight: 650; }
.tab.is-active::after {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--gradient);
}
.pill {
  position: absolute; top: 5px; left: 50%; margin-left: 6px;
  background: var(--danger); color: #fff; font-size: .62rem; font-weight: 700;
  min-width: 17px; height: 17px; line-height: 17px; text-align: center;
  border-radius: 9px; padding: 0 4px;
}

/* ------------------------------------------------------------ toast */
/* Anchored to the top: the bottom of a phone screen belongs to the keyboard,
   and a toast down there lands on the field you are still filling in. */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 9px); z-index: 60;   /* over the header, never over a field */
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 22px;
  font-size: .88rem; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
