/* ==========================================================================
   Journal: iPhone-native layer. Loaded LAST. System font, iOS system colours (light + dark), large titles that scroll
   away, a frosted tab bar, grouped lists, sheets with a grabber and a spring, iOS-style buttons, fields and switches.
   Everything here is tokens + a small set of overrides; no inline styles (CSP).
   ========================================================================== */

/* ---- 1. tokens: iOS system colours, light and dark ---- */
:root{
  color-scheme:light dark;
  --ds-font:-apple-system,BlinkMacSystemFont,"SF Pro Text","SF Pro Display",system-ui,"Segoe UI",Roboto,sans-serif;
  --ds-brand:#007aff;--ds-brand-hover:#006ee6;--ds-brand-press:#0062cc;--ds-brand-soft:#e5f1ff;--ds-brand-soft-2:#cfe4ff;--ds-brand-ring:rgba(0,122,255,.3);
  --ds-bg:#f2f2f7;--ds-surface:#ffffff;--ds-surface-2:#f2f2f7;--ds-surface-3:#e5e5ea;
  --ds-border:#e0e0e6;--ds-border-strong:#c7c7cc;--ds-divider:#e5e5ea;
  --ds-text:#000000;--ds-text-2:#3c3c43;--ds-muted:#6c6c70;--ds-faint:#aeaeb2;
  --ds-success:#248a3d;--ds-success-soft:#e3f5e8;--ds-warning:#b25e09;--ds-warning-soft:#fdf1de;--ds-danger:#d70015;--ds-danger-soft:#ffe9ea;--ds-info:#0a60d0;--ds-info-soft:#e5f0ff;
  --ds-glass:rgba(249,249,251,.97);--ds-glass-line:rgba(60,60,67,.18);--ds-grabber:rgba(60,60,67,.3);--ds-scrim:rgba(0,0,0,.4);
  --ds-tint:rgba(0,122,255,.12);--ds-tint-red:rgba(215,0,21,.1);
  --ds-sh-xs:none;--ds-sh-sm:0 1px 2px rgba(0,0,0,.04);--ds-sh-md:0 8px 24px -6px rgba(0,0,0,.18);--ds-sh-lg:0 20px 48px -12px rgba(0,0,0,.3);
  --ds-r:10px;--ds-r-lg:12px;--ds-r-xl:14px;
  --ds-nav:#1c1c1e;
}
@media(prefers-color-scheme:dark){
  :root{
    --ds-brand:#0a84ff;--ds-brand-hover:#2f95ff;--ds-brand-press:#5aa9ff;--ds-brand-soft:#0b2a4d;--ds-brand-soft-2:#10396b;--ds-brand-ring:rgba(10,132,255,.45);
    --ds-bg:#000000;--ds-surface:#1c1c1e;--ds-surface-2:#2c2c2e;--ds-surface-3:#3a3a3c;
    --ds-border:#38383a;--ds-border-strong:#48484a;--ds-divider:#38383a;
    --ds-text:#ffffff;--ds-text-2:#ebebf5;--ds-muted:#98989f;--ds-faint:#636366;
    --ds-success:#30d158;--ds-success-soft:#0f3320;--ds-warning:#ff9f0a;--ds-warning-soft:#3a2a0a;--ds-danger:#ff453a;--ds-danger-soft:#3d1513;--ds-info:#64a7ff;--ds-info-soft:#0e2747;
    --ds-glass:rgba(28,28,30,.97);--ds-glass-line:rgba(84,84,88,.6);--ds-grabber:rgba(235,235,245,.3);--ds-scrim:rgba(0,0,0,.6);
    --ds-tint:rgba(10,132,255,.2);--ds-tint-red:rgba(255,69,58,.18);
    --ds-sh-md:0 8px 24px -6px rgba(0,0,0,.6);--ds-sh-lg:0 20px 48px -12px rgba(0,0,0,.8);
    --ds-nav:#000;
  }
  html body .login-logo,html body .brand img{content:url("brand/dealerstation-logo-white.svg")}
  html body .boot img{content:url("brand/dealerstation-mark-white.svg")}
}
html,body{background:var(--ds-bg);color:var(--ds-text);font-family:var(--ds-font);-webkit-font-smoothing:antialiased}
body input,body textarea,body select,body button{font-family:inherit}
body ::selection{background:var(--ds-brand-ring)}

/* ---- 2. surfaces that were hard-coded white ---- */
body .panel,body .qcard,body .camp-card,body .metric,body .goalbox,body .callwin,body .board-card,body .board-col,body .filter-panel,body .bulkbar,body .mt-row,body .step,body .login-card,body .more-menu,body .cchip,body .searchbox,body .toggle,body .activity-row,body .day,body .calendar-wrap,body dialog,body .dialog-head,body .dialog-actions{background-color:var(--ds-surface)}
body .searchbox input[type=search]{background:transparent;color:var(--ds-text)}
body input:not([type=checkbox]):not([type=radio]),body textarea,body select{color:var(--ds-text)}

/* ---- 3. all sizes: buttons, fields, motion ---- */
@keyframes ios-sheet{from{transform:translateY(100%)}to{transform:none}}
@keyframes ios-scrim{from{opacity:0}to{opacity:1}}
@keyframes ios-pop{from{opacity:0;transform:translateY(8px) scale(.98)}to{opacity:1;transform:none}}
body dialog::backdrop{background:var(--ds-scrim);animation:ios-scrim .25s ease-out}
body button:not(:disabled):active,body .crow:active,body .nav:active{opacity:.7}
body .primary{background:var(--ds-brand);color:#fff;border:0;border-radius:12px;font-weight:600;box-shadow:none}
body .primary:active{background:var(--ds-brand-press)}
body .ghost{background:var(--ds-tint);color:var(--ds-brand);border:0;border-radius:12px;font-weight:600;box-shadow:none}
body .ghost:hover{background:var(--ds-tint)}
body .danger{background:var(--ds-tint-red);color:var(--ds-danger);border:0;border-radius:12px;font-weight:600}
body .primary:disabled,body .ghost:disabled{opacity:.45}
body input:not([type=checkbox]):not([type=radio]):not([type=search]),body textarea,body select{background-color:var(--ds-surface-2);border:1px solid transparent;border-radius:10px;box-shadow:none}
body input:not([type=checkbox]):not([type=radio]):not([type=search]):focus,body textarea:focus,body select:focus{border-color:var(--ds-brand);background-color:var(--ds-surface);outline:0;box-shadow:0 0 0 3px var(--ds-brand-ring)}
@supports (-webkit-appearance:switch){
  body input[type=checkbox][switch]{-webkit-appearance:switch;appearance:switch;width:51px;height:31px;min-height:31px;flex:0 0 auto}
}
body .pill,body .chip{font-weight:600}

/* ---- 4. phones ---- */
@media(max-width:760px){
  :root{--ios-nav-h:44px;--ios-tab-h:49px}
  html,body{overflow:hidden;height:100%;overscroll-behavior:none}
  html body .app{height:100dvh;display:flex;flex-direction:column;background:var(--ds-bg);padding-top:0;padding-bottom:0}

  /* navigation bar: frosted, hairline under it */
  html body header{flex:0 0 auto;height:calc(var(--ios-nav-h) + env(safe-area-inset-top));padding-top:env(safe-area-inset-top);background:var(--ds-glass);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px);border-bottom:.5px solid var(--ds-glass-line);box-shadow:none;position:relative;z-index:20}
  html body .brand img{height:19px;width:auto}
  html body .avatar-btn{border:0;background:transparent;box-shadow:none;color:var(--ds-brand)}

  /* main is the scroller, so large titles scroll away like a native app */
  html body main{flex:1 1 auto;min-height:0;height:auto;display:block;overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;overscroll-behavior-y:contain;padding:0 max(16px,env(safe-area-inset-right)) calc(var(--ios-tab-h) + env(safe-area-inset-bottom) + 20px) max(16px,env(safe-area-inset-left));scroll-padding-top:60px}
  html body.kbd main{padding-bottom:24px}
  html body .page{display:block;flex:none;overflow:visible;min-height:0;animation:ios-pop .22s ease-out}
  html body .topline{display:flex;align-items:flex-end;justify-content:space-between;gap:8px;margin:0;padding:6px 0 6px}
  html body .topline h1{font-size:34px;line-height:41px;font-weight:700;letter-spacing:.37px;margin:0;color:var(--ds-text)}
  html body .top-actions .primary{background:transparent;color:var(--ds-brand);min-height:44px;padding:0 2px;font-size:17px;font-weight:600}
  html body[data-page=calls] .topline{display:none}

  /* tab bar: edge to edge, frosted */
  html body .nav-tabs{position:fixed;left:0;right:0;bottom:0;margin:0;height:calc(var(--ios-tab-h) + env(safe-area-inset-bottom));padding:5px max(4px,env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px,env(safe-area-inset-left));gap:0;background:var(--ds-glass);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px);border:0;border-top:.5px solid var(--ds-glass-line);border-radius:0;box-shadow:none;z-index:30}
  html body .nav{flex:1;min-height:44px;margin:0;padding:0;border-radius:0;background:transparent;color:var(--ds-muted);font-size:10px;font-weight:500;gap:2px;letter-spacing:.1px}
  html body .nav:before{width:25px;height:25px}
  html body .nav.active{background:transparent;color:var(--ds-brand)}
  html body .nav-more.active{color:var(--ds-brand)}
  html body .more-menu{right:max(10px,env(safe-area-inset-right));bottom:calc(var(--ios-tab-h) + env(safe-area-inset-bottom) + 10px);background:var(--ds-glass);-webkit-backdrop-filter:saturate(180%) blur(24px);backdrop-filter:saturate(180%) blur(24px);border:.5px solid var(--ds-glass-line);border-radius:14px;box-shadow:var(--ds-sh-md);animation:ios-pop .18s ease-out}
  html body .more-menu button{color:var(--ds-text);font-size:17px}
  html body .more-menu button+button{border-top:.5px solid var(--ds-divider);border-radius:0}

  /* Calls: sticky frosted search header, one grouped list */
  html body .calls-head{position:sticky;top:0;z-index:6;margin:0 -16px;padding:8px 16px 4px;background:var(--ds-glass);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px);border-bottom:.5px solid transparent}
  html body .calls-bar{padding:0 0 8px}
  html body .searchbox{background:var(--ds-surface-2);border:0;border-radius:10px;height:40px;min-height:40px;box-shadow:none}
  html body .searchbox input[type=search]{min-height:40px!important;font-size:17px}
  html body .calls-new{background:transparent;box-shadow:none;color:var(--ds-brand);width:40px;height:40px;flex-basis:40px;font-size:34px;font-weight:300;padding:0 0 4px}
  html body .calls-chips{margin:0 -16px;padding:0 16px 8px}
  html body .cchip{min-height:34px;padding:0 14px;font-size:15px;font-weight:500;background:var(--ds-surface-2);border:0;color:var(--ds-text-2)}
  html body .cchip.on{background:var(--ds-brand);color:#fff}
  html body .calls-sub select{background-color:var(--ds-surface-2);border:0;min-height:36px;font-size:15px;font-weight:500;border-radius:10px}
  html body .calls-count{font-size:13px;color:var(--ds-muted)}
  html body .calls-list{display:block;gap:0;padding:0;margin:8px 0 28px;background:var(--ds-surface);border-radius:12px;overflow:hidden}
  html body .swipe{position:relative;overflow:hidden;background:var(--ds-surface)}
  html body .swipe+.swipe:before{content:"";position:absolute;top:0;left:16px;right:0;height:.5px;background:var(--ds-divider);z-index:2}
  html body .crow{position:relative;z-index:1;border:0;border-radius:0;box-shadow:none;background:var(--ds-surface);min-height:72px;padding:11px 14px 11px 16px;gap:10px;touch-action:pan-y;will-change:transform}
  html body .crow.is-hot{border-left:0;box-shadow:inset 3px 0 0 #ff9f0a}
  html body .cr-name h3{font-size:17px;font-weight:600;letter-spacing:-.2px}
  html body .cr-who{font-size:15px}
  html body .cr-meta,html body .cr-note{font-size:13px}
  html body .cr-score{font-size:11px;padding:1px 6px;border-radius:6px}
  html body .cr-call{width:48px;height:48px;background:var(--ds-success);color:#fff;box-shadow:none}
  html body .swipe-actions{position:absolute;top:0;right:0;bottom:0;display:flex;z-index:0}
  html body .swipe-actions button{width:84px;border:0;border-radius:0;color:#fff;font-size:15px;font-weight:600;padding:0 6px}
  html body .swipe-actions .sa-na{background:#8e8e93}
  html body .swipe-actions .sa-vm{background:var(--ds-brand)}
  html body .open-dot{display:inline-block;width:8px;height:8px;border-radius:50%;background:#34c759;margin-right:6px;vertical-align:1px}
  html body .goalline{height:3px;border-radius:2px;background:var(--ds-surface-3);overflow:hidden;margin:4px 0 0}
  html body .goalline i{display:block;height:100%;background:var(--ds-success);border-radius:2px;transition:width .4s ease}
  html body .nextpill{position:fixed;left:50%;transform:translateX(-50%);bottom:calc(var(--ios-tab-h) + env(safe-area-inset-bottom) + 12px);z-index:40;display:flex;align-items:center;gap:10px;max-width:calc(100vw - 32px);padding:6px 6px 6px 16px;border-radius:999px;background:var(--ds-glass);-webkit-backdrop-filter:saturate(180%) blur(24px);backdrop-filter:saturate(180%) blur(24px);border:.5px solid var(--ds-glass-line);box-shadow:var(--ds-sh-md);font-size:15px;animation:ios-pop .2s ease-out}
  html body .nextpill span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
  html body .nextpill button{flex:0 0 auto;min-height:40px;padding:0 16px;border-radius:999px;background:var(--ds-success);color:#fff;border:0;font-size:15px;font-weight:600}

  /* other screens: grouped cards, hairline borders */
  html body .panel,html body .qcard,html body .camp-card,html body .metric,html body .goalbox,html body .callwin{border:0;border-radius:12px;box-shadow:none}
  html body .section-head h2{font-size:22px;font-weight:700}
  html body .toast{background:rgba(44,44,46,.94);color:#fff;border-radius:14px;-webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);bottom:calc(var(--ios-tab-h) + env(safe-area-inset-bottom) + 14px);box-shadow:var(--ds-sh-md)}

  /* sheets: grabber, rounded top, spring */
  html body dialog.crm-dialog,html body dialog#inviteDialog,html body dialog#eventDialog,html body #outcomeDialog,html body #modalDialog{border-radius:14px 14px 0 0!important;background:var(--ds-surface);border:0;box-shadow:var(--ds-sh-lg);animation:ios-sheet .42s cubic-bezier(.32,.72,0,1)}
  html body dialog::before{content:"";display:block;position:sticky;top:6px;z-index:9;width:36px;height:5px;margin:6px auto -11px;border-radius:3px;background:var(--ds-grabber)}
  html body .crm-form .dialog-head,html body dialog form .dialog-head{background:var(--ds-glass);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px);padding-top:22px;border-bottom:.5px solid var(--ds-glass-line)}
  html body .crm-form .dialog-actions,html body dialog form .dialog-actions{background:var(--ds-surface);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px);border-top:.5px solid var(--ds-glass-line)}
  html body .dialog-head h2{font-size:22px;font-weight:700;letter-spacing:.2px}
  html body .dialog-head .eyebrow{display:none}
  html body .outcome{background:var(--ds-surface-2);border:0;border-radius:12px;color:var(--ds-text);font-weight:500}
  html body .outcome.on{background:var(--ds-brand);color:#fff}
  html body .outcome-title{color:var(--ds-muted)}
  html body .action-bar #actCall{border-radius:14px}
}
@media(prefers-reduced-motion:reduce){body dialog,body dialog::backdrop,html body .page,html body .more-menu,html body .nextpill{animation:none!important}}

/* swipe actions exist on touch layouts only */
body .swipe-actions{display:none}
@media(max-width:760px){html body .swipe-actions{display:flex}}
body .nextpill{position:fixed;left:50%;transform:translateX(-50%);bottom:24px;z-index:40;display:flex;align-items:center;gap:10px;max-width:calc(100vw - 32px);padding:6px 6px 6px 16px;border-radius:999px;background:var(--ds-surface);border:1px solid var(--ds-border);box-shadow:var(--ds-sh-md);font-size:15px}
body .nextpill[hidden]{display:none}
body .nextpill span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
body .nextpill button{flex:0 0 auto;min-height:40px;padding:0 16px;border-radius:999px;background:var(--ds-brand);color:#fff;border:0;font-size:15px;font-weight:600;cursor:pointer}
body .goalline[hidden]{display:none}
body .goalline{height:3px;border-radius:2px;background:var(--ds-surface-3);overflow:hidden;margin:2px 0 4px}
body .goalline i{display:block;height:100%;background:var(--ds-success);border-radius:2px;transition:width .4s ease}
body .open-dot{display:inline-block;width:8px;height:8px;border-radius:50%;background:#34c759;margin-right:6px;flex:0 0 auto}

/* calendar: tab badge + next appointment on Calls */
body .nav{position:relative}
body .tab-badge{position:absolute;top:2px;left:calc(50% + 6px);min-width:17px;height:17px;padding:0 5px;border-radius:9px;background:#ff3b30;color:#fff;font-size:11px;font-weight:700;line-height:17px;text-align:center;font-style:normal}
body .tab-badge[hidden]{display:none}
body .nextevent{display:flex;align-items:center;gap:8px;width:100%;margin:0 0 8px;padding:9px 12px;border:0;border-radius:10px;background:var(--ds-brand-soft);color:var(--ds-text);font-size:14px;text-align:left;cursor:pointer;min-height:44px}
body .nextevent[hidden]{display:none}
body .nextevent b{color:var(--ds-brand);font-weight:600;white-space:nowrap}
body .nextevent span{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
body .nextevent i{font-style:normal;color:var(--ds-muted);font-size:20px;line-height:1}

/* tap targets stay at 44 px (Apple's minimum) even where the look is lighter */
@media(max-width:760px){
  html body .searchbox{height:44px;min-height:44px}
  html body .searchbox input[type=search]{min-height:44px!important}
  html body .calls-new{width:44px;height:44px;flex-basis:44px}
  html body .cchip{min-height:44px}
  html body .calls-sub select{min-height:44px}
}

/* swipe buttons exist only while a row is being dragged or is open (no sliver at row edges) */
@media(max-width:760px){
  html body .swipe-actions{visibility:hidden;transition:visibility 0s linear .32s}
  html body .crow.open+.swipe-actions,html body .crow.dragging+.swipe-actions{visibility:visible;transition-delay:0s}
}
html body .calls-sub select{flex:1 1 52%;min-width:0;max-width:none}
html body .calls-sub .calls-count{flex:1 1 40%;white-space:normal;text-align:right;line-height:1.25;font-size:12.5px}

/* calendar: upcoming list */
body .agenda{margin:16px 0 8px;background:var(--ds-surface);border-radius:12px;padding:14px 16px 8px}
body .agenda h3{margin:0 0 6px;font-size:20px;font-weight:700}
body .ag-day{margin:12px 0 4px;font-size:12.5px;font-weight:600;text-transform:uppercase;letter-spacing:.05em;color:var(--ds-muted)}
body .ag-row{display:flex;align-items:center;gap:12px;width:100%;min-height:48px;padding:6px 0;border:0;border-top:.5px solid var(--ds-divider);background:transparent;color:var(--ds-text);font-size:16px;text-align:left;cursor:pointer}
body .ag-day+.ag-row{border-top:0}
body .ag-time{flex:0 0 74px;color:var(--ds-brand);font-weight:600;font-variant-numeric:tabular-nums}
body .ag-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
@media(max-width:760px){
  html body .event-chip{display:none}
  html body .day.has-ev:after{content:"";display:block;width:7px;height:7px;border-radius:50%;background:var(--ds-brand);margin:6px auto 0}
  html body .day.today .daynum{background:var(--ds-brand);color:#fff;border-radius:50%;display:inline-grid;place-items:center;min-width:26px;height:26px}
}
/* desktop: badge sits after the label, active chip is brand blue everywhere */
@media(min-width:761px){body .tab-badge{position:static;display:inline-block;margin-left:6px;vertical-align:1px}}
body .cchip.on{background:var(--ds-brand);color:#fff;border-color:var(--ds-brand)}

/* Today filter (segmented control): track is one step darker than the selected pill, in light and dark, text always readable */
html body .segmented{background-color:var(--ds-surface-3);border:0}
html body .segment{color:var(--ds-text-2);background:transparent}
html body .segment.active{background-color:var(--ds-surface);color:var(--ds-text);box-shadow:0 1px 3px rgba(0,0,0,.18)}
@media(prefers-color-scheme:dark){html body .segment.active{background-color:#636366;color:#fff;box-shadow:none}}
/* ---- iPhone polish (kept deliberately plain: no overlays, transforms or animations on anything tappable) ---- */
@media(max-width:760px){
  html{-webkit-tap-highlight-color:transparent}
  html body button,html body .nav,html body .crow,html body .lead-row,html body .camp-card,html body .cmp-opt,html body .qcard{touch-action:manipulation}
  html body .send-panel{border:0;border-radius:12px;box-shadow:none}
  /* More: a plain list above the tab bar */
  html body .more-menu{position:fixed;left:max(8px,env(safe-area-inset-left));right:max(8px,env(safe-area-inset-right));bottom:calc(var(--ios-tab-h) + env(safe-area-inset-bottom) + 8px);top:auto;width:auto;min-width:0;margin:0;padding:0;border-radius:14px;z-index:60;box-shadow:0 14px 44px rgba(0,0,0,.3);animation:none}
  html body .more-menu button{display:flex;align-items:center;justify-content:space-between;width:100%;min-height:54px;padding:0 18px;border-radius:0}
  html body .more-menu button:after{content:"\203A";color:var(--ds-faint);font-size:24px;font-weight:300;line-height:1}
}
