/* ============================================================
   Expiry Admin — iPlusView · Design system v2 (2026-10)
   IBM Plex Sans Thai · Swiss/minimal · light + dark tokens
   ============================================================ */

:root {
    --font: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', monospace;

    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f3f4f7;
    --surface-3: #e9ebf0;
    --border: #e2e5eb;
    --border-strong: #cdd2dc;

    --text: #111827;
    --text-2: #4b5563;
    --text-3: #6b7280;

    --accent: #5b4de6;
    --accent-hover: #4a3dd4;
    --accent-soft: #efedfd;
    --accent-text: #4335c9;
    --on-accent: #ffffff;

    --red: #dc2626;      --red-soft: #fdeded;   --red-text: #b42318;
    --amber: #d97706;    --amber-soft: #fdf4e3; --amber-text: #8f4a06;
    --green: #16a34a;    --green-soft: #e7f6ec; --green-text: #166534;
    --blue: #2563eb;     --blue-soft: #e8effd;  --blue-text: #1e4fc2;
    --gray-soft: #eef0f3; --gray-text: #4b5563;

    --o-renew: #2563eb;  /* ผลลัพธ์: ต่ออายุ — palette ผ่าน CVD check (blue/orange/violet) */
    --o-lost: #e8590c;   /* ไม่ต่อ */
    --o-pend: #a855f7;   /* รอปิด */
    --c1: #0891b2;  /* Canva */
    --c2: #2563eb;  /* Traffic */
    --c3: #9333ea;  /* อื่นๆ */
    --line: #06c755;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
    --backdrop: rgba(17, 24, 39, .45);

    --r: 12px;
    --r-sm: 8px;
    --r-xs: 6px;
    --side-w: 248px;
    --top-h: 64px;
    --ease: cubic-bezier(.2, .7, .2, 1);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0c0e13;
    --surface: #14171f;
    --surface-2: #1a1e28;
    --surface-3: #232836;
    --border: #252a37;
    --border-strong: #353c4d;

    --text: #e9ebf1;
    --text-2: #b0b6c4;
    --text-3: #8a91a2;

    --accent: #7b6ef6;
    --accent-hover: #8e83f8;
    --accent-soft: rgba(123, 110, 246, .16);
    --accent-text: #b9b2ff;
    --on-accent: #ffffff;

    --red: #f05252;   --red-soft: rgba(240, 82, 82, .14);   --red-text: #ff9090;
    --amber: #f0a020; --amber-soft: rgba(240, 160, 32, .14); --amber-text: #fbc35f;
    --green: #2fc56a; --green-soft: rgba(47, 197, 106, .14); --green-text: #6ee09a;
    --blue: #4f8cf7;  --blue-soft: rgba(79, 140, 247, .15);  --blue-text: #9cc0ff;
    --gray-soft: rgba(148, 160, 184, .13); --gray-text: #b0b6c4;

    --o-renew: #4f8cf7;
    --o-lost: #e8590c;
    --o-pend: #a855f7;
    --c1: #22b8d6;
    --c2: #5b95f8;
    --c3: #b27af6;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 3px rgba(0, 0, 0, .35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .3);
    --backdrop: rgba(0, 0, 0, .6);
    color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
body.booting .app, body.booting .bottomnav { visibility: hidden; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
svg { flex-shrink: 0; }
code, .mono { font-family: var(--mono); font-size: .86em; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-3); }
.sm { font-size: .87rem; }
.xs { font-size: .8rem; }
.b { font-weight: 600; }
.trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 4px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--side-w);
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; z-index: 40;
    transition: transform .25s var(--ease);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-mark {
    width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
    background: var(--accent); color: var(--on-accent);
}
.brand-name { font-weight: 700; font-size: 1.02rem; line-height: 1.2; }
.brand-sub { font-size: .8rem; color: var(--text-3); }
.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-sec { font-size: .75rem; font-weight: 600; color: var(--text-3); padding: 14px 10px 6px; letter-spacing: .02em; }
.nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-sm);
    color: var(--text-2); font-weight: 500; text-decoration: none; min-height: 40px;
    transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav a .nav-badge { margin-left: auto; }
.nav .ext { margin-left: auto; opacity: .6; }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--r-sm); min-width: 0; }
.side-user:hover { background: var(--surface-2); }

.main { flex: 1; min-width: 0; margin-left: var(--side-w); display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 30; height: var(--top-h);
    display: flex; align-items: center; gap: 12px; padding: 0 24px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}
.tb-title { min-width: 0; flex: 1; }
.tb-title h1 { font-size: 1.2rem; font-weight: 700; line-height: 1.25; }
.tb-title p { font-size: .82rem; color: var(--text-3); }
.tb-actions { display: flex; align-items: center; gap: 8px; }
.topbar .tb-menu { display: none; }
.view { padding: 24px; max-width: 1480px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.bottomnav { display: none; }
.scrim { position: fixed; inset: 0; background: var(--backdrop); z-index: 39; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.on { opacity: 1; pointer-events: auto; }

@media (max-width: 1023px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: none; }
    .main { margin-left: 0; }
    .topbar .tb-menu { display: inline-flex; }
    .view { padding: 16px 16px 96px; }
    .topbar { padding: 0 12px; gap: 8px; }
    .bottomnav {
        display: grid; grid-template-columns: repeat(5, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
        background: var(--surface); border-top: 1px solid var(--border);
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    }
    .bottomnav a, .bottomnav button {
        display: flex; flex-direction: column; align-items: center; gap: 2px;
        padding: 6px 2px; min-height: 52px; justify-content: center;
        font-size: .75rem; color: var(--text-3); text-decoration: none; border-radius: var(--r-sm); position: relative;
    }
    .bottomnav [aria-current="page"] { color: var(--accent-text); font-weight: 600; }
    .bottomnav .badge { position: absolute; top: 2px; left: calc(50% + 6px); }
    .hide-md { display: none !important; }
}
@media (max-width: 639px) {
    .hide-sm { display: none !important; }
    .tb-title h1 { font-size: 1.08rem; }
    .tb-title p { display: none; }
}
@media (min-width: 1024px) { .show-md { display: none !important; } }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 38px; padding: 0 14px; border-radius: var(--r-sm);
    font-weight: 600; font-size: .9rem; white-space: nowrap; line-height: 1;
    border: 1px solid transparent; transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
    user-select: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-outline { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.94); }
.btn-danger-ghost { color: var(--red-text); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--red-soft); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(.95); }
.btn-sm { height: 32px; padding: 0 10px; font-size: .84rem; gap: 6px; }
.btn-lg { height: 44px; padding: 0 18px; font-size: .95rem; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm.btn-icon { width: 32px; }
.btn-block { width: 100%; }
.btn .kbd { margin-left: 4px; }
.split { display: inline-flex; }
.split .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgba(255, 255, 255, .25); width: 32px; padding: 0; }
.kbd {
    font-family: var(--mono); font-size: .72rem; padding: 1px 5px; border-radius: 4px;
    border: 1px solid var(--border-strong); color: var(--text-3); background: var(--surface-2); line-height: 1.4;
}
.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .7s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- pills, badges, chips ---------- */
.badge {
    display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 10px; font-size: .74rem; font-weight: 700; background: var(--surface-3); color: var(--text-2);
}
.badge.red { background: var(--red); color: #fff; }
.badge.accent { background: var(--accent); color: var(--on-accent); }
.pill {
    display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 12px;
    font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--gray-soft); color: var(--gray-text);
}
.pill.red { background: var(--red-soft); color: var(--red-text); }
.pill.amber { background: var(--amber-soft); color: var(--amber-text); }
.pill.green { background: var(--green-soft); color: var(--green-text); }
.pill.blue { background: var(--blue-soft); color: var(--blue-text); }
.pill.accent { background: var(--accent-soft); color: var(--accent-text); }
.pill.line { background: rgba(6, 199, 85, .13); color: #078a3d; }
:root[data-theme="dark"] .pill.line { color: #4ade80; }
.tag {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: .78rem;
    background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.chip {
    display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 16px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: .86rem; font-weight: 500;
    transition: all .15s; white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); font-weight: 600; }
.chip .cnt { font-size: .76rem; opacity: .75; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button {
    height: 30px; padding: 0 12px; border-radius: 6px; font-size: .86rem; font-weight: 500; color: var(--text-2);
    display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.seg .cnt { font-size: .76rem; color: var(--text-3); font-variant-numeric: tabular-nums; }
.seg-scroll { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.seg-scroll::-webkit-scrollbar { display: none; }

/* ---------- category icon ---------- */
.cat {
    width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
    background: color-mix(in srgb, var(--cc) 14%, transparent); color: var(--cc);
}
.cat.sm { width: 28px; height: 28px; border-radius: 8px; }
.c1 { --cc: var(--c1); } .c2 { --cc: var(--c2); } .c3 { --cc: var(--c3); }

/* ---------- avatar ---------- */
.av {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; object-fit: cover; background: var(--surface-3);
    display: grid; place-items: center; font-weight: 700; color: var(--text-2); font-size: .9rem; overflow: hidden;
}
.av.sm { width: 24px; height: 24px; font-size: .72rem; }
.av.lg { width: 48px; height: 48px; font-size: 1.1rem; }
.av-wrap { position: relative; flex-shrink: 0; }
.av-wrap .dot { position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border: 2px solid var(--surface); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-h h2, .card-h h3 { font-size: .98rem; font-weight: 700; }
.card-h .sub { font-size: .8rem; color: var(--text-3); }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }
.card + .card { margin-top: 16px; }
.section-title { font-size: .8rem; font-weight: 700; color: var(--text-3); letter-spacing: .02em; margin: 2px 0 8px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.card-b > .field:last-child, .modal-b > .field:last-child, .card-b > div > .field:last-child { margin-bottom: 0; }
.label { font-size: .86rem; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
.label .req { color: var(--red-text); }
.hint { font-size: .8rem; color: var(--text-3); }
.err-msg { font-size: .8rem; color: var(--red-text); display: none; }
.field.invalid .err-msg { display: block; }
.field.invalid .input { border-color: var(--red); }
.input {
    width: 100%; height: 40px; padding: 0 12px; border-radius: var(--r-sm);
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    transition: border-color .15s, box-shadow .15s; font-size: .93rem;
}
.input::placeholder { color: var(--text-3); opacity: .8; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
select.input { padding-right: 32px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a91a2' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon .input { padding-left: 36px; }
.input-icon .clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 639px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .9rem; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border-radius: 11px; transition: background .15s; }
.switch span::after { content: ''; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .15s var(--ease); box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.cat-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-pick button {
    display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 8px; border-radius: var(--r-sm);
    border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: .88rem; color: var(--text-2);
    transition: all .15s;
}
.cat-pick button:hover { border-color: var(--border-strong); }
.cat-pick button[aria-pressed="true"] { border-color: var(--cc); background: color-mix(in srgb, var(--cc) 8%, var(--surface)); color: var(--text); box-shadow: 0 0 0 1px var(--cc); }
.date-quick { display: flex; gap: 6px; flex-wrap: wrap; }
.date-quick .chip { height: 28px; font-size: .8rem; padding: 0 10px; }

/* combobox (customer picker) */
.combo { position: relative; }
.combo-list {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 80; max-height: 280px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); box-shadow: var(--shadow-lg); padding: 4px;
}
.combo-opt { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; cursor: pointer; min-height: 40px; }
.combo-opt[aria-selected="true"], .combo-opt:hover { background: var(--surface-2); }
.combo-opt .o-name { font-weight: 600; font-size: .9rem; }
.combo-opt .o-sub { font-size: .76rem; color: var(--text-3); }
.combo-sel { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 6px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); min-height: 40px; background: var(--surface); }
.combo-empty { padding: 12px; font-size: .86rem; color: var(--text-3); text-align: center; }
.combo-foot { padding: 6px 8px; border-top: 1px solid var(--border); margin-top: 4px; }

/* ---------- list rows ---------- */
.rows { display: flex; flex-direction: column; }
.ri {
    display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 60px;
    border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s;
}
.ri:last-child { border-bottom: 0; }
.ri:hover { background: var(--surface-2); }
.ri-main { flex: 1; min-width: 0; }
.ri-title { font-weight: 600; font-size: .93rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri-sub { font-size: .8rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.ri-date { text-align: right; flex-shrink: 0; font-size: .84rem; }
.ri-date .d { font-weight: 600; font-variant-numeric: tabular-nums; }
.ri-acts { display: flex; gap: 4px; flex-shrink: 0; }
.ri.done .ri-title { color: var(--text-3); }
.group-h {
    display: flex; align-items: center; gap: 8px; padding: 10px 16px 8px; font-size: .8rem; font-weight: 700;
    color: var(--text-2); background: var(--surface-2); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1;
}
.group-h .badge { height: 18px; min-width: 18px; font-size: .7rem; }
@media (max-width: 639px) {
    .ri { padding: 10px 12px; gap: 10px; }
    .ri-acts { display: none; }
}

/* ---------- table ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th {
    text-align: left; font-size: .78rem; font-weight: 700; color: var(--text-3); padding: 10px 12px;
    border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { cursor: pointer; transition: background .12s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.sel { background: var(--accent-soft); }
.tbl .cb { width: 40px; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.sel-bar {
    position: fixed; bottom: 16px; left: calc(var(--side-w) + 24px); right: 24px; max-width: 720px; margin: 0 auto; z-index: 25; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; animation: pop .18s var(--ease);
    background: var(--text); color: var(--bg); padding: 8px 8px 8px 16px; border-radius: var(--r); box-shadow: var(--shadow-lg);
}
.sel-bar .btn-ghost { color: var(--bg); }
.sel-bar .btn-ghost:hover { background: rgba(127, 127, 127, .25); color: var(--bg); }
@media (max-width: 1023px) { .sel-bar { bottom: 76px; left: 12px; right: 12px; } }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi {
    display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; text-align: left;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm);
    transition: border-color .15s, box-shadow .15s; position: relative; overflow: hidden;
}
.kpi:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.kpi-top { display: flex; align-items: center; gap: 8px; font-size: .84rem; font-weight: 600; color: var(--text-2); }
.kpi-ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; }
.kpi-v { font-size: 1.85rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-s { font-size: .78rem; color: var(--text-3); }
.kpi.red .kpi-ico { background: var(--red-soft); color: var(--red-text); }
.kpi.amber .kpi-ico { background: var(--amber-soft); color: var(--amber-text); }
.kpi.green .kpi-ico { background: var(--green-soft); color: var(--green-text); }
.kpi.blue .kpi-ico { background: var(--blue-soft); color: var(--blue-text); }
.kpi.accent .kpi-ico { background: var(--accent-soft); color: var(--accent-text); }
.kpi.red.hot { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }
@media (max-width: 1099px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .kpi-v { font-size: 1.5rem; } .kpi { padding: 12px; } }

.ov-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 1199px) { .ov-grid { grid-template-columns: minmax(0, 1fr); } }
.stat-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: .88rem; }
.stat-line:last-child { border-bottom: 0; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 4px; background: var(--cc, var(--accent)); }
.callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r-sm); background: var(--surface-2); font-size: .86rem; color: var(--text-2); align-items: flex-start; }
.callout.warn { background: var(--amber-soft); color: var(--amber-text); }
.callout.err { background: var(--red-soft); color: var(--red-text); }
.callout.ok { background: var(--green-soft); color: var(--green-text); }
.callout.info { background: var(--blue-soft); color: var(--blue-text); }

/* ---------- empty / skeleton ---------- */
.empty { padding: 40px 20px; text-align: center; color: var(--text-3); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .e-ico { width: 52px; height: 52px; border-radius: 16px; background: var(--surface-2); display: grid; place-items: center; color: var(--text-3); }
.empty .e-t { font-weight: 600; color: var(--text-2); }
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 6px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- overlays ---------- */
.ov {
    position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px;
    background: var(--backdrop); animation: fade .15s ease;
}
.ov.drawer-ov { justify-content: flex-end; padding: 0; }
@keyframes fade { from { opacity: 0; } }
.modal {
    background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px;
    max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop .18s var(--ease); border: 1px solid var(--border);
}
.modal.sm { max-width: 420px; }
.modal.lg { max-width: 760px; }
.modal.xl { max-width: 960px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-h h2 { font-size: 1.05rem; font-weight: 700; flex: 1; min-width: 0; }
.modal-b { padding: 20px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-f { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-f .sp { flex: 1; }
.drawer {
    background: var(--surface); width: 100%; max-width: 480px; height: 100%; display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg); border-left: 1px solid var(--border); animation: slide .22s var(--ease);
}
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
@media (max-width: 639px) {
    .ov { padding: 0; align-items: flex-end; }
    .modal { max-width: none !important; border-radius: 16px 16px 0 0; max-height: 92vh; }
    .drawer { max-width: none; }
    .modal-b { padding: 16px; }
    .modal-h, .modal-f { padding: 12px 16px; }
}

.pop {
    position: fixed; z-index: 120; min-width: 200px; background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--r-sm); box-shadow: var(--shadow-lg); padding: 4px; animation: pop .12s var(--ease);
}
.mi { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 6px; font-size: .9rem; text-align: left; min-height: 38px; }
.mi:hover, .mi:focus-visible { background: var(--surface-2); outline: none; }
.mi .mi-d { font-size: .78rem; color: var(--text-3); }
.mi.danger { color: var(--red-text); }
.pop hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--r-sm); pointer-events: auto;
    background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: .9rem; max-width: 420px; animation: pop .18s var(--ease);
}
.toast .t-ico { display: grid; place-items: center; }
.toast.success .t-ico { color: #4ade80; }
.toast.error .t-ico { color: #f87171; }
.toast.warning .t-ico { color: #fbbf24; }
:root[data-theme="dark"] .toast { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); }
@media (max-width: 1023px) { .toasts { left: 12px; right: 12px; bottom: 80px; align-items: stretch; } .toast { max-width: none; } }

/* ---------- detail drawer ---------- */
.dt-head { padding: 18px 20px 16px; border-bottom: 1px solid var(--border); }
.dt-title { font-size: 1.18rem; font-weight: 700; line-height: 1.35; word-break: break-word; }
.dt-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.dt-body { padding: 16px 20px 24px; overflow-y: auto; flex: 1; }
.facts { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 0; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.facts > div { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: .88rem; min-width: 0; }
.facts > div:nth-last-child(-n+2) { border-bottom: 0; }
.facts .k { color: var(--text-3); background: var(--surface-2); font-size: .82rem; }
.facts .v { word-break: break-word; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.copy-btn { color: var(--text-3); padding: 2px; border-radius: 4px; display: inline-grid; place-items: center; }
.copy-btn:hover { color: var(--text); background: var(--surface-3); }
.note-box { background: var(--amber-soft); border-radius: var(--r-sm); padding: 12px 14px; font-size: .88rem; white-space: pre-line; word-break: break-word; color: var(--text); }
.tl { display: flex; flex-direction: column; }
.tl-i { display: flex; gap: 10px; padding: 8px 0; font-size: .86rem; border-bottom: 1px solid var(--border); align-items: flex-start; }
.tl-i:last-child { border-bottom: 0; }
.tl-i .tl-ico { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
.tl-i.ok .tl-ico { background: var(--green-soft); color: var(--green-text); }
.tl-i.bad .tl-ico { background: var(--red-soft); color: var(--red-text); }
.dt-sec { margin-top: 20px; }

/* ---------- calendar ---------- */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 1279px) { .cal-layout { grid-template-columns: minmax(0, 1fr); } }
.cal-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.cal-month { font-size: 1.1rem; font-weight: 700; min-width: 150px; }
.cal-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.cal-wds { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--border); }
.cal-wds div { padding: 8px 10px; font-size: .78rem; font-weight: 700; color: var(--text-3); }
.cal-wds .we { color: var(--red-text); opacity: .8; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-cell {
    min-height: 118px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 3px; cursor: pointer; position: relative; min-width: 0; transition: background .12s;
}
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell:hover { background: var(--surface-2); }
.cal-cell.out { background: var(--surface-2); opacity: .55; cursor: default; }
.cal-cell.out:hover { background: var(--surface-2); }
.cal-cell.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell-h { display: flex; align-items: center; gap: 4px; min-height: 26px; }
.cal-num { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; font-size: .84rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-cell.past .cal-num { color: var(--text-3); font-weight: 500; }
.cal-cell.today .cal-num { background: var(--accent); color: var(--on-accent); }
.cal-add { margin-left: auto; width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; color: var(--text-3); opacity: 0; transition: opacity .12s; }
.cal-cell:hover .cal-add, .cal-add:focus-visible { opacity: 1; }
.cal-add:hover { background: var(--surface-3); color: var(--text); }
.cal-flag { font-size: .7rem; font-weight: 700; color: var(--red-text); background: var(--red-soft); border-radius: 8px; padding: 0 6px; height: 18px; display: inline-flex; align-items: center; gap: 3px; }
.cal-ev {
    display: flex; align-items: center; gap: 5px; padding: 2px 6px; border-radius: 5px; font-size: .76rem; font-weight: 500;
    background: color-mix(in srgb, var(--cc) 13%, transparent); color: var(--text); min-width: 0; text-align: left;
    border-left: 3px solid var(--cc); line-height: 1.45;
}
.cal-ev span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cal-ev:hover { background: color-mix(in srgb, var(--cc) 22%, transparent); }
.cal-ev.done { opacity: .55; border-left-style: dashed; }
.cal-ev.done span { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text) 40%, transparent); }
.cal-ev.overdue { background: var(--red-soft); border-left-color: var(--red); }
.cal-more { font-size: .76rem; font-weight: 600; color: var(--text-2); padding: 1px 6px; text-align: left; border-radius: 5px; }
.cal-more:hover { background: var(--surface-3); }
.cal-dots { display: none; gap: 3px; flex-wrap: wrap; padding: 0 2px; }
.cal-dots .dot { width: 6px; height: 6px; background: var(--cc); }
.cal-dots .dot.done { opacity: .35; }
@media (max-width: 719px) {
    .cal-cell { min-height: 58px; padding: 4px 2px; align-items: center; }
    .cal-cell-h { justify-content: center; }
    .cal-add, .cal-ev, .cal-more, .cal-flag { display: none; }
    .cal-dots { display: flex; justify-content: center; }
    .cal-wds div { text-align: center; padding: 6px 0; }
    .cal-month { min-width: 0; font-size: 1rem; }
}
.agenda-h { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.agenda-h h3 { font-size: .98rem; font-weight: 700; flex: 1; }
.cal-side { position: sticky; top: calc(var(--top-h) + 16px); max-height: calc(100vh - var(--top-h) - 32px); display: flex; flex-direction: column; }
.cal-side .rows { overflow-y: auto; }
@media (max-width: 1279px) { .cal-side { position: static; max-height: none; } }

/* ---------- customers ---------- */
.cust-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.cust {
    display: flex; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
    align-items: center; transition: border-color .15s; min-width: 0;
}
.cust:hover { border-color: var(--border-strong); }
.cust-name { font-weight: 700; font-size: .95rem; }
.cust-meta { font-size: .78rem; color: var(--text-3); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cust-acts { display: flex; gap: 2px; margin-left: auto; flex-shrink: 0; }
.rename-input { height: 32px; font-weight: 600; }

/* ---------- templates ---------- */
.tpl-top { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.tpl-picks { display: flex; gap: 8px; flex-wrap: wrap; }
.tpl-pick {
    display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 8px; border: 1px solid var(--border); border-radius: var(--r-sm);
    background: var(--surface); font-weight: 600; font-size: .9rem; color: var(--text-2); position: relative;
}
.tpl-pick:hover { border-color: var(--border-strong); color: var(--text); }
.tpl-pick[aria-pressed="true"] { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 1px var(--accent); }
.tpl-pick .unsaved { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.tpl-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 460px); gap: 16px; align-items: start; }
.tpl-preview { position: sticky; top: calc(var(--top-h) + 16px); }
@media (max-width: 1199px) { .tpl-layout { grid-template-columns: minmax(0, 1fr); } .tpl-preview { position: static; } }
.tpl-actions { position: sticky; bottom: 0; z-index: 5; display: flex; gap: 8px; align-items: center; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border); border-radius: 0 0 var(--r) var(--r); flex-wrap: wrap; }
@media (max-width: 1023px) { .tpl-actions { bottom: 64px; } }
.vars { display: flex; flex-wrap: wrap; gap: 6px; }
.var-chip { font-family: var(--mono); font-size: .76rem; padding: 3px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); border: 1px solid transparent; }
.var-chip:hover { border-color: var(--accent); }
.var-chip small { font-family: var(--font); opacity: .8; margin-left: 4px; }
.color-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.color-row input[type="color"] { width: 40px; height: 40px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 3px; background: var(--surface); cursor: pointer; }
.color-row .input { width: 110px; font-family: var(--mono); font-size: .86rem; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong); }
.swatch:hover { transform: scale(1.1); }
.irow { display: grid; grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1.2fr) auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.irow .input { height: 36px; font-size: .88rem; }
@media (max-width: 639px) { .irow { grid-template-columns: 52px 1fr; } .irow .iv { grid-column: 1 / -1; } .irow .ia { grid-column: 1 / -1; justify-content: flex-end; } }
.irow .ia { display: flex; gap: 2px; }
.preview-frame { width: 100%; height: 640px; border: 0; border-radius: 0 0 var(--r) var(--r); background: #f4f4f4; display: block; }
.phone { background: #8fa3c0; border-radius: 0 0 var(--r) var(--r); padding: 20px 16px 28px; min-height: 420px; }
.phone-bar { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 600; font-size: .86rem; margin-bottom: 14px; }
.fx { background: #fff; border-radius: 16px; overflow: hidden; max-width: 300px; color: #111; font-size: 13px; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.fx-h { padding: 12px 16px; color: #fff; font-weight: 700; font-size: 14px; }
.fx-b { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.fx-title { font-weight: 700; font-size: 16px; }
.fx-sub { color: #ef4444; font-weight: 600; }
.fx-sep { height: 1px; background: #e5e7eb; }
.fx-row { display: flex; gap: 6px; align-items: baseline; }
.fx-row .l { color: #6b7280; flex-shrink: 0; }
.fx-row .v { margin-left: auto; font-weight: 600; text-align: right; word-break: break-all; }
.fx-row .v.date { color: #dc2626; }
.fx-foot { color: #6b7280; font-size: 12px; line-height: 1.5; white-space: pre-line; }
.fx-cta { margin: 0 16px 14px; border-radius: 8px; color: #fff; text-align: center; padding: 10px; font-weight: 700; }

/* ---------- settings ---------- */
.set-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 639px) { .set-grid { grid-template-columns: 1fr; } }
.day-chips .chip { min-width: 64px; justify-content: center; }
.recip { display: flex; flex-wrap: wrap; gap: 6px; }
.recip .tag { padding: 3px 4px 3px 3px; gap: 6px; }
.recip .tag button { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 4px; color: var(--text-3); }
.recip .tag button:hover { background: var(--surface-3); color: var(--text); }

/* ---------- traffic report ---------- */
.tr-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 639px) { .tr-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tr-kpi { background: var(--surface-2); border-radius: var(--r-sm); padding: 10px 12px; }
.tr-kpi .l { font-size: .76rem; color: var(--text-3); font-weight: 600; }
.tr-kpi .v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tr-kpi .s { font-size: .74rem; color: var(--text-3); }
.chart { width: 100%; height: auto; display: block; }
.chart .grid-l { stroke: var(--border); stroke-width: 1; }
.chart .ax { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .b-hits { fill: var(--accent); }
.chart .b-vis { fill: var(--green); }
.chart .b-last { opacity: 1; }
.chart rect.b { opacity: .85; }
.chart rect.b:hover { opacity: 1; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--text-2); align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- command palette ---------- */
.pal { max-width: 640px; align-self: flex-start; margin-top: 10vh; }
.pal-in { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.pal-in input { flex: 1; height: 54px; border: 0; background: transparent; font-size: 1rem; outline: none; color: var(--text); }
.pal-res { max-height: 60vh; overflow-y: auto; padding: 6px; }
.pal-sec { font-size: .74rem; font-weight: 700; color: var(--text-3); padding: 8px 10px 4px; }
.pal-i { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; min-height: 48px; }
.pal-i[aria-selected="true"] { background: var(--accent-soft); }
.pal-foot { display: flex; gap: 14px; padding: 8px 16px; border-top: 1px solid var(--border); font-size: .76rem; color: var(--text-3); flex-wrap: wrap; }
@media (max-width: 639px) { .pal { margin-top: 0; align-self: stretch; } }

/* ---------- credits pill ---------- */
.credit-btn { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: .86rem; font-variant-numeric: tabular-nums; }
.credit-btn:hover { border-color: var(--border-strong); }
.credit-btn.low { border-color: color-mix(in srgb, var(--amber) 50%, var(--border)); color: var(--amber-text); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; padding: 36px 32px; text-align: center; }
.login-card .brand-mark { width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 16px; }
.login-card h1 { font-size: 1.4rem; font-weight: 700; }
.login-card p { color: var(--text-3); margin: 6px 0 24px; }
.g-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 46px; border-radius: var(--r-sm); background: #fff; color: #1f2937; font-weight: 600; border: 1px solid #dadce0; text-decoration: none; }
.g-btn:hover { background: #f8f9fa; text-decoration: none; box-shadow: var(--shadow); }
.toast-act { background: transparent; color: inherit; border: 1px solid currentColor; opacity: .85; height: 28px; }
.toast-act:hover { opacity: 1; }
.ri-date .pill { margin-left: auto; }
.ri-date { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.chart-box { margin-top: 6px; }
.chart-tip { position: absolute; top: -8px; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-xs); padding: 6px 10px; box-shadow: var(--shadow); white-space: nowrap; transform: translateY(-100%); z-index: 2; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.modal:focus, .drawer:focus { outline: none; }
.field .hint + .err-msg { margin-top: -2px; }

/* ---------- phone refinements ---------- */
.tb-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 639px) {
    .page-head > .input-icon { max-width: none !important; flex: 1 1 100% !important; order: 3; }
    .page-head > select.input { flex: 1 1 0; }
    .cal-filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .cal-filters::-webkit-scrollbar { display: none; }
    .cal-filters .chips { flex-wrap: nowrap; }
    .cal-tools .input-icon { flex: 1 1 100% !important; max-width: none !important; order: 5; }
    .tbl { table-layout: fixed; }
    .tbl th.c-date { width: 104px; }
    .tbl th.c-menu { width: 40px; }
    .tbl td, .tbl th { padding: 10px 8px; }
    .tbl .cb { width: 34px; }
    .kpis { gap: 8px; }
    .card-h { flex-wrap: wrap; }
}
.show-sm-only { display: none; }
@media (max-width: 639px) { .show-sm-only { display: block; } }
@media (max-width: 639px) { .page-head > .grow { display: none; } }
.tb-title p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- outcome (ต่อ / ไม่ต่อ) ---------- */
.pill.o-renew { background: color-mix(in srgb, var(--o-renew) 14%, transparent); color: color-mix(in srgb, var(--o-renew) 75%, var(--text)); }
.pill.o-lost { background: color-mix(in srgb, var(--o-lost) 14%, transparent); color: color-mix(in srgb, var(--o-lost) 72%, var(--text)); }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-sm);
    text-align: left; background: var(--surface); transition: border-color .15s, background .15s; min-height: 56px;
}
.opt:hover, .opt:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.opt .o-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; background: color-mix(in srgb, var(--oc) 14%, transparent); color: var(--oc); }
.opt .o-t { font-weight: 600; }
.opt .o-d { font-size: .8rem; color: var(--text-3); }
.rep-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--text-2); }
.rep-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart .ax-b { fill: var(--text-2); font-size: 11px; font-weight: 600; font-family: var(--font); }

/* ---------- triage ---------- */
.tri .modal-b { padding-top: 16px; }
.tri-prog { height: 3px; background: var(--surface-3); }
.tri-prog span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s var(--ease); }
.tri-title { font-size: 1.25rem; font-weight: 700; margin-top: 12px; word-break: break-word; }
.tri-date { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-2); font-size: .92rem; flex-wrap: wrap; }
.opt[aria-pressed="true"] { border-color: var(--oc); box-shadow: 0 0 0 1px var(--oc); }
.opt .kbd { margin-left: auto; }
.opt:disabled { opacity: .6; cursor: progress; }

/* ---------- renewal cycles ---------- */
.cyc { position: relative; display: flex; flex-direction: column; padding-left: 22px; }
.cyc::before { content: ''; position: absolute; left: 9px; top: 14px; bottom: 14px; width: 2px; background: var(--border-strong); }
.cyc-i { position: relative; display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-xs); text-align: left; font-size: .88rem; min-height: 38px; }
.cyc-i:not(:disabled):hover { background: var(--surface-2); }
.cyc-i.cur { background: var(--accent-soft); cursor: default; }
.cyc-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--oc); flex-shrink: 0; box-shadow: 0 0 0 2px var(--surface); }
.cyc .cyc-dot { position: absolute; left: -19px; }
.mini-cyc { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; margin-top: 6px; }
.mini-cyc button { display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px; border-radius: 12px; font-size: .76rem; color: var(--text-2); }
.mini-cyc button:hover { background: var(--surface-2); color: var(--text); }
.mini-cyc .cyc-dot { width: 9px; height: 9px; box-shadow: none; }
.mini-sep { width: 10px; height: 2px; background: var(--border-strong); border-radius: 1px; }

/* ---------- inline date edit ---------- */
.date-edit { display: inline-flex; align-items: center; gap: 6px; padding: 2px 6px; margin: -2px -6px; border-radius: var(--r-xs); font-variant-numeric: tabular-nums; }
.date-edit .de-ic { opacity: 0; color: var(--text-3); transition: opacity .12s; }
.date-edit:hover, .date-edit:focus-visible { background: var(--surface-3); }
.date-edit:hover .de-ic, .date-edit:focus-visible .de-ic { opacity: 1; }
.ie { display: inline-flex; align-items: center; gap: 4px; }
.ie .input { height: 32px; width: 150px; padding: 0 8px; font-size: .86rem; }

/* ---------- swipe rows (touch) ---------- */
.rows { overflow-x: hidden; }
.ri[data-swipe] { position: relative; touch-action: pan-y; transition: transform .2s var(--ease), background .12s; }
.sw-tray { position: absolute; top: 0; bottom: 0; left: 100%; width: 152px; display: flex; }
.sw-tray button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #fff; font-size: .78rem; font-weight: 600; }
.sw-tray .t-close { background: var(--green); }
.sw-tray .t-renew { background: var(--o-renew); }
.ri.sel { background: var(--accent-soft); }
