/* =====================================================================
   PrimeLogic Sales OS — design system
   Dark sidebar · light workspace · violet/blue accents
   ===================================================================== */
:root {
  --c-bg: #F5F6FA;
  --c-surface: #FFFFFF;
  --c-surface-2: #F9FAFC;
  --c-border: #E4E7EF;
  --c-border-strong: #D3D8E4;
  --c-text: #161B2E;
  --c-text-2: #4B5368;
  --c-muted: #7A8299;
  --c-primary: #6D4AFF;
  --c-primary-600: #5B37F0;
  --c-primary-50: #F1EDFF;
  --c-blue: #2F6BFF;
  --c-success: #12A150;
  --c-success-50: #E8F7EF;
  --c-warning: #C27803;
  --c-warning-50: #FEF5E1;
  --c-danger: #DC2E3F;
  --c-danger-50: #FDECEE;
  --c-info: #0B84C6;
  --c-info-50: #E6F4FB;
  --sidebar-bg: #0F1222;
  --sidebar-bg-2: #171B30;
  --sidebar-text: #A6ADC8;
  --sidebar-active: #FFFFFF;
  --grad: linear-gradient(135deg, #7C3AED 0%, #2563EB 100%);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  --shadow-lg: 0 20px 50px rgba(15, 18, 34, .25);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 248px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--c-text); background: var(--c-bg); -webkit-font-smoothing: antialiased; }
a { color: var(--c-primary-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0 0 .75em; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.icon { width: 18px; height: 18px; flex: none; vertical-align: middle; }
.icon-sm { width: 15px; height: 15px; flex: none; vertical-align: -2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.sr-only[href]:focus { position: fixed; top: 8px; left: 8px; width: auto; height: auto; margin: 0; padding: 10px 14px; clip: auto; overflow: visible; z-index: 1000; background: #fff; color: #4c1d95; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); font-weight: 600; }
:focus-visible { outline: 3px solid rgba(109, 74, 255, .45); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------------- App shell ---------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 40; transition: transform .2s ease; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.sidebar-brand img { width: 32px; height: 32px; }
.sidebar-brand small { display: block; font-weight: 500; font-size: 11px; color: var(--sidebar-text); letter-spacing: .02em; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }
.nav-section { margin-top: 16px; }
.nav-section-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #646C8A; padding: 0 10px 6px; font-weight: 650; }
.nav-link { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; color: var(--sidebar-text); font-weight: 520; margin-bottom: 2px; }
.nav-link:hover { background: var(--sidebar-bg-2); color: #fff; text-decoration: none; }
.nav-link.is-active { background: linear-gradient(135deg, rgba(124, 58, 237, .28), rgba(37, 99, 235, .22)); color: var(--sidebar-active); box-shadow: inset 0 0 0 1px rgba(139, 92, 246, .35); }
.nav-link.is-active .icon { color: #C4B5FD; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.06); padding: 12px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; color: #fff; }
.sidebar-user:hover { background: var(--sidebar-bg-2); text-decoration: none; }
.sidebar-user .meta { min-width: 0; flex: 1; }
.sidebar-user .name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .role { font-size: 11.5px; color: var(--sidebar-text); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--grad); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12.5px; flex: none; position: relative; }
.avatar-lg { width: 56px; height: 56px; font-size: 19px; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--c-surface); background: #9AA1B5; }
.avatar .dot.on { background: var(--c-success); }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: rgba(255,255,255,.85); backdrop-filter: saturate(180%) blur(8px); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; gap: 12px; padding: 0 28px; position: sticky; top: 0; z-index: 30; }
.topbar-title { font-weight: 650; font-size: 15px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-toggle { display: none; }
.content { padding: 26px 28px 48px; max-width: 1400px; width: 100%; }
.system-banner { display: flex; align-items: center; gap: 10px; padding: 9px 28px; font-weight: 550; font-size: 13px; }
.system-banner.warn { background: var(--c-warning-50); color: #8A5300; border-bottom: 1px solid #F6DDA8; }
.system-banner.danger { background: var(--c-danger-50); color: #A1172A; border-bottom: 1px solid #F5C2C8; }
.backdrop { display: none; }

/* ---------------- Page header ---------------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-header p { color: var(--c-muted); margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumb { font-size: 12.5px; color: var(--c-muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.breadcrumb a { color: var(--c-muted); }

/* ---------------- Cards & grid ---------------- */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--c-border); }
.card-header p { margin: 2px 0 0; color: var(--c-muted); font-size: 12.5px; }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }
.card + .card { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 18px; }

.stat { padding: 18px 20px; display: flex; gap: 14px; align-items: flex-start; }
.stat-icon { width: 40px; height: 40px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; background: var(--c-primary-50); color: var(--c-primary-600); flex: none; }
.stat-icon.blue { background: #E9F0FF; color: var(--c-blue); }
.stat-icon.green { background: var(--c-success-50); color: var(--c-success); }
.stat-icon.amber { background: var(--c-warning-50); color: var(--c-warning); }
.stat-icon.red { background: var(--c-danger-50); color: var(--c-danger); }
.stat-label { color: var(--c-muted); font-size: 12.5px; font-weight: 550; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin-top: 2px; }
.stat-sub { font-size: 12px; color: var(--c-muted); margin-top: 2px; }

/* ---------------- Buttons ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--c-border-strong); background: var(--c-surface); color: var(--c-text); font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s; text-decoration: none !important; }
.btn:hover { background: var(--c-surface-2); border-color: #C4CAD8; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 1px 2px rgba(91, 55, 240, .3); }
.btn-primary:hover { background: linear-gradient(135deg, #6D28D9 0%, #1D4ED8 100%); border-color: transparent; }
.btn-danger { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #BF2233; border-color: #BF2233; }
.btn-warning { background: #F59E0B; border-color: #F59E0B; color: #1F1300; }
.btn-warning:hover { background: #E08E06; border-color: #E08E06; }
.btn-success { background: var(--c-success); border-color: var(--c-success); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(15, 18, 34, .05); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 36px; padding: 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--c-primary-600); font: inherit; font-weight: 600; cursor: pointer; }
.link-btn.danger { color: var(--c-danger); }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field label, .label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--c-text); }
.field .hint { font-size: 12px; color: var(--c-muted); margin-top: 5px; }
.field .error { font-size: 12.5px; color: var(--c-danger); margin-top: 5px; font-weight: 550; }
.req { color: var(--c-danger); }
.input, .select, .textarea { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm); background: #fff; color: var(--c-text); font: inherit; font-size: 14px; transition: border-color .15s, box-shadow .15s; }
.textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237A8299' 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; background-size: 16px; padding-right: 34px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(109, 74, 255, .15); }
.has-error .input, .has-error .select, .has-error .textarea { border-color: var(--c-danger); }
.input-sm, .select-sm { height: 32px; font-size: 13px; }
.input-group { position: relative; }
.input-group .input { padding-right: 42px; }
.input-group .reveal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; font-weight: 500; }
.check input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--c-primary); flex: none; }
.radio-cards { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.radio-card { border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm); padding: 12px; display: flex; gap: 10px; cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--c-primary); background: var(--c-primary-50); }
.radio-card input { accent-color: var(--c-primary); margin-top: 3px; }
.radio-card strong { display: block; font-size: 13px; }
.radio-card span { font-size: 12px; color: var(--c-muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 18px; margin-top: 6px; border-top: 1px solid var(--c-border); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--c-border); background: var(--c-surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.filters .input, .filters .select { height: 34px; width: auto; min-width: 150px; font-size: 13px; }
.filters .search { position: relative; flex: 1; min-width: 220px; }
.filters .search .input { width: 100%; padding-left: 34px; }
.filters .search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--c-muted); width: 16px; height: 16px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); font-weight: 650; padding: 10px 16px; background: var(--c-surface-2); border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #FBFBFE; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-compact td, .table-compact th { padding: 8px 14px; }
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-user .name { font-weight: 600; color: var(--c-text); }
.cell-user .sub { font-size: 12px; color: var(--c-muted); }
.empty { text-align: center; padding: 42px 20px; color: var(--c-muted); }
.empty .icon { width: 34px; height: 34px; color: #B7BDCC; margin-bottom: 8px; }
.empty h3 { color: var(--c-text-2); margin-bottom: 4px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--c-border); font-size: 13px; color: var(--c-muted); }
.pagination .pages { display: flex; gap: 6px; }

/* ---------------- Badges / pills ---------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; line-height: 1.6; white-space: nowrap; border: 1px solid transparent; }
.badge-success { background: var(--c-success-50); color: #0B7A3C; border-color: #BFE9D1; }
.badge-warning { background: var(--c-warning-50); color: #8A5300; border-color: #F6DDA8; }
.badge-danger { background: var(--c-danger-50); color: #A1172A; border-color: #F5C2C8; }
.badge-info { background: var(--c-info-50); color: #075E8E; border-color: #BFE3F5; }
.badge-primary { background: var(--c-primary-50); color: var(--c-primary-600); border-color: #DCD3FF; }
.badge-muted { background: #F0F2F7; color: #5A6278; border-color: #E1E5EE; }
.badge-dark { background: #1E2235; color: #fff; }
.dot-status { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #B3B9C9; margin-right: 6px; }
.dot-status.on { background: var(--c-success); box-shadow: 0 0 0 3px rgba(18, 161, 80, .15); }

/* ---------------- Alerts / flashes ---------------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: 13.5px; margin-bottom: 16px; }
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--c-success-50); border-color: #BFE9D1; color: #0B5F30; }
.alert-error { background: var(--c-danger-50); border-color: #F5C2C8; color: #8F1424; }
.alert-warning { background: var(--c-warning-50); border-color: #F6DDA8; color: #7A4A00; }
.alert-info { background: var(--c-info-50); border-color: #BFE3F5; color: #075077; }
.alert .close { margin-left: auto; background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 0; }
.alert .close:hover { opacity: 1; }

.secret-box { display: flex; align-items: center; gap: 10px; background: #0F1222; color: #E9E5FF; border-radius: var(--radius-sm); padding: 12px 14px; font-family: var(--mono); font-size: 16px; letter-spacing: .02em; }
.secret-box span { flex: 1; user-select: all; }
.secret-box .btn { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.15); color: #fff; }

/* ---------------- Lists / misc ---------------- */
.kv { display: grid; grid-template-columns: 160px minmax(0,1fr); gap: 10px 16px; font-size: 13.5px; }
.kv dt { color: var(--c-muted); font-weight: 550; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--c-border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; font-size: 13.5px; }
.list-item .sub { font-size: 12px; color: var(--c-muted); }
.muted { color: var(--c-muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; display: inline-block; vertical-align: bottom; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-1 { gap: 8px; } .gap-2 { gap: 16px; } .justify-between { justify-content: space-between; } .wrap { flex-wrap: wrap; }
.divider { height: 1px; background: var(--c-border); margin: 18px 0; border: 0; }
pre.json { background: #0F1222; color: #DCD7FF; padding: 14px 16px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 12.5px; margin: 0; max-height: 420px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--c-border); margin-bottom: 20px; overflow-x: auto; }
.tab { padding: 10px 14px; font-weight: 600; color: var(--c-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--c-text); text-decoration: none; }
.tab.is-active { color: var(--c-primary-600); border-bottom-color: var(--c-primary); }

.role-bars { display: flex; flex-direction: column; gap: 12px; }
.role-bar .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.role-bar .track { height: 8px; background: #EEF0F6; border-radius: 99px; overflow: hidden; }
.role-bar .fill { height: 100%; background: var(--grad); border-radius: 99px; }
.w-0{width:0}.w-5{width:5%}.w-10{width:10%}.w-15{width:15%}.w-20{width:20%}.w-25{width:25%}.w-30{width:30%}.w-35{width:35%}.w-40{width:40%}.w-45{width:45%}.w-50{width:50%}.w-55{width:55%}.w-60{width:60%}.w-65{width:65%}.w-70{width:70%}.w-75{width:75%}.w-80{width:80%}.w-85{width:85%}.w-90{width:90%}.w-95{width:95%}.w-100{width:100%}

.chart-box { position: relative; height: 260px; }

.perm-module { border: 1px solid var(--c-border); border-radius: var(--radius-sm); margin-bottom: 14px; overflow: hidden; }
.perm-module-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--c-surface-2); border-bottom: 1px solid var(--c-border); font-weight: 650; text-transform: capitalize; }
.perm-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--c-border); }
.perm-row:last-child { border-bottom: 0; }
.perm-row .grow { flex: 1; min-width: 0; }
.perm-row .slug { font-family: var(--mono); font-size: 11.5px; color: var(--c-muted); }
.perm-row .select { width: 150px; height: 32px; font-size: 12.5px; }

.toggle-card { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; padding: 18px 20px; }
.toggle-card + .toggle-card { border-top: 1px solid var(--c-border); }
.state-on { color: var(--c-danger); font-weight: 700; }
.state-off { color: var(--c-success); font-weight: 700; }

/* ---------------- Dropdown & modal ---------------- */
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; background: #fff; border: 1px solid var(--c-border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 60; }
.dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 7px; color: var(--c-text); font: inherit; font-weight: 520; background: none; border: 0; cursor: pointer; text-align: left; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--c-surface-2); text-decoration: none; }
.dropdown-menu .sep { height: 1px; background: var(--c-border); margin: 5px 0; }
.dropdown-menu .head { padding: 8px 10px 10px; border-bottom: 1px solid var(--c-border); margin-bottom: 5px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 18, 34, .55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100; }
.modal { background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 440px; }
.modal-body { padding: 22px 22px 8px; }
.modal-body h3 { font-size: 16px; margin-bottom: 8px; }
.modal-body p { color: var(--c-text-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 20px; }

.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #161B2E; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 550; max-width: 360px; }

/* ---------------- Auth layout ---------------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: #fff; }
.auth-brand { background: radial-gradient(1200px 600px at -10% -10%, rgba(124,58,237,.55), transparent 60%), radial-gradient(900px 600px at 110% 110%, rgba(37,99,235,.55), transparent 60%), #0B0E1C; color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-brand .logo { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; }
.auth-brand .logo img { width: 40px; height: 40px; }
.auth-brand h2 { font-size: 34px; line-height: 1.15; letter-spacing: -.03em; max-width: 460px; margin-bottom: 14px; }
.auth-brand p { color: #B9BEDA; max-width: 440px; font-size: 15px; }
.auth-points { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; color: #D5D8EE; }
.auth-points li { display: flex; gap: 10px; align-items: center; }
.auth-points .icon { color: #A78BFA; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card .lead { color: var(--c-muted); margin-bottom: 24px; }
.auth-card .field { margin-bottom: 16px; }
.auth-foot { margin-top: 26px; font-size: 12px; color: var(--c-muted); text-align: center; }
.auth-wide .auth-card { max-width: 560px; }

/* ---------------- Agent (minimal) layout ---------------- */
.agent-shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--c-bg); }
.agent-top { height: 56px; background: #fff; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; gap: 12px; padding: 0 18px; position: sticky; top: 0; z-index: 30; }
.agent-top .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--c-text); margin-right: 8px; }
.agent-nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.agent-nav-link { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 8px; color: var(--c-text-2); font-weight: 600; font-size: 13px; white-space: nowrap; }
.agent-nav-link:hover { background: var(--c-surface-2); text-decoration: none; }
.agent-nav-link.is-active { background: var(--c-primary-50); color: var(--c-primary-600); }
.agent-top .brand img { width: 26px; height: 26px; }
.agent-main { flex: 1; padding: 24px 18px 40px; max-width: 980px; width: 100%; margin: 0 auto; }
.agent-shell, .shell { min-height: 100vh; min-height: 100dvh; }
.agent-nav-link .nav-label { margin-left: 2px; }
/* Narrow / side-by-side windows: labels collapse to icons, then the menu (which has every link) takes over. */
@media (max-width: 900px) {
  .agent-top { padding: 0 10px; gap: 6px; }
  .agent-nav-link .nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .agent-nav-link { padding: 7px 9px; position: relative; }
}
@media (max-width: 560px) { .agent-top .brand-name { display: none; } .agent-top .brand { margin-right: 0; } }
@media (max-width: 360px) { .agent-nav { visibility: hidden; } }
.tabs { scrollbar-width: none; } .tabs::-webkit-scrollbar { display: none; }
body { overflow-x: clip; }

/* ---------------- CRM: shared ---------------- */
.strong { font-weight: 600; color: var(--c-text); }
.text-danger { color: var(--c-danger) !important; }
.mb-1 { margin-bottom: 8px; }
.p-0 { padding: 0 !important; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px; background: var(--c-surface-2); border: 1px solid var(--c-border); font-size: 12px; font-weight: 600; color: var(--c-text-2); white-space: nowrap; }
.pill-dot { width: 8px; height: 8px; flex: none; }
.chip { display: inline-block; padding: 2px 8px; margin: 0 4px 4px 0; border-radius: 6px; background: var(--c-primary-50); color: var(--c-primary-600); font-size: 12.5px; font-weight: 550; overflow-wrap: anywhere; }
kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--c-border-strong); background: var(--c-surface-2); color: var(--c-text-2); }
.kbd-on-primary { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.3); color: #fff; margin-left: 4px; }
.card-warn { border-color: #F3D9A4; }
.card-warn .card-header { background: var(--c-warning-50); border-radius: var(--radius) var(--radius) 0 0; }
.kv-compact { grid-template-columns: 110px minmax(0,1fr); gap: 6px 12px; }
.stat-link { display: block; color: inherit; transition: box-shadow .15s, border-color .15s; }
.stat-link:hover { text-decoration: none; border-color: var(--c-primary); box-shadow: var(--shadow); }
.handoff .label { font-size: 12px; font-weight: 600; color: var(--c-muted); margin-bottom: 6px; }
.note-form { border-bottom: 1px solid var(--c-border); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 8px 20px 16px; }
.tl-item { position: relative; padding: 10px 0 10px 20px; border-left: 2px solid var(--c-border); margin-left: 5px; }
.tl-item::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--c-border-strong); }
.tl-item.tl-note::before { border-color: var(--c-primary); background: var(--c-primary-50); }
.tl-item.tl-system_note::before { border-color: var(--c-warning); }
.tl-head { display: flex; flex-wrap: wrap; gap: 4px; align-items: baseline; font-size: 13px; }
.tl-time { margin-left: auto; white-space: nowrap; }
.tl-body { margin-top: 6px; padding: 10px 12px; background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--radius-sm); white-space: normal; overflow-wrap: anywhere; font-size: 13.5px; }
.tl-detail { margin: 4px 0 0; padding-left: 18px; color: var(--c-text-2); }

/* Pipeline admin */
.config-row > summary { list-style: none; }
.config-row > summary::-webkit-details-marker { display: none; }
.config-summary { display: flex; align-items: center; gap: 12px; padding: 14px 20px; cursor: pointer; }
.config-summary .grow { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.config-row[open] .config-summary { border-bottom: 1px solid var(--c-border); }
.config-row.is-inactive .config-summary { opacity: .65; }
.flag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 16px; }
.inline-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; width: 100%; }
.inline-row .grow { flex: 1; min-width: 160px; }
.input-num { width: 90px !important; }
.input-color { width: 56px; padding: 3px; height: 38px; cursor: pointer; }

/* ---------------- Smart Notepad (desktop-notepad style, fills the window) ---------------- */
.notepad { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.np-window { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: 0; }
.np-titlebar { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--c-border); min-width: 0; }
.np-titlebar h1 { font-size: 15px; margin: 0; white-space: nowrap; }
.np-status { flex: 1; min-width: 0; font-size: 12px; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-help, .np-recent { position: relative; }
.np-help > summary, .np-recent > summary { list-style: none; cursor: pointer; }
.np-help > summary::-webkit-details-marker, .np-recent > summary::-webkit-details-marker { display: none; }
.np-help > summary { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 8px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--c-text-2); }
.np-help > summary:hover { background: var(--c-surface-2); }
.np-help-body, .np-recent-body { position: absolute; right: 0; width: min(340px, calc(100vw - 24px)); background: #fff; border: 1px solid var(--c-border); border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 12.5px; color: var(--c-text-2); z-index: 25; }
.np-help-body { top: calc(100% + 6px); }
.np-help-body p { margin: 0 0 6px; }
.np-recent-body { bottom: calc(100% + 6px); max-height: 50vh; overflow-y: auto; }
.np-text { display: block; flex: 1 1 auto; width: 100%; min-height: 150px; resize: none; margin: 0; padding: 12px 14px; border: 0; border-radius: 0; font: 15px/1.6 var(--mono); color: var(--c-text); background: #fff; tab-size: 4; }
.np-text:focus { outline: none; box-shadow: inset 0 0 0 2px rgba(109, 74, 255, .22); }
.notepad.is-saving .np-text { background: var(--c-surface-2); }
.np-summary { padding: 5px 14px; border-top: 1px solid var(--c-border); background: var(--c-surface-2); font-size: 12.5px; max-height: 32vh; overflow-y: auto; }
.np-summary:empty { display: none; }
.np-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-business { color: var(--c-text); }
.np-issue { padding: 4px 8px; border-radius: 6px; font-size: 12px; margin: 4px 0 2px; }
.np-warn { background: var(--c-warning-50); color: #8A5300; }
.np-error { background: var(--c-danger-50); color: var(--c-danger); font-weight: 600; }
.np-dups { margin: 4px 0 2px; padding: 6px 10px; border-radius: 8px; border: 1px solid #F3D9A4; background: #FFFBF2; font-size: 12.5px; overflow-wrap: anywhere; }
.np-dups-title { font-weight: 700; color: #8A5300; }
.np-dups ul { margin: 0; padding-left: 18px; }
.np-message { margin: 6px 10px; }
.np-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; padding: 8px 10px 8px 14px; border-top: 1px solid var(--c-border); }
.np-field { display: flex; align-items: center; gap: 6px; min-width: 0; margin: 0; font-size: 12.5px; font-weight: 600; color: var(--c-text-2); }
.np-field > span { white-space: nowrap; }
.np-field-assign { flex: 1 1 230px; }
.np-field-assign .select { flex: 1 1 auto; min-width: 0; max-width: 340px; }
.np-cb { position: relative; gap: 2px; }
.np-cb-btn { max-width: 100%; min-width: 0; }
.np-cb-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-cb-btn.is-set { border-color: var(--c-primary, #6D4AFF); color: var(--c-primary, #6D4AFF); background: rgba(109, 74, 255, .07); }
.np-cb-panel { position: absolute; left: 0; bottom: calc(100% + 8px); width: min(340px, calc(100vw - 16px)); max-height: min(640px, calc(100vh - 90px)); max-height: min(640px, calc(100dvh - 90px)); overflow-y: auto; background: #fff; border: 1px solid var(--c-border); border-radius: 12px; box-shadow: var(--shadow); padding: 12px; z-index: 30; font-weight: 400; }
.np-cb-panel[hidden] { display: none; }
.np-cb-head { font-size: 13.5px; font-weight: 700; color: var(--c-text); margin-bottom: 8px; }
.np-cb-quick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.np-cb-choice { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; padding: 7px 9px; border: 1px solid var(--c-border); border-radius: 8px; background: var(--c-surface, #fff); color: var(--c-text); cursor: pointer; text-align: left; font: inherit; }
.np-cb-choice:hover, .np-cb-choice:focus-visible { border-color: var(--c-primary, #6D4AFF); background: rgba(109, 74, 255, .06); outline: none; }
.np-cb-choice.is-active { border-color: var(--c-primary, #6D4AFF); background: rgba(109, 74, 255, .1); }
.np-cb-choice-label { font-size: 13px; font-weight: 600; }
.np-cb-choice-when { font-size: 11.5px; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.np-cb-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; margin-bottom: 10px; border-radius: 9px; background: var(--c-surface-2); border: 1px solid var(--c-border); }
.np-cb-tab { padding: 6px 8px; border: 0; border-radius: 7px; background: transparent; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--c-text-2); cursor: pointer; }
.np-cb-tab[aria-selected="true"] { background: #fff; color: var(--c-primary); box-shadow: var(--shadow-sm); }
.np-cb-pane[hidden] { display: none; }
.np-step { margin: 2px 0 5px; font-size: 12px; font-weight: 700; color: var(--c-text-2); text-transform: uppercase; letter-spacing: .03em; }
.np-cal { margin-bottom: 10px; }
.np-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; font-size: 13px; }
.np-cal-nav { width: 30px; height: 28px; border: 1px solid var(--c-border); border-radius: 7px; background: #fff; font-size: 18px; line-height: 1; color: var(--c-text); cursor: pointer; }
.np-cal-nav:disabled { opacity: .35; cursor: default; }
.np-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.np-cal-dow { text-align: center; font-size: 11px; font-weight: 600; color: var(--c-muted); padding: 2px 0; }
.np-cal-day { height: 30px; border: 1px solid transparent; border-radius: 7px; background: transparent; font: inherit; font-size: 13px; color: var(--c-text); cursor: pointer; }
.np-cal-day:hover:not(:disabled) { background: var(--c-primary-50); }
.np-cal-day.is-today { border-color: var(--c-border-strong, #C9C2E8); font-weight: 700; }
.np-cal-day.is-active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; font-weight: 700; }
.np-cal-day:disabled { color: var(--c-muted); opacity: .4; cursor: default; }
.np-hours { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-bottom: 6px; }
.np-mins { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.np-chip { height: 30px; padding: 0 2px; border: 1px solid var(--c-border); border-radius: 7px; background: #fff; font: inherit; font-size: 12px; font-weight: 600; color: var(--c-text); white-space: nowrap; cursor: pointer; }
.np-chip:hover:not(:disabled) { border-color: var(--c-primary); background: var(--c-primary-50); }
.np-chip.is-active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.np-chip:disabled { opacity: .35; cursor: default; }
.np-pick-summary { margin: 8px 0 6px; font-size: 13px; font-weight: 600; color: var(--c-text); min-height: 18px; }
.np-pick-summary:empty { display: none; }
.np-cb-error { margin-top: 6px; padding: 4px 8px; border-radius: 6px; background: var(--c-danger-50); color: var(--c-danger); font-size: 12px; font-weight: 600; }
.np-cb-foot { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.np-cb-foot .small { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.np-chat { flex: none; }

.segmented { display: inline-flex; border: 1px solid var(--c-border-strong); border-radius: 9px; padding: 3px; margin: 0; gap: 2px; background: var(--c-surface-2); max-width: 100%; overflow: hidden; }

/* The notepad page fills the window exactly — no page scrollbar, the text box grows/shrinks. */
.agent-shell:has(.notepad), .shell:has(.notepad) { height: 100vh; height: 100dvh; min-height: 0; }
.agent-shell:has(.notepad) .agent-main, .shell:has(.notepad) .main, .shell:has(.notepad) .content { display: flex; flex-direction: column; min-height: 0; }
.agent-shell:has(.notepad) .agent-main { max-width: 1100px; padding-top: 12px; padding-bottom: 12px; }
.shell:has(.notepad) .content { flex: 1 1 auto; padding-top: 14px; padding-bottom: 14px; }
.agent-main > .notepad, .content > .notepad { flex: 1 1 auto; }
@media (max-width: 640px) {
  .agent-shell:has(.notepad) .agent-main, .shell:has(.notepad) .content { padding: 8px; }
  .np-field-assign { flex-basis: 100%; }
  .np-field-assign .select { max-width: none; }
  .np-field-callback { flex: 1 1 100%; }
  .np-cb-btn { flex: 1 1 auto; justify-content: center; }
  .np-actions { flex: 1 1 100%; }
  .np-actions .btn { flex: 1; justify-content: center; }
  .np-actions .np-recent { flex: none; }
}
@media (max-width: 400px) {
  .np-cb-choice { padding: 6px 7px; }
  .np-cb-choice-label { font-size: 12.5px; }
  .np-titlebar { padding-left: 10px; }
  .np-bar { padding-left: 10px; }
}
@media (max-height: 520px) { .np-text { min-height: 96px; } .np-summary { max-height: 20vh; } }

/* ---------------- Responsive ---------------- */
@media (max-width: 1180px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid-main { grid-template-columns: minmax(0,1fr); } }
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .shell.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .shell.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(15,18,34,.45); z-index: 35; }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .topbar, .content, .system-banner { padding-left: 16px; padding-right: 16px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0,1fr); }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
}
@media (max-width: 640px) {
  .grid-4 { grid-template-columns: minmax(0,1fr); }
  .form-grid { grid-template-columns: minmax(0,1fr); }
  .kv { grid-template-columns: minmax(0,1fr); gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .radio-cards { grid-template-columns: minmax(0,1fr); }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.narrow { max-width: 600px; }
.d-block { display: block; }
.narrow-lg { max-width: 920px; }
.grow { flex: 1; min-width: 0; }
a.card { color: inherit; transition: border-color .15s, box-shadow .15s; }
a.card:hover { text-decoration: none; border-color: #CFC4FF; box-shadow: var(--shadow); }

/* ---------------- Phase 3: callbacks & notifications ---------------- */
.nav-count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--c-danger); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.nav-count[hidden] { display: none; }
.agent-nav-link .nav-count { margin-left: 2px; }
.bell { position: relative; }
.bell .nav-count { position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; font-size: 10px; padding: 0 4px; margin: 0; border: 2px solid #fff; box-sizing: content-box; }
.bell.is-active { background: var(--c-primary-50); color: var(--c-primary-600); }

.when-picker { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
.when-picker legend { padding: 0; }
.when-picker .error { font-size: 12.5px; color: var(--c-danger); margin: 6px 0; font-weight: 550; }
.when-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 6px; margin-bottom: 10px; }
.when-opt { position: relative; display: block; cursor: pointer; }
.when-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.when-opt > span { display: block; height: 100%; border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm); padding: 7px 9px; background: #fff; transition: border-color .12s, background .12s; }
.when-opt strong { display: flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 650; }
.when-opt small { display: block; font-size: 11.5px; color: var(--c-muted); margin-top: 1px; }
.when-opt:hover > span { border-color: #BFB2FF; }
.when-opt input:checked + span { border-color: var(--c-primary); background: var(--c-primary-50); box-shadow: inset 0 0 0 1px var(--c-primary); }
.when-opt input:focus-visible + span { outline: 2px solid var(--c-primary); outline-offset: 2px; }
.when-custom { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 10px; }
.when-custom[hidden] { display: none; }
.when-custom .field { margin-bottom: 8px; }

.callback-card.is-urgent { border-color: #F5C2C8; box-shadow: 0 0 0 3px rgba(220, 46, 63, .08); }
.callback-card .card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.callback-when { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.callback-time { font-size: 16px; font-weight: 700; color: var(--c-text); }
.callback-notes { background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: 8px 10px; margin: 0 0 12px; overflow-wrap: anywhere; }
.callback-form .field { margin-bottom: 10px; }
.callback-more > summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--c-primary-600); display: flex; align-items: center; gap: 6px; padding: 4px 0; list-style: none; }
.callback-more > summary::-webkit-details-marker { display: none; }
.callback-more[open] > summary { margin-bottom: 8px; }
.callback-history { list-style: none; margin: 0; padding: 0; }
.callback-history li { padding: 6px 0; border-top: 1px solid var(--c-border); overflow-wrap: anywhere; }
.callback-history li:first-child { border-top: 0; }

.callback-row-time { width: 92px; flex: none; display: flex; flex-direction: column; }
.callback-row-time strong { font-size: 14px; }
.callback-row.is-overdue, .callback-row.is-missed { box-shadow: inset 3px 0 0 var(--c-danger); }
.callback-row.is-due { box-shadow: inset 3px 0 0 var(--c-warning); }
.callback-row .sub a { color: inherit; }

.segmented .seg-link { display: block; padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--c-text-2); }
.segmented .seg-link:hover { text-decoration: none; color: var(--c-text); }
.segmented .seg-link.is-active { background: #fff; color: var(--c-primary-600); box-shadow: var(--shadow-sm); }
.tab .badge { margin-left: 4px; }

.notif { align-items: flex-start; }
.notif.is-unread { background: #FBFAFF; }
.notif.is-unread .title::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c-primary); margin-right: 7px; vertical-align: middle; }
.notif-icon { width: 32px; height: 32px; flex: none; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; background: var(--c-primary-50); color: var(--c-primary-600); }
.notif-high .notif-icon { background: var(--c-warning-50); color: var(--c-warning); }
.notif-urgent .notif-icon { background: var(--c-danger-50); color: var(--c-danger); }
.notif .sub { overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .when-custom { grid-template-columns: minmax(0, 1fr); }
  .callback-row { flex-wrap: wrap; }
  .callback-row-time { width: auto; flex-direction: row; gap: 6px; align-items: baseline; }
}

/* ---------------- Phase 4: shifts, attendance, devices ---------------- */
.d-inline { display: inline; }
.border-top { border-top: 1px solid var(--c-border); }
.border-bottom { border-bottom: 1px solid var(--c-border); }
.icon-flip { transform: scaleX(-1); }
.table tr.is-inactive td, .list-item.is-inactive { opacity: .6; }
.tabs.tabs-inline { border-bottom: 0; margin-bottom: 0; flex-wrap: wrap; }
.fieldset { border: 1px solid var(--c-border); border-radius: 10px; padding: 12px 16px 14px; margin: 16px 0; min-width: 0; }
.fieldset legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
.fieldset.has-error { border-color: var(--c-danger, #DC2E3F); }
.fieldset .flag-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.break-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(96px, 1fr) auto minmax(96px, 1fr) auto; gap: 8px; align-items: center; margin-top: 8px; }
.break-row .error { grid-column: 1 / -1; }
.break-row.has-error .input { border-color: var(--c-danger, #DC2E3F); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat-mini { background: var(--c-surface, #fff); border: 1px solid var(--c-border); border-radius: 12px; padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat-mini .label { font-size: 12px; color: var(--c-muted); font-weight: 550; }
.stat-mini strong { font-size: 20px; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .break-row { grid-template-columns: 1fr 1fr; }
  .break-row > .muted { display: none; }
}

/* ---------------- Phase 5: group chat ---------------- */
.chat-page { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
.chat-side { padding: 14px 10px; position: sticky; top: 12px; max-height: calc(100vh - 120px); overflow: auto; }
.chat-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 6px 10px; }
.chat-side-head h2 { font-size: 15px; margin: 0; }
.chat-side-group + .chat-side-group { margin-top: 12px; }
.chat-side-title { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--c-muted); padding: 4px 8px; }
.chat-side-empty { padding: 0 8px; }
.chat-channel-list { list-style: none; margin: 0; padding: 0; }
.chat-channel { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 8px; color: var(--c-text-2); text-decoration: none !important; font-weight: 550; font-size: 13.5px; }
.chat-channel:hover { background: var(--c-surface-2); color: var(--c-text); }
.chat-channel.is-active { background: var(--c-primary-50); color: var(--c-primary-600); }
.chat-channel .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-hash { color: var(--c-muted); font-weight: 700; margin-right: 2px; }
.chat-channel .nav-count { background: var(--c-primary); color: #fff; }
.chat-main { display: flex; flex-direction: column; min-height: 420px; height: calc(100vh - 120px); position: relative; overflow: hidden; }
.chat-header { display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--c-border); }
.chat-header h1 { font-size: 18px; margin: 0 0 2px; }
.chat-note { padding: 8px 18px; background: var(--c-info-50); color: #075985; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.chat-scroll { flex: 1 1 auto; overflow-y: auto; padding: 10px 6px 10px 0; outline: none; }
.chat-scroll:focus-visible { box-shadow: inset 0 0 0 2px rgba(109, 74, 255, .35); }
.chat-older { text-align: center; padding: 6px 0 10px; }
.chat-empty { padding: 48px 16px; }
.chat-messages { list-style: none; margin: 0; padding: 0; }
.chat-msg { display: flex; gap: 10px; padding: 7px 18px; position: relative; }
.chat-msg:hover, .chat-msg:focus-within { background: var(--c-surface-2); }
.chat-msg.is-highlight { background: #FFF8E1; transition: background 1.5s; }
.chat-avatar { width: 32px; height: 32px; font-size: 11.5px; margin-top: 2px; }
.chat-msg.is-own .chat-avatar { background: linear-gradient(135deg, #2F6BFF, #6D4AFF); }
.chat-msg-main { min-width: 0; flex: 1 1 auto; }
.chat-msg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.chat-author { font-size: 13.5px; }
.chat-role { font-size: 11.5px; color: var(--c-muted); }
.chat-time, .chat-edited { font-size: 11.5px; color: var(--c-muted); text-decoration: none !important; }
.chat-time:hover { text-decoration: underline !important; }
.chat-body { font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; white-space: normal; margin-top: 1px; }
.chat-body a { overflow-wrap: anywhere; }
.chat-body-deleted { color: var(--c-muted); font-style: italic; display: flex; align-items: center; gap: 4px; }
.chat-actions { display: flex; gap: 10px; margin-top: 2px; opacity: 0; transition: opacity .12s; }
.chat-msg:hover .chat-actions, .chat-msg:focus-within .chat-actions, .chat-msg.is-editing .chat-actions { opacity: 1; }
@media (hover: none) { .chat-actions { opacity: 1; } }
.chat-action { background: none; border: 0; padding: 0; font: inherit; font-size: 12px; font-weight: 600; color: var(--c-muted); cursor: pointer; text-decoration: none !important; }
.chat-action:hover, .chat-action:focus-visible { color: var(--c-primary-600); text-decoration: underline !important; }
.chat-action.text-danger:hover { color: var(--c-danger) !important; }
.mention { background: var(--c-primary-50); color: var(--c-primary-600); border-radius: 5px; padding: 0 3px; font-weight: 600; }
.mention.is-me { background: #FFF1C2; color: #7A4A00; }
.mention-group { background: var(--c-info-50); color: #075985; }
.chat-tag { display: inline-block; background: var(--c-success-50); color: #0B6B37; border-radius: 5px; padding: 0 4px; font-weight: 600; text-decoration: none !important; }
.chat-tag:hover { text-decoration: underline !important; }
.chat-tag.is-locked { background: #F0F2F7; color: #5A6278; cursor: help; }
.chat-divider { display: flex; align-items: center; gap: 10px; padding: 6px 18px; color: var(--c-danger); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.chat-divider::before, .chat-divider::after { content: ""; flex: 1; height: 1px; background: #F4B7BE; }
.chat-jump { position: absolute; left: 50%; transform: translateX(-50%); bottom: 118px; border: 0; border-radius: 999px; background: var(--c-primary); color: #fff; font: inherit; font-size: 12.5px; font-weight: 600; padding: 6px 14px; box-shadow: var(--shadow-sm); cursor: pointer; display: inline-flex; gap: 4px; align-items: center; z-index: 2; }
.chat-jump[hidden] { display: none; }
.chat-composer { border-top: 1px solid var(--c-border); padding: 10px 14px 12px; background: var(--c-surface); }
.chat-input-wrap { position: relative; }
.chat-input { min-height: 46px; max-height: 200px; resize: none; }
.chat-composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.chat-composer.is-sending .chat-input { opacity: .7; }
.chat-composer .is-error { color: var(--c-danger); }
.chat-suggest { position: absolute; left: 0; right: 0; bottom: calc(100% + 4px); list-style: none; margin: 0; padding: 4px; background: #fff; border: 1px solid var(--c-border-strong); border-radius: 10px; box-shadow: 0 8px 24px rgba(15, 18, 34, .12); max-height: 240px; overflow: auto; z-index: 5; }
.chat-suggest[hidden] { display: none; }
.chat-suggest li { display: flex; align-items: baseline; gap: 8px; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.chat-suggest li[aria-selected="true"], .chat-suggest li:hover { background: var(--c-primary-50); }
.chat-suggest .hint { color: var(--c-muted); font-size: 12px; margin-left: auto; text-align: right; }
.chat-edit-form { margin-top: 4px; }
.chat-edit-form .textarea { min-height: 64px; }
.chat-edit-form .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; align-items: center; }
.chat-readonly { border-top: 1px solid var(--c-border); padding: 14px 18px; color: var(--c-muted); font-size: 13.5px; display: flex; gap: 6px; align-items: center; background: var(--c-surface-2); }
.chat-history-body { white-space: normal; overflow-wrap: anywhere; }
.chat-ref-body { font-size: 13.5px; overflow-wrap: anywhere; margin-top: 2px; }
.member-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 16px; max-height: 320px; overflow: auto; padding: 2px; }
@media (max-width: 960px) {
  .chat-page { grid-template-columns: minmax(0, 1fr); }
  .chat-side { position: static; max-height: none; }
  .chat-channel-list { display: flex; flex-wrap: wrap; gap: 4px; }
  .chat-side-group + .chat-side-group { margin-top: 6px; }
  .chat-main { height: calc(100vh - 90px); }
}
@media (max-width: 640px) {
  .chat-msg { padding: 7px 10px; }
  .chat-header { padding: 12px; }
  .chat-jump { bottom: 128px; }
}
.btn .nav-count { margin-left: 2px; }

/* ---------------------------------------------------------------- Phase 6: notifications */
.h-sub { font-size: 14px; font-weight: 650; margin: 0 0 4px; }
.center { text-align: center; }
.pref-table th[scope="row"] { font-weight: 550; }
.pref-table input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--c-primary); }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-item { display: flex; align-items: flex-start; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--c-border); }
.device-item:first-child { border-top: 0; }
.device-item .grow { flex: 1; min-width: 0; }
.device-item .badge { margin-right: 4px; }
.device-item.is-inactive { opacity: .65; }
.health-list { list-style: none; margin: 0; padding: 0; }
.health-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--c-border); }
.health-list li:first-child { border-top: 0; padding-top: 0; }
.health-list .icon { flex: none; margin-top: 1px; }
.health-ok { color: var(--c-success, #12805c); }
.health-bad { color: var(--c-danger, #c62a3a); }
.delivery-error { max-width: 340px; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- Phase 7: reports, deals, backups */
.report-filters { border-radius: var(--radius); border-bottom: 0; }
.report-filters .select { min-width: 140px; }
.report-range { display: inline-flex; align-items: center; gap: 6px; }
.report-range[hidden] { display: none; }
.report-range .input { min-width: 0; width: 150px; }
.report-label { margin-left: auto; }
.kpi .stat-value { font-size: 24px; }
.kpi-delta { margin-top: 4px; font-weight: 600; }
.kpi-delta.is-up { color: var(--c-success, #12805c); }
.kpi-delta.is-down { color: var(--c-danger, #c62a3a); }
.report-table td:first-child { white-space: nowrap; }
.report-table tfoot th, .report-table tfoot td { border-top: 2px solid var(--c-border); background: var(--c-surface-2); padding: 8px 14px; }
.bar-track { height: 5px; background: #EEF0F6; border-radius: 99px; overflow: hidden; margin-top: 6px; max-width: 220px; }
.bar-fill { height: 100%; background: var(--grad); border-radius: 99px; }
.report-help > summary { cursor: pointer; list-style: revert; }
.dropdown-inline { position: relative; display: inline-block; }
.dropdown-inline > summary { list-style: none; }
.dropdown-inline > summary::-webkit-details-marker { display: none; }
.dropdown-menu-inline { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 230px; background: #fff; border: 1px solid var(--c-border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; }
.dropdown-menu-inline a { padding: 8px 10px; border-radius: 8px; color: inherit; font-size: 13.5px; }
.dropdown-menu-inline a:hover { background: var(--c-surface-2); text-decoration: none; }
.deal-amount { font-size: 20px; margin: 0 0 8px; font-variant-numeric: tabular-nums; }
.backup-file { font-family: var(--font-mono, ui-monospace, monospace); font-size: 12.5px; overflow-wrap: anywhere; }
@media (max-width: 760px) { .report-label { margin-left: 0; width: 100%; } .report-range .input { width: 130px; } }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-head .h-sub { margin: 0; }

/* ---------------------------------------------------------------------
   Phase 8 — offline page (served by the service worker) and install button
   --------------------------------------------------------------------- */
.offline-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--c-bg); }
.offline-card { max-width: 440px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 16px; padding: 32px 28px; text-align: center; box-shadow: 0 10px 30px rgba(15, 18, 34, .06); }
.offline-card h1 { font-size: 1.4rem; margin: 14px 0 8px; }
.offline-card p { color: var(--c-text-2); margin: 0 0 12px; }
.offline-card .btn { margin-top: 8px; }
.offline-logo { width: 56px; height: 56px; }

/* ------------------------------------------------------------ floating team chat (bottom-right bubble) */
.chat-fab { position: fixed; right: 16px; bottom: 16px; z-index: 90; font-size: 14px; }
.chat-fab-btn { position: relative; width: 54px; height: 54px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: var(--c-primary, #6D4AFF); color: #fff; box-shadow: 0 6px 20px rgba(76, 29, 149, .35); transition: transform .15s ease, background .15s ease; }
.chat-fab-btn:hover { background: var(--c-primary-600, #5B37F0); transform: translateY(-1px); }
.chat-fab-btn:focus-visible { outline: 3px solid rgba(109, 74, 255, .45); outline-offset: 3px; }
.chat-fab-btn .icon { width: 24px; height: 24px; }
.chat-fab-btn .nav-count { position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: #E5484D; color: #fff;
  font-size: 11px; font-weight: 700; line-height: 20px; text-align: center; box-shadow: 0 0 0 2px #fff; margin: 0; }
.chat-fab.is-open .chat-fab-btn .nav-count { display: none; }
.cw-panel { position: absolute; right: 0; bottom: 66px; width: min(380px, calc(100vw - 32px)); height: min(540px, calc(100vh - 100px)); height: min(540px, calc(100dvh - 100px));
  display: flex; flex-direction: column; background: #fff; border: 1px solid var(--c-border); border-radius: 14px; box-shadow: 0 18px 50px rgba(22, 27, 46, .22); overflow: hidden; }
.cw-panel[hidden] { display: none; }
.cw-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 12px; background: var(--c-primary, #6D4AFF); color: #fff; }
.cw-title { display: flex; align-items: center; gap: 6px; font-weight: 700; white-space: nowrap; }
.cw-channel { flex: 1 1 auto; min-width: 0; }
.cw-head .btn-ghost { color: #fff; }
.cw-head .btn-ghost:hover { background: rgba(255, 255, 255, .18); }
.cw-messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 6px 0; background: var(--c-surface-2, #F9FAFC); }
.cw-messages .chat-msg { padding: 6px 12px; }
.cw-messages .chat-actions { display: none; }
.cw-note { padding: 8px 12px; font-size: 12.5px; color: var(--c-text-2); background: var(--c-surface-2, #F9FAFC); border-top: 1px solid var(--c-border); }
.cw-compose { display: flex; align-items: flex-end; gap: 6px; padding: 8px; border-top: 1px solid var(--c-border); }
.cw-input-wrap { position: relative; flex: 1 1 auto; min-width: 0; display: flex; }
.cw-input { flex: 1 1 auto; min-width: 0; resize: none; min-height: 38px; max-height: 120px; }
.cw-suggest { max-height: 200px; }
.cw-suggest li { font-size: 13px; }
.cw-suggest li > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Keep clear of the notepad's bottom bar (Save sits at its right end) and of toasts. */
body:has(.chat-fab) .np-bar { padding-right: 66px; }
body:has(.notepad) .chat-fab { right: 10px; bottom: 6px; }
body:has(.notepad) .chat-fab-btn { width: 44px; height: 44px; }
body:has(.notepad) .cw-panel { bottom: 54px; }
body:has(.chat-fab) .toast-stack { bottom: 84px; }
@media (max-width: 520px) {
  .chat-fab { right: 12px; bottom: 12px; }
  .cw-panel { position: fixed; left: 8px; right: 8px; top: 8px; bottom: 74px; width: auto; height: auto; }
  body:has(.notepad) .cw-panel { bottom: 58px; }
}
@media print { .chat-fab { display: none; } }

/* ------------------------------------------------------------------ installer (app/Install) */
.install-body { background: var(--c-surface-2, #F9FAFC); min-height: 100vh; }
.install-top { display: flex; align-items: center; gap: 10px; padding: 14px 20px; background: #0B0E1C; color: #fff; }
.install-top img { width: 32px; height: 32px; }
.install { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }
.install-intro h1 { font-size: 26px; margin-bottom: 6px; }
.install-intro .lead { color: var(--c-text-2); margin-bottom: 18px; }
.install-card { margin-bottom: 16px; }
.install-card h1 { font-size: 24px; margin-bottom: 8px; }
.install-h2 { display: flex; align-items: center; gap: 10px; font-size: 17px; margin: 4px 0 12px; }
.install-card .install-h2 + p { margin-top: -4px; }
.install-num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--c-primary, #6D4AFF); color: #fff; font-size: 13px; font-weight: 700; flex: none; }
.install-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.install-checks li { display: flex; gap: 10px; align-items: flex-start; }
.install-checks .hint { display: block; }
.install-mark { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; font-weight: 700; flex: none; color: #fff; }
.install-checks .is-ok .install-mark { background: var(--c-success, #12A150); }
.install-checks .is-bad .install-mark { background: #E5484D; }
.install-checks .is-warn .install-mark { background: #D97706; }
.install-checks li > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.install-form .form-grid { margin-bottom: 4px; }
.install-wide { grid-column: 1 / -1; }
.install-more { margin: 8px 0 4px; }
.install-more summary { cursor: pointer; color: var(--c-text-2); font-size: 13px; }
.install-more .field { max-width: 200px; margin-top: 8px; }
.install-test { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.install-ok { color: var(--c-success, #12A150); }
.install-bad { color: #C9353A; }
.install-note { text-align: center; margin-top: 10px; }
.install-steps, .install-list { padding-left: 20px; display: grid; gap: 8px; margin: 0 0 14px; }
.install-copy { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding: 8px 10px; background: var(--c-surface-2, #F9FAFC); border: 1px solid var(--c-border); border-radius: 8px; }
.install-copy code { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
.install-list code { overflow-wrap: anywhere; }
@media (max-width: 640px) { .install-form .form-grid { grid-template-columns: 1fr; } }

/* ---- Permanent-delete controls ---- */
.inline-form { display: inline-flex; margin: 0; }
.tl-delete { display: inline-flex; margin: 0 0 0 4px; }
.tl-delete .btn-icon { width: 24px; height: 24px; opacity: .55; }
.tl-item:hover .tl-delete .btn-icon, .tl-delete .btn-icon:focus-visible { opacity: 1; }
@media (hover: none) { .tl-delete .btn-icon { opacity: .8; } }
.trash-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.trash-bar form { margin: 0; }
.steps-list { margin: 4px 0 0; padding-left: 20px; display: grid; gap: 4px; }
.col-choice { width: 170px; }
