/* ============================================================
   Tender Hub (V2) — design system
   Light, friendly, dense-but-calm. Custom (no framework).
   ============================================================ */
:root {
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.12);
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --ink: #0f172a;
    --ink-2: #475569;
    --ink-3: #94a3b8;
    --line: #e2e8f0;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .18);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --success: #16a34a; --success-bg: #dcfce7;
    --warning: #d97706; --warning-bg: #fef3c7;
    --danger:  #dc2626; --danger-bg:  #fee2e2;
    --info:    #2563eb; --info-bg:    #dbeafe;
    --muted:   #64748b; --muted-bg:   #e2e8f0;
    --sidebar: #0b1120;
    --sidebar-2: #111a2e;
   --sidebar-width: 252px;
   --sidebar-rail-width: 76px;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font-size: 14.5px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; color: var(--ink); font-weight: 650; letter-spacing: -.01em; }
svg.emblem, svg.avatar { display: block; flex: none; }
.avatar-sm { display: grid; place-items: center; }
.avatar-sm svg { width: 100%; height: 100%; display: block; }

/* -------- Layout shell -------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-width); flex: none; overflow-x: hidden; background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2)); color: #cbd5e1; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; height: 100dvh; transition: width .26s cubic-bezier(.4, 0, .2, 1); }
.sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px; }
.sidebar .brand-copy { min-width: 0; white-space: nowrap; opacity: 1; transition: opacity .16s ease, width .26s cubic-bezier(.4, 0, .2, 1); }
.sidebar .brand .name { color: #fff; font-weight: 700; font-size: 15px; line-height: 1.1; }
.sidebar .brand .sub { color: #7c89a3; font-size: 11px; }
.nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav .label { max-height: 24px; overflow: hidden; color: #5b6783; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; margin: 14px 10px 6px; opacity: 1; transition: opacity .14s ease, max-height .22s ease, margin .22s ease; }
.nav a { position: relative; display: flex; align-items: center; gap: 11px; min-height: 38px; padding: 9px 11px; overflow: hidden; white-space: nowrap; border-radius: 9px; color: #aeb9d0; font-weight: 500; font-size: 13.5px; transition: gap .22s ease, padding .22s ease, background-color .15s ease, color .15s ease; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; box-shadow: 0 6px 16px -8px var(--accent); }
.nav a svg { width: 17px; height: 17px; flex: none; }
.nav a .nav-text { max-width: 180px; overflow: hidden; text-overflow: ellipsis; opacity: 1; transition: max-width .24s cubic-bezier(.4, 0, .2, 1), opacity .14s ease; }
.nav a .pilln { margin-left: auto; background: rgba(255,255,255,.14); color: #fff; font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.sidebar .userbox { border-top: 1px solid rgba(255,255,255,.07); padding: 12px; display: flex; align-items: center; gap: 10px; transition: padding .22s ease, gap .22s ease; }
.sidebar .userbox .meta { min-width: 0; opacity: 1; transition: opacity .14s ease; }
.sidebar .userbox .meta .n { color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .userbox .meta .r { color: #7c89a3; font-size: 11px; }
.sidebar .userbox form { margin-left: auto; }
.icon-btn { background: rgba(255,255,255,.08); border: 0; color: #cbd5e1; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255,255,255,.16); color: #fff; }

.sidebar-collapsed .sidebar { width: var(--sidebar-rail-width); }
.sidebar-collapsed .sidebar .brand { gap: 0; }
.sidebar-collapsed .sidebar .brand-copy { width: 0; opacity: 0; }
.sidebar-collapsed .sidebar .nav { padding-inline: 10px; }
.sidebar-collapsed .sidebar .nav .label { max-height: 0; margin-block: 0; opacity: 0; }
.sidebar-collapsed .sidebar .nav a { justify-content: center; gap: 0; padding-inline: 0; }
.sidebar-collapsed .sidebar .nav-text { max-width: 0; opacity: 0; }
.sidebar-collapsed .sidebar .nav a .pilln { position: absolute; top: 3px; right: 3px; min-width: 14px; padding: 0 4px; font-size: 9px; text-align: center; }
.sidebar-collapsed .sidebar .userbox { justify-content: center; gap: 0; padding-inline: 10px; }
.sidebar-collapsed .sidebar .userbox .meta,
.sidebar-collapsed .sidebar .userbox form { width: 0; margin: 0; overflow: hidden; opacity: 0; pointer-events: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 62px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 0 26px; position: sticky; top: 0; z-index: 20; }
.topbar > div:not(.spacer) { min-width: 0; }
.topbar h1 { overflow: hidden; margin: 0; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumb { overflow: hidden; color: var(--ink-3); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.bell { position: relative; }
.bell .dot { position: absolute; top: -3px; right: -3px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
.content { container: app-content / inline-size; padding: 24px 26px 48px; max-width: 1320px; width: 100%; margin-inline: auto; }

/* -------- Cards & grid -------- */
.card { container: card / inline-size; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card .hd { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card .hd h3 { margin: 0; font-size: 14.5px; }
.card .hd .spacer { flex: 1; }
.card .bd { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mb-16 { margin-bottom: 16px; }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* -------- KPI tiles -------- */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.kpi .k-label { color: var(--ink-2); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.kpi .k-ico { width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.kpi .k-ico svg { width: 17px; height: 17px; }
.kpi .k-value { font-size: 25px; font-weight: 720; letter-spacing: -.02em; margin-top: 8px; }
.kpi .k-foot { color: var(--ink-3); font-size: 12px; margin-top: 3px; }

/* -------- Badges & chips -------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; line-height: 1.4; }
.badge.success { color: var(--success); background: var(--success-bg); }
.badge.warning { color: var(--warning); background: var(--warning-bg); }
.badge.danger  { color: var(--danger);  background: var(--danger-bg); }
.badge.info    { color: var(--info);    background: var(--info-bg); }
.badge.muted   { color: var(--muted);   background: var(--muted-bg); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--ink-2); background: var(--surface-2); }
.chip.small { padding: 3px 8px; font-size: 11px; }
.chip svg { opacity: .8; }
.pill-accent { background: var(--accent-soft); color: var(--accent); border: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* -------- Tables -------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; color: var(--ink-3); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table.tight td, .table.tight th { padding: 8px 10px; }

/* -------- Progress -------- */
.progress { height: 8px; background: var(--muted-bg); border-radius: 99px; overflow: hidden; min-width: 90px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.progress.success > span { background: var(--success); }
.progress.warning > span { background: var(--warning); }
.progress.danger  > span { background: var(--danger); }

/* -------- Buttons -------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 15px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 13.5px; cursor: pointer; transition: .15s; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 8px 18px -10px var(--accent); }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); border-color: var(--danger-bg); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-group { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface-2); }
.btn-group button { border: 0; background: transparent; padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn-group button.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

/* -------- Forms -------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, .select, .textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-size: 14px; color: var(--ink); font-family: inherit; transition: .15s; }
.input:focus, .select:focus, .textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { min-height: 90px; resize: vertical; }
.hint { color: var(--ink-3); font-size: 12px; margin-top: 5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) { .form-grid, .form-grid.three { grid-template-columns: 1fr; } }

/* -------- Alerts / flash -------- */
.alert { padding: 12px 15px; border-radius: 10px; font-size: 13.5px; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid transparent; }
.alert.success { background: var(--success-bg); color: #166534; border-color: #bbf7d0; }
.alert.error   { background: var(--danger-bg);  color: #991b1b; border-color: #fecaca; }
.alert.info    { background: var(--info-bg);     color: #1e40af; border-color: #bfdbfe; }
.alert.warning { background: var(--warning-bg);  color: #92400e; border-color: #fde68a; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* -------- Misc -------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-2); font-size: 13.5px; margin-top: 3px; max-width: 680px; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }
.strong { font-weight: 680; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.tag { font-size: 11px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); padding: 2px 7px; border-radius: 6px; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.empty svg { width: 38px; height: 38px; opacity: .5; margin-bottom: 10px; }
.ai-panel { background: linear-gradient(180deg, #faf5ff, #f5f3ff); border: 1px solid #e9d5ff; border-radius: var(--radius); }
.ai-panel .hd { border-color: #e9d5ff; }
.ai-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; color: #7c3aed; background: #f3e8ff; padding: 3px 9px; border-radius: 999px; }
.spin { width: 16px; height: 16px; border: 2px solid rgba(124,58,237,.3); border-top-color: #7c3aed; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
canvas { max-width: 100%; }
.stars { color: #f59e0b; letter-spacing: 1px; font-size: 12.5px; }
.stars .off { color: var(--line); }

/* -------- Tabs -------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 8px 15px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--ink-2); text-decoration: none; display: inline-flex; align-items: center; gap: 7px; }
.tab:hover { text-decoration: none; background: var(--surface-2); }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* -------- Auth -------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .brandside { background: linear-gradient(150deg, #1e3a8a, #2563eb 55%, #0ea5e9); color: #fff; padding: 48px; display: flex; flex-direction: column; gap: 26px; }
.auth .brandside .logo { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; }
.auth .brandside h2 { color: #fff; font-size: 30px; line-height: 1.15; max-width: 460px; margin: auto 0 8px; }
.auth .brandside p.lede { color: rgba(255,255,255,.9); max-width: 460px; margin: 0; }
.auth .feats { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.auth .feat { display: flex; gap: 11px; align-items: flex-start; color: #fff; font-size: 13.5px; }
.auth .feat svg { flex: none; opacity: .95; margin-top: 1px; }
.auth .formside { display: flex; align-items: center; justify-content: center; padding: 40px; background: var(--bg); }
.auth .formcard { width: 100%; max-width: 400px; }
.auth .accounts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 260px; overflow: auto; }
.auth .acct { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface); text-align: left; width: 100%; }
.auth .acct:hover { border-color: var(--accent); background: var(--surface-2); }
.auth .acct.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth .acct .nm { font-weight: 600; font-size: 13px; }
.auth .acct .em { font-size: 11.5px; color: var(--ink-3); }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth .brandside { display: none; } }

/* -------- Hamburger / mobile drawer -------- */
.hamburger { display: grid; flex: none; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); width: 36px; height: 36px; border-radius: 9px; cursor: pointer; place-items: center; transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .2s ease; }
.hamburger:hover { border-color: var(--accent); color: var(--accent); }
.hamburger:focus-visible { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hamburger:active { transform: scale(.96); }
.nav-backdrop { position: fixed; inset: 0; z-index: 90; visibility: hidden; opacity: 0; pointer-events: none; background: rgba(2, 6, 23, .5); transition: opacity .25s ease, visibility 0s linear .25s; }

/* -------- File inputs -------- */
input[type="file"].input,
input[type="file"].input.file { display: flex; align-items: center; padding: 0; padding-right: 12px; border: 1px dashed var(--line); border-radius: 9px; background: var(--surface-2); cursor: pointer; font-size: 12.5px; color: var(--ink-2); overflow: hidden; transition: border-color .15s, box-shadow .15s, background .15s; }
input[type="file"].input:hover { border-color: var(--accent); background: var(--accent-soft); }
input[type="file"].input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="file"].input::file-selector-button { margin-right: 12px; padding: 10px 16px; border: 0; cursor: pointer; background: var(--accent); color: #fff; font-weight: 600; font-size: 12.5px; font-family: inherit; border-radius: 0; transition: filter .15s; }
input[type="file"].input::-webkit-file-upload-button { margin-right: 12px; padding: 10px 16px; border: 0; cursor: pointer; background: var(--accent); color: #fff; font-weight: 600; font-size: 12.5px; font-family: inherit; border-radius: 0; transition: filter .15s; }
input[type="file"].input:hover::file-selector-button { filter: brightness(1.07); }
input[type="file"].input:hover::-webkit-file-upload-button { filter: brightness(1.07); }

/* -------- Document list (tender supporting docs) -------- */
.doc-group { display: flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--ink-3); margin: 4px 0 8px; }
.doc-group svg { opacity: .8; }
.doc-list { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.doc-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); transition: border-color .15s, background .15s; }
.doc-row:hover { border-color: var(--accent); background: var(--surface-2); }
.doc-row .doc-ico { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.doc-row .doc-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.doc-row .doc-name { font-weight: 620; font-size: 13.5px; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-row .doc-name:hover { color: var(--accent); text-decoration: underline; }
.doc-row .doc-sub { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-row form.inline { display: inline; margin: 0; }
.doc-upload { border-top: 1px dashed var(--line); padding-top: 16px; margin-top: 2px; }
.doc-upload-foot { align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.doc-upload-foot .hint { margin: 0; flex: 1; min-width: 200px; }
.inline { display: inline; margin: 0; }

/* -------- Toasts -------- */
.toast-host { position: fixed; right: 16px; bottom: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: flex-start; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ink-3); border-radius: 11px; box-shadow: var(--shadow); padding: 12px 14px; min-width: 260px; max-width: 360px; transform: translateX(120%); opacity: 0; transition: transform .3s ease, opacity .3s ease; }
.toast.show { transform: translateX(0); opacity: 1; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }
.toast .toast-ico { flex: none; margin-top: 1px; }
.toast.success .toast-ico { color: var(--success); }
.toast.error .toast-ico { color: var(--danger); }
.toast.info .toast-ico { color: var(--info); }
.toast .toast-msg { flex: 1; font-size: 13.5px; color: var(--ink); line-height: 1.4; }
.toast .toast-x { background: none; border: 0; color: var(--ink-3); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }

/* -------- Modals -------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); z-index: 1100; display: flex; align-items: center; justify-content: center; padding: 18px; opacity: 0; transition: opacity .18s ease; }
.modal-overlay.show { opacity: 1; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: 0 24px 64px -20px rgba(2, 6, 23, .5); width: 100%; max-width: 460px; transform: translateY(8px) scale(.98); transition: transform .18s ease; display: flex; flex-direction: column; max-height: 90vh; }
.modal-overlay.show .modal { transform: none; }
.modal.modal-lg { max-width: 920px; }
.modal-hd { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-hd h3 { margin: 0; font-size: 15.5px; flex: 1; }
.modal-x { background: none; border: 0; color: var(--ink-3); font-size: 22px; line-height: 1; cursor: pointer; }
.modal-bd { padding: 18px; overflow: auto; color: var(--ink-2); font-size: 14px; }
.modal-ft { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }

/* ======================================================================
   Hub diagram (mirrors the operating map: central hub + member ring)
   ====================================================================== */
.hub-diagram { position: relative; min-height: 540px; display: grid; place-items: center; padding: 24px 12px; }
.hub-center { position: relative; z-index: 3; width: 124px; height: 124px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #3b82f6, #1e3a8a); color: #fff; display: grid; place-content: center; text-align: center; box-shadow: 0 18px 40px -14px rgba(37,99,235,.7); }
.hub-center .hc-t { font-weight: 800; font-size: 15px; }
.hub-center .hc-s { font-size: 10.5px; opacity: .85; margin-top: 2px; }
.hub-ring { position: absolute; inset: 0; z-index: 2; }
.hub-node { position: absolute; width: 128px; margin-left: -64px; margin-top: -42px; text-align: center; }
.hub-node a { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px; box-shadow: var(--shadow-sm); text-decoration: none; transition: .15s; }
.hub-node a:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-2px); }
.hub-node .hn-badge { width: 24px; height: 24px; border-radius: 7px; display: inline-grid; place-items: center; color: #fff; font-weight: 800; font-size: 12px; margin-bottom: 5px; }
.hub-node .hn-name { font-size: 11.5px; font-weight: 700; color: var(--ink); line-height: 1.2; }
.hub-node .hn-cat { font-size: 10px; color: var(--ink-3); margin-top: 2px; }
.hub-svg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.hub-svg line { stroke: var(--line); stroke-width: 2; }
.hub-svg line.flow { stroke: var(--accent); stroke-dasharray: 4 6; opacity: .5; animation: dash 1.4s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -20; } }
@media (max-width: 720px) { .hub-diagram { min-height: auto; } .hub-ring { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; } .hub-node { position: static !important; width: auto; margin: 0; transform: none !important; } .hub-svg { display: none; } }

/* ======================================================================
   Maps (Leaflet, light theme)
   ====================================================================== */
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow-sm); isolation: isolate; }
.leaflet-map { width: 100%; height: 560px; z-index: 0; background: #eef3f8; }
.leaflet-map.sm { height: 360px; }
.map-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.map-toolbar .ttl { font-weight: 700; font-size: 13px; margin-right: 4px; }
.map-filters { display: flex; gap: 8px; min-width: 0; margin-left: 8px; }
.map-filters .select { width: auto; min-width: 0; padding: 7px 10px; }
.map-toggle { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.map-toggle .sw { width: 11px; height: 11px; border-radius: 3px; }
.map-toggle.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.map-toggle.off { opacity: .55; }
.map-count { margin-left: auto; font-size: 12px; color: var(--ink-3); }
.bsp-pin { background: none; border: 0; }
.bsp-pin-dot { display: block; width: 22px; height: 22px; border-radius: 50% 50% 50% 0; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); transform: rotate(-45deg); }
.bsp-pin-dot.tender { background: #2563eb; }
.bsp-pin-dot.contractor { background: #16a34a; }
.bsp-pin-dot.supplier { background: #d97706; }
.bsp-pin-dot.self { background: #7c3aed; }
.map-pop { display: block; width: 220px; color: var(--ink); text-decoration: none; }
.map-pop:hover { text-decoration: none; }
.map-pop .mp-kind { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.map-pop .mp-kind.tender { color: #2563eb; }
.map-pop .mp-kind.contractor { color: #16a34a; }
.map-pop .mp-kind.supplier { color: #d97706; }
.map-pop strong { display: block; font-size: 13.5px; margin: 2px 0 3px; line-height: 1.25; }
.map-pop span.mp-sub { display: block; font-size: 12px; color: var(--ink-3); }
.map-pop .mp-meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.map-pop .mp-link { margin-top: 8px; display: inline-flex; align-items: center; gap: 5px; color: var(--accent); font-weight: 700; font-size: 12px; }
.leaflet-popup-content { margin: 12px 14px; }

/* -------- Match list (paired with the per-entity maps) -------- */
.match-list { display: flex; flex-direction: column; gap: 8px; max-height: 560px; overflow: auto; padding-right: 2px; }
.match-row { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); transition: .15s; }
.match-row:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.match-row .mr-ico { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; color: #fff; flex: none; }
.match-row .mr-ico.tender { background: #2563eb; } .match-row .mr-ico.contractor { background: #16a34a; } .match-row .mr-ico.supplier { background: #d97706; }
.match-row .mr-main { flex: 1; min-width: 0; }
.match-row .mr-name { font-weight: 650; font-size: 13.5px; line-height: 1.25; }
.match-row .mr-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.match-row .mr-score { text-align: center; flex: none; }
.match-row .mr-score .sc { font-weight: 800; font-size: 15px; }
.match-row .mr-score .sl { font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.score-hi { color: var(--success); } .score-mid { color: var(--warning); } .score-lo { color: var(--ink-3); }

/* -------- Source cards -------- */
.source-card { display: flex; flex-direction: column; gap: 8px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.source-card .sc-top { display: flex; align-items: center; gap: 10px; }
.source-card .sc-ico { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.source-card h3 { margin: 0; font-size: 14.5px; }
.source-card .sc-meta { font-size: 11.5px; color: var(--ink-3); }

/* -------- Detail layout -------- */
.detail-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 7px 12px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; color: var(--ink); }
.owner-card { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.owner-card .oc-logo { width: 40px; height: 40px; flex: none; }

/* -------- Project accounting -------- */
.financial-positive { color: var(--success) !important; }
.financial-negative { color: var(--danger) !important; }
.company-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--company-color, var(--accent)); margin-right: 6px; flex: none; }
.project-title-meta { gap: 8px; align-items: center; }
.project-filter-bar { grid-template-columns: minmax(220px, 1.5fr) repeat(auto-fit, minmax(160px, 1fr)); }
.project-table .progress, .budget-table .progress, .report-table .progress { margin-top: 5px; }
.budget-usage-cell { min-width: 132px; }
.project-budget-alert { align-items: center; }
.project-accounting-grid { grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); }
.project-kv { grid-template-columns: 92px 1fr; }
.budget-tabs .tab { white-space: nowrap; }
.tab-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center; background: var(--muted-bg); color: var(--ink-2); font-size: 10.5px; }
.tab.active .tab-count { background: rgba(255,255,255,.2); color: #fff; }
.budget-alert-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.budget-alert-dot.over { background: var(--danger); }
.budget-focus-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.budget-focus-grid > div { border-left: 3px solid var(--line); padding-left: 11px; min-width: 0; }
.budget-focus-grid strong { display: block; margin-top: 4px; font-size: 17px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-label { color: var(--ink-3); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.project-progress-lg { height: 11px; margin-top: 7px; }
.textarea.compact { min-height: 68px; }
.input-suffix { position: relative; }
.input-suffix .input { padding-right: 36px; }
.input-suffix > span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); font-weight: 650; pointer-events: none; }
.project-profit-preview { border: 1px solid var(--line); border-left: 4px solid var(--accent); background: var(--surface-2); padding: 13px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; display: grid; gap: 2px; }
.project-profit-preview span, .project-profit-preview small { color: var(--ink-2); }
.project-profit-preview strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.budget-entry-head, .budget-entry-row { display: grid; grid-template-columns: minmax(150px, 1.05fr) minmax(140px, .7fr) minmax(160px, 1.15fr) 36px; gap: 8px; align-items: center; }
.budget-entry-head { color: var(--ink-3); font-size: 11.5px; font-weight: 600; padding: 0 2px 6px; }
.budget-entry-row .icon-btn { background: var(--surface-2); color: var(--ink-2); }
.budget-entry-row .icon-btn:hover { color: var(--danger); background: var(--danger-bg); }

@media (min-width: 861px) {
   .project-table td.num, .budget-table td.num, .expense-table td.num, .report-table td.num { white-space: nowrap; }
}

@media (max-width: 980px) {
   .project-accounting-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
   .budget-entry-head { display: none; }
   .budget-entry-row { grid-template-columns: 1fr 1fr 40px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
   .budget-entry-row > :nth-child(3) { grid-column: 1 / 3; }
   .budget-entry-row > :last-child { grid-column: 3; grid-row: 1; }
   .budget-focus-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 460px) {
   .budget-entry-row { grid-template-columns: 1fr 40px; }
   .budget-entry-row > :nth-child(1), .budget-entry-row > :nth-child(2), .budget-entry-row > :nth-child(3) { grid-column: 1 / 3; }
   .budget-entry-row > :last-child { grid-column: 2; grid-row: 1; }
   .budget-focus-grid { grid-template-columns: 1fr; }
}

@media print {
   body { background: #fff; font-size: 11px; }
   .sidebar, .topbar, .no-print, .assist-fab, .assist-panel, .toast-host { display: none !important; }
   .layout, .main { display: block; }
   .content { max-width: none; padding: 0; }
   .card, .kpi { box-shadow: none; break-inside: avoid; }
   .report-table { font-size: 10px; }
   .report-table th, .report-table td { padding: 6px; }
   a { color: inherit; }
}

/* ======================================================================
   Email client (matches the retail email UI)
   ====================================================================== */
.mail { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; align-items: start; }
.mail__side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow-sm); }
.mailbox-nav { display: grid; gap: 2px; }
.mailbox-link { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 13.5px; }
.mailbox-link:hover { background: var(--surface-2); text-decoration: none; }
.mailbox-link.is-active { background: var(--accent-soft); color: var(--accent); }
.mailbox-link__icon { display: inline-flex; align-items: center; justify-content: center; width: 22px; color: var(--ink-3); }
.mailbox-link.is-active .mailbox-link__icon { color: var(--accent); }
.mailbox-link__icon--star { color: #f59e0b; }
.mailbox-link__label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mailbox-link__badge { background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 0 6px; height: 18px; line-height: 18px; border-radius: 9px; }
.mailbox-link__count { color: var(--ink-3); font-size: 12px; }
.mail__folders { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 11px; }
.mail__folders-head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 0 11px 6px; }
.mail__folder-row { display: flex; align-items: center; gap: 2px; }
.mail__folder-row .mailbox-link { flex: 1; min-width: 0; }
.mail__folder-del { display: flex; }
.mail__folder-add { display: flex; gap: 5px; margin-top: 6px; }
.mail__folder-add input { flex: 1; min-width: 0; height: 36px; padding: 6px 10px; }
.mail__folder-add .btn { flex: none; padding: 8px 10px; }

.mail__main { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.mail__search { padding: 11px; border-bottom: 1px solid var(--line); }
.mail__search input { width: 100%; }
.mail-list { display: flex; flex-direction: column; }
.mail-row { display: grid; grid-template-columns: 24px 180px minmax(0, 1fr) auto; align-items: center; gap: 11px; padding: 11px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover { background: var(--surface-2); text-decoration: none; }
.mail-row.is-unread { background: #f5f9ff; }
.mail-row.is-unread .mail-row__who, .mail-row.is-unread .mail-row__subject strong { font-weight: 800; }
.mail-row__star { color: var(--line); display: inline-flex; align-items: center; }
.mail-row__star.is-on { color: #f59e0b; }
.mail-row__who { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-row__count { color: var(--ink-3); font-weight: 600; }
.mail-row__subject { min-width: 0; display: flex; gap: 8px; align-items: baseline; overflow: hidden; }
.mail-row__subject strong { white-space: nowrap; }
.mail-row__preview { color: var(--ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-row__meta { display: flex; align-items: center; gap: 8px; color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
.mail-row__clip { display: inline-flex; }

/* Compose modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); z-index: 1100; display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal-backdrop[hidden] { display: none; }
body.modal-open { overflow: hidden; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal__head h3 { margin: 0; font-size: 15.5px; }
.mail-compose { background: var(--surface); border-radius: 16px; box-shadow: 0 24px 64px -20px rgba(2, 6, 23, .5); width: 100%; max-width: 640px; max-height: 90vh; overflow: auto; transform: none; display: block; }
.mail-compose__form { padding: 16px 20px 20px; }

/* recipient pills (To/Cc) */
.mail-recipients { position: relative; display: grid; grid-template-columns: 56px 1fr; align-items: start; gap: 9px; margin-bottom: 9px; }
.mail-recipients__label { font-size: 12.5px; font-weight: 700; color: var(--ink-3); padding-top: 9px; }
.mail-recipients__field { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; min-height: 40px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.mail-recipients__field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.mail-recipients__input { flex: 1; min-width: 120px; border: 0 !important; background: transparent !important; padding: 5px 3px !important; height: auto !important; box-shadow: none !important; outline: none; font: inherit; font-size: 14px; }
.mail-recipients--subject { align-items: center; }
.mail-subject-input { width: 100%; }
.mail-pill { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--ink); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 12.5px; max-width: 100%; }
.mail-pill__txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.mail-pill__x { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-3); cursor: pointer; }
.mail-pill__x:hover { background: var(--danger-bg); color: var(--danger); }
.mail-compose__foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.mail-attach { cursor: pointer; }
.mail-x { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--ink-3); cursor: pointer; transition: background .15s, color .15s; }
.mail-x:hover { background: var(--danger-bg); color: var(--danger); }
.mail-attach-previews { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0; }
.mail-att-prev { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 12.5px; max-width: 220px; }
.mail-att-prev img { width: 38px; height: 38px; border-radius: 7px; object-fit: cover; }
.mail-att-prev__ic { display: inline-flex; width: 38px; height: 38px; align-items: center; justify-content: center; color: var(--ink-3); }
.mail-att-prev__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* autocomplete panel */
.ac-panel { position: absolute; left: 56px; right: 0; top: calc(100% + 4px); z-index: 70; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); max-height: 240px; overflow: auto; padding: 4px; }
.ac-panel[hidden] { display: none; }
.ac-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left; border: 0; background: none; cursor: pointer; padding: 8px 10px; border-radius: 8px; color: var(--ink); font: inherit; }
.ac-item:hover, .ac-item.active { background: var(--accent-soft); }
.ac-item__main { display: flex; flex-direction: column; min-width: 0; }
.ac-item__main strong { font-size: 13px; }
.ac-item__main small { font-size: 11px; color: var(--ink-3); }
.ac-item__meta { font-size: 12px; color: var(--ink-3); white-space: nowrap; }

/* Conversation */
.mail-thread-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.mail-thread-actions__primary { display: flex; gap: 6px; flex-wrap: wrap; }
.mail-thread-actions__spacer { flex: 1; min-width: 8px; }
.mail-iform { display: inline-flex; margin: 0; }
.mail-thread-actions .btn svg, .mail-composer .btn svg { vertical-align: -3px; }
.mail-move-menu { position: relative; }
.mail-move-menu > summary { list-style: none; cursor: pointer; }
.mail-move-menu > summary::-webkit-details-marker { display: none; }
.mail-move-menu__panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 210px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; }
.mail-move-menu__title { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 5px 8px 6px; }
.mail-move-menu__opt { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: none; cursor: pointer; color: var(--ink); font: inherit; padding: 8px 9px; border-radius: 8px; }
.mail-move-menu__opt:hover { background: var(--surface-2); }
.mail-move-menu__opt svg { color: var(--ink-3); }
.mail-composer { background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; max-height: 0; opacity: 0; overflow: hidden; transition: max-height .28s ease, opacity .2s ease; }
.mail-composer.is-open { max-height: 1600px; opacity: 1; }
.mail-composer__head { display: flex; align-items: center; justify-content: space-between; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.mail-composer form { padding: 14px 18px 18px; }
.mail-composer textarea { width: 100%; }
.mail-composer__foot { display: flex; align-items: center; gap: 10px; margin-top: 11px; }
.mail-composer__spacer { flex: 1; }
.mail-conv { display: flex; flex-direction: column; gap: 13px; }
.mail-msg { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); overflow: visible; }
.mail-msg--out { border-left: 3px solid var(--accent); }
.mail-msg__head { display: grid; grid-template-columns: auto 1fr auto; gap: 13px; align-items: start; margin-bottom: 11px; }
.mail-msg__avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 13.5px; }
.mail-msg__meta { min-width: 0; line-height: 1.4; }
.mail-msg__to { font-size: 12.5px; }
.mail-msg__body { line-height: 1.65; }
.mail-msg__atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 13px; border-top: 1px dashed var(--line); }
.mail-att { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--ink); background: var(--surface-2); font-size: 13.5px; }
.mail-att:hover { border-color: var(--accent); text-decoration: none; }
.mail-att__icon { display: inline-flex; color: var(--ink-3); }
.mail-att__size { font-size: 12px; }
.mail-att--img { flex-direction: column; gap: 5px; padding: 6px; cursor: pointer; width: 120px; }
.mail-att--img img { width: 100%; height: 84px; object-fit: cover; border-radius: 7px; }
.mail-att--img .mail-att__cap { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.mail-lightbox { position: fixed; inset: 0; z-index: 2000; background: rgba(15,23,42,.82); display: none; align-items: center; justify-content: center; padding: 2rem; }
.mail-lightbox.open { display: flex; }
.mail-lightbox figure { margin: 0; max-width: 90vw; max-height: 90vh; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.mail-lightbox img { max-width: 90vw; max-height: 82vh; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.mail-lightbox figcaption { color: #fff; font-size: 13.5px; }
.mail-lightbox__close { position: absolute; top: 1rem; right: 1rem; width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.mail-lightbox__close:hover { background: rgba(255,255,255,.3); }
.mail-ai-panel { background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 16px; overflow: hidden; }
.mail-ai-panel__head { display: flex; align-items: center; justify-content: space-between; padding: 11px 18px; background: var(--accent-soft); border-bottom: 1px solid var(--line); }
.mail-ai-panel__body { padding: 16px; }
.mail-ai-loading { color: var(--ink-3); }
.mail-ai-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin-bottom: 5px; }
.mail-ai-summary { margin-bottom: 16px; }
.mail-ai-summary p { margin: 0; line-height: 1.6; }
.mail-ai-suggestions { display: grid; gap: 9px; }
.mail-ai-sugg { display: flex; gap: 11px; align-items: flex-start; text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); cursor: pointer; color: var(--ink); line-height: 1.5; transition: border-color .15s; }
.mail-ai-sugg:hover { border-color: var(--accent); }
.mail-ai-sugg__n { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
@media (max-width: 860px) {
    .mail { grid-template-columns: 1fr; }
    .mail-row { grid-template-columns: 20px 1fr auto; }
    .mail-row__who { grid-column: 2; }
    .mail-row__subject { grid-column: 1 / -1; }
}

/* -------- Responsive -------- */
@media (max-width: 860px) {
   .sidebar { width: min(86vw, 280px); position: fixed; left: 0; top: 0; height: 100vh; height: 100dvh; z-index: 100; transform: translateX(-100%); transition: transform .25s ease; box-shadow: 0 24px 64px -16px rgba(2, 6, 23, .6); }
    body.nav-open .sidebar { transform: translateX(0); }
   body.nav-open { overflow: hidden; }
   body.nav-open .nav-backdrop { visibility: visible; opacity: 1; pointer-events: auto; transition-delay: 0s; }
    .topbar { padding: 0 14px; gap: 10px; }
    .topbar h1 { font-size: 15.5px; }
    .content { padding: 16px 14px 32px; }
    .page-head h1 { font-size: 18px !important; }
    .detail-grid { grid-template-columns: 1fr; }
    .leaflet-map { height: 420px; }
}
@media (max-width: 520px) {
    .page-head { flex-direction: column; align-items: stretch; }
    .kpi .k-value { font-size: 22px; }
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dt { margin-top: 8px; }
}

/* ======================================================================
   Global AI assistant (floating chat, bottom-right)
   ====================================================================== */
.assist-fab { position: fixed; right: 22px; bottom: 22px; z-index: 800; width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #2563eb, #1e3a8a); box-shadow: 0 14px 30px -8px rgba(37,99,235,.65); transition: transform .15s ease, opacity .15s ease; }
.assist-fab:hover { transform: translateY(-2px) scale(1.04); }
.assist-fab.hidden { opacity: 0; pointer-events: none; transform: scale(.6); }
.assist-fab svg { width: 24px; height: 24px; }

.assist-panel { position: fixed; right: 22px; bottom: 22px; z-index: 801; width: 390px; max-width: calc(100vw - 28px); height: 600px; max-height: calc(100vh - 96px); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 28px 70px -20px rgba(2,6,23,.5); display: flex; flex-direction: column; overflow: hidden; opacity: 0; transform: translateY(16px) scale(.98); pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.assist-panel.open { opacity: 1; transform: none; pointer-events: auto; }
.assist-hd { display: flex; align-items: center; gap: 10px; padding: 13px 14px; background: linear-gradient(120deg, #1e3a8a, #2563eb); color: #fff; }
.assist-hd .assist-ico { width: 30px; height: 30px; border-radius: 9px; background: rgba(255,255,255,.18); display: grid; place-items: center; flex: none; }
.assist-hd .at { font-weight: 700; font-size: 14px; line-height: 1.1; }
.assist-hd .as { font-size: 11px; opacity: .85; }
.assist-ic { background: rgba(255,255,255,.15); border: 0; color: #fff; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.assist-ic:hover { background: rgba(255,255,255,.28); }
.assist-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); }
.assist-msg { display: flex; flex-direction: column; max-width: 88%; }
.assist-msg.user { align-self: flex-end; align-items: flex-end; }
.assist-msg.bot { align-self: flex-start; }
.assist-bubble { padding: 10px 13px; border-radius: 13px; font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.assist-msg.user .assist-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.assist-msg.bot .assist-bubble { background: var(--surface); border: 1px solid var(--line); color: var(--ink); border-bottom-left-radius: 4px; }
.assist-matches { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; width: 100%; }
.assist-match { display: flex; flex-direction: column; padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); text-decoration: none; transition: .15s; }
.assist-match:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); text-decoration: none; }
.assist-match strong { font-size: 12.5px; color: var(--ink); }
.assist-match span { font-size: 11.5px; color: var(--ink-3); }
.assist-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.assist-chip { font-size: 11.5px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 6px 11px; cursor: pointer; }
.assist-chip:hover { border-color: var(--accent); color: var(--accent); }
.assist-input { display: flex; gap: 8px; padding: 11px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.assist-input input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; font-family: inherit; }
.assist-input input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.assist-input .btn { padding: 9px 13px; }
@media (max-width: 520px) {
    .assist-panel { right: 8px; bottom: 8px; height: calc(100vh - 80px); }
    .assist-fab { right: 14px; bottom: 14px; }
}

/* ======================================================================
   Filterable combobox (sectioned, custom-text) — owner & assist fields
   ====================================================================== */
.combo { position: relative; }
.combo-pop { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; z-index: 60; display: none; }
.combo.open .combo-pop { display: block; }
.combo-group { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 9px 12px 5px; font-weight: 700; background: var(--surface-2); position: sticky; top: 0; }
.combo-item { padding: 8px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.combo-item:hover { background: var(--accent-soft); }
.combo-item .ci-name { font-size: 13px; color: var(--ink); font-weight: 550; }
.combo-item .ci-sub { font-size: 11px; color: var(--ink-3); }
.combo-empty, .combo-more { padding: 10px 12px; font-size: 12px; color: var(--ink-3); }
.assist-row { display: flex; gap: 8px; align-items: flex-start; }
.assist-row .combo { flex: 1; min-width: 0; }
.assist-row .combo-remove { flex: none; padding: 9px 11px; }

/* ======================================================================
   Mobile responsiveness — filter bars, stacked tables, touch tweaks
   ====================================================================== */

/* Filter bars: an auto-flowing grid that fills wide screens on one row and
   collapses cleanly to fewer columns (and finally one) on small screens. */
.filter-bar { display: grid; gap: 10px; align-items: end; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.filter-bar .field { margin: 0; min-width: 0; }
.filter-bar .filter-submit { width: 100%; justify-content: center; }

/* Two-column split that collapses on mobile (e.g. dashboard hub + chart). */
.grid.split { grid-template-columns: 1.4fr 1fr; }

/* Let grid/flex items shrink below their content's intrinsic width so that
   nowrap text ellipsizes inside its cell instead of forcing the whole page
   to scroll horizontally on narrow screens. */
.grid > *, .detail-grid > *, .mail > *, .row > * { min-width: 0; }

/* Opt-in horizontal scroll for any table we keep tabular on mobile. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 860px) {
    .grid.split { grid-template-columns: 1fr; }

    /* -------- Stacked card tables (opt-in via .cards-sm) -------- */
    table.cards-sm, table.cards-sm tbody, table.cards-sm tr, table.cards-sm td { display: block; width: 100%; }
    table.cards-sm { white-space: normal; overflow: visible; border-collapse: separate; }
    table.cards-sm thead { display: none; }
    table.cards-sm tr { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
    table.cards-sm tr:last-child { margin-bottom: 0; }
    table.cards-sm tbody tr:hover { background: var(--surface); }
    table.cards-sm td { border: 0; border-bottom: 1px solid var(--line); padding: 9px 14px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; max-width: none !important; white-space: normal; }
    table.cards-sm td:last-child { border-bottom: 0; }
    table.cards-sm td.num { text-align: left; }
    table.cards-sm td::before { content: attr(data-label); font-weight: 700; color: var(--ink-3); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
    table.cards-sm td[data-label=""]::before, table.cards-sm td:not([data-label])::before { content: none; }
    table.cards-sm td:first-child { background: var(--surface-2); }
    table.cards-sm td > div { width: 100%; }
    .hide-sm { display: none !important; }

    /* Map toolbar: let the filter form + selects use the full width. */
    .map-toolbar { gap: 7px; }
    .map-toolbar form#mapFilters, .map-toolbar form { width: 100%; margin-left: 0 !important; }
    .map-toolbar form .select { flex: 1; width: auto !important; }
    .map-toolbar .map-count { margin-left: 0; }
}

@media (max-width: 560px) {
    /* Stack page-head action buttons full width for easy tapping. */
    .page-head > .row { flex-direction: column; align-items: stretch; width: 100%; }
    .page-head > .row .btn { width: 100%; }
    .filter-bar { grid-template-columns: 1fr; }
    .kpi { padding: 14px 15px; }
    .modal { width: 100%; }
    .btn { padding: 10px 14px; }
    .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Email conversation: drop the timestamp under the sender. */
    .mail-msg { padding: 16px; }
    .mail-msg__head { grid-template-columns: auto 1fr; }
    .mail-msg__head time { grid-column: 2; font-size: 11.5px; }
    .mail-thread-actions__primary { width: 100%; }
}

/* ======================================================================
   Touch & small-screen refinements
   ====================================================================== */
@media (max-width: 640px) {
    /* Prevent iOS Safari from auto-zooming when a field gains focus — it does
       this whenever the control's font-size is below 16px. */
    .input, .select, .textarea,
    input[type="text"], input[type="email"], input[type="password"],
    input[type="search"], input[type="number"], input[type="date"],
    input[type="tel"], input[type="url"],
    .assist-input input, .mail-recipients__input, .mail-subject-input, .mail__folder-add input {
        font-size: 16px;
    }
    /* Bigger, easier-to-hit touch targets. */
    .icon-btn, .hamburger { width: 40px; height: 40px; }
    .nav a { padding: 11px 12px; }
    .mailbox-link { padding: 11px 12px; }
    .btn.sm { padding: 8px 12px; }
    /* Stop the floating assistant button from covering the last bit of content. */
    .content { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
}

/* Components respond to the width left inside the application shell. This
   keeps tablet layouts sound whether the sidebar is expanded or collapsed. */
@container app-content (max-width: 1050px) {
   .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
   .project-accounting-grid { grid-template-columns: minmax(0, 1fr); }
}

@container app-content (max-width: 900px) {
   .detail-grid, .grid.split { grid-template-columns: minmax(0, 1fr); }
   .mail { grid-template-columns: minmax(0, 1fr); }
}

@container app-content (max-width: 650px) {
   .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
   .page-head > .row { width: 100%; }
}

@container card (max-width: 480px) {
   .form-grid, .form-grid.three { grid-template-columns: minmax(0, 1fr); }
   .card .hd { padding-inline: 14px; }
   .card .bd { padding: 15px 14px; }
   .map-filters { flex-direction: column; }
   .map-filters .select { width: 100%; }
}

@container app-content (max-width: 760px) {
   table.cards-sm, table.cards-sm tbody, table.cards-sm tr, table.cards-sm td { display: block; width: 100%; }
   table.cards-sm { overflow: visible; border-collapse: separate; white-space: normal; }
   table.cards-sm thead { display: none; }
   table.cards-sm tr { overflow: hidden; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); }
   table.cards-sm tr:last-child { margin-bottom: 0; }
   table.cards-sm tbody tr:hover { background: var(--surface); }
   table.cards-sm td { display: flex; align-items: flex-start; flex-direction: column; gap: 4px; max-width: none !important; padding: 9px 14px; border: 0; border-bottom: 1px solid var(--line); text-align: left; white-space: normal; }
   table.cards-sm td:last-child { border-bottom: 0; }
   table.cards-sm td.num { text-align: left; }
   table.cards-sm td::before { content: attr(data-label); color: var(--ink-3); font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
   table.cards-sm td[data-label=""]::before, table.cards-sm td:not([data-label])::before { content: none; }
   table.cards-sm td:first-child { background: var(--surface-2); }
   table.cards-sm td > div { width: 100%; }
}

@media (pointer: coarse) {
   .btn { min-height: 42px; }
   .icon-btn, .hamburger { width: 42px; height: 42px; }
   .nav a { min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
   .sidebar, .nav-backdrop, .hamburger, .sidebar *, .sidebar *::before, .sidebar *::after { transition-duration: .01ms !important; }
}

/* Honour device safe areas (notch / home indicator) for the floating UI. */
@supports (padding: max(0px)) {
    .assist-fab { bottom: max(22px, env(safe-area-inset-bottom)); }
    .assist-panel { bottom: max(22px, env(safe-area-inset-bottom)); }
}

/* Remove the grey tap-flash on touch devices for a more app-like feel. */
* { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); }


