/* Tradeworx — clean contemporary stylesheet
   Brand fallback palette (we couldn't fetch tradeworx.me): a calm,
   professional navy + accent yellow that suits trade-business UIs.
*/
:root {
    --c-bg:        #f5f7fb;
    --c-surface:   #ffffff;
    --c-ink:       #0a2540;
    --c-ink-soft:  #4a5b73;
    --c-muted:     #8492a6;
    --c-border:    #e3e8ef;
    --c-primary:   #0a2540;
    --c-primary-2: #1d3a5f;
    --c-accent:    #f5c518;
    --c-success:   #1f9d55;
    --c-warning:   #c97300;
    --c-danger:    #c0392b;
    --c-focus:     #4a90e2;
    --radius-sm:   6px;
    --radius:      10px;
    --radius-lg:   14px;
    --shadow-1:    0 1px 2px rgba(10,37,64,.06), 0 2px 8px rgba(10,37,64,.04);
    --shadow-2:    0 8px 24px rgba(10,37,64,.10);
    --sb-w:        260px;
    --sb-w-collapsed: 72px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font: 15px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
    color: var(--c-ink); background: var(--c-bg);
}

a { color: var(--c-primary-2); }
a:hover { color: var(--c-primary); }

/* ---------- App shell with sidebar ---------- */
.shell { display: grid; grid-template-columns: var(--sb-w) 1fr; min-height: 100vh; }
.shell[data-collapsed="true"] { grid-template-columns: var(--sb-w-collapsed) 1fr; }

.sidebar {
    background: var(--c-primary); color: #cfdbe8;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.iconbtn {
    background: transparent; border: 0; color: inherit; cursor: pointer;
    width: 36px; height: 36px; border-radius: 8px;
}
.iconbtn:hover { background: rgba(255,255,255,.08); }
.brand { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--c-accent); color: var(--c-primary); display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .5px; }
.brand-text { letter-spacing: .3px; }

.nav { padding: 12px 8px; flex: 1; overflow-y: auto; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 8px; color: #cfdbe8; text-decoration: none;
    font-weight: 500; margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.is-active { background: rgba(245,197,24,.14); color: #fff; }
.nav-link svg { flex: 0 0 18px; }
/* Collapsible nav section ── trigger is a <summary> element */
.nav-section-trigger {
    display: flex; align-items: center; justify-content: space-between;
    list-style: none;
    width: 100%; background: none; border: none; cursor: pointer;
    padding: 14px 12px 4px; text-align: left;
    font-size: 10px; font-weight: 700; letter-spacing: .08em;
    text-transform: uppercase; color: rgba(255,255,255,.35);
    border-radius: 4px;
}
.nav-section-trigger::-webkit-details-marker { display: none; }
.nav-section-trigger:hover { color: rgba(255,255,255,.55); }

/* Chevron: points right (closed) → down (open) */
.nav-section-chevron {
    flex-shrink: 0; margin-left: 4px;
    transform: rotate(-90deg);
    transition: transform 0.2s ease;
}
details.nav-section[open] > .nav-section-trigger .nav-section-chevron {
    transform: rotate(0deg);
}

/* Icon-only collapsed sidebar: hide the trigger, always show the body */
.shell[data-collapsed="true"] .nav-section-trigger { display: none; }
.shell[data-collapsed="true"] details.nav-section > .nav-section-body { display: block !important; }

.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding: 12px; }
.user-card { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--c-accent); color: var(--c-primary); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user-name { color: #fff; font-weight: 600; font-size: 14px; }
.user-meta { color: #8aa1bc; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.signout { display: block; padding: 8px 10px; color: #cfdbe8; border-radius: 6px; text-decoration: none; font-size: 13px; }
.signout:hover { background: rgba(255,255,255,.06); color: #fff; }

/* Collapsed sidebar */
.shell[data-collapsed="true"] .nav-label,
.shell[data-collapsed="true"] .brand-text,
.shell[data-collapsed="true"] .user-info,
.shell[data-collapsed="true"] .signout { display: none; }
.shell[data-collapsed="true"] .nav-link { justify-content: center; }
.shell[data-collapsed="true"] .user-card { justify-content: center; }
.shell[data-collapsed="true"] .brand img { width: 15px; height: 15px; object-fit: contain; }

/* ---------- Main content ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    padding: 18px 28px;
    display: flex; align-items: center; justify-content: space-between;
}
.page-title { font-size: 20px; margin: 0; font-weight: 600; color: var(--c-ink); }
.page { padding: 28px; }

/* ---------- Cards / panels / tables ---------- */
.card {
    background: var(--c-surface); border: 1px solid var(--c-border);
    border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 18px; }
.card h2, .card h3 { margin-top: 0; }

.grid { display: grid; gap: 18px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; } }

.stat { padding: 16px; }
.stat .label { color: var(--c-ink-soft); font-size: 13px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 30px; font-weight: 700; color: var(--c-ink); margin-top: 6px; }

.stats-row { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 4px; }
.stat-card { flex: 1 1 160px; background: var(--c-surface); border: 1px solid var(--c-border);
    border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-1); min-width: 140px; }
.stat-card--highlight { border-color: var(--c-accent); background: #fffbea; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--c-ink-soft); margin-bottom: 6px; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--c-ink); line-height: 1.1; }
.stat-link { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--c-ink-soft); text-decoration: none; }
.stat-link:hover { color: var(--c-ink); }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--c-border); text-align: left; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--c-ink-soft); }
.table tr:hover td { background: rgba(74,144,226,.04); }

/* Card-style list rows */
.table.table-cards { border-collapse: separate; border-spacing: 0 5px; }
.table.table-cards thead th { border-bottom: none; padding-bottom: 2px; }
.table.table-cards tbody tr td { background: #f8fafc; border-top: 1px solid var(--c-border); border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.table.table-cards tbody tr td:first-child { border-left: 1px solid var(--c-border); border-radius: 8px 0 0 8px; }
.table.table-cards tbody tr td:last-child { border-right: 1px solid var(--c-border); border-radius: 0 8px 8px 0; }
.table.table-cards tbody tr:hover td { background: #edf2fb; border-color: #c5d7f0; }
.table.table-cards tbody tr[data-href] { cursor: pointer; }
.table.table-cards tbody tr[data-href]:hover td { background: #e4ecfa; border-color: #b0c8ed; }
.table.table-cards tbody tr td.hint-row { background: transparent; border: none; }

.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 18px; }
.badge.success { background: #e3f5ec; color: var(--c-success); }
.badge.warning { background: #fff1d6; color: var(--c-warning); }
.badge.danger  { background: #fde0dd; color: var(--c-danger); }
.badge.muted   { background: #eef1f5; color: var(--c-ink-soft); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--c-ink); }
.field input, .field select, .field textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: var(--radius-sm);
    font-size: 15px; background: #fff; color: var(--c-ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid var(--c-focus); outline-offset: 2px;
}
.field .hint { color: var(--c-muted); font-size: 12px; margin-top: 6px; }

.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
    background: var(--c-primary); color: #fff; cursor: pointer; text-decoration: none;
    font-weight: 600; font-size: 14px; line-height: 1;
}
.button:hover { background: var(--c-primary-2); }
.button.secondary { background: #fff; color: var(--c-ink); border-color: var(--c-border); }
.button.secondary:hover { border-color: var(--c-ink); }
.button.accent { background: var(--c-accent); color: var(--c-primary); }
.button.danger { background: var(--c-danger); }

.errors {
    background: #fde0dd; border: 1px solid #f5b7b1; color: #922010;
    padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 16px;
}
.errors ul { margin: 0; padding-left: 18px; }

.notice {
    background: #e7f1fb; border: 1px solid #c7dcf4; color: #1d3a5f;
    padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 16px;
}

/* ---------- Auth pages ---------- */
.auth-body { background: linear-gradient(135deg, #0a2540 0%, #1d3a5f 100%); min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-shell { width: 100%; max-width: 460px; }
.auth-card {
    background: var(--c-surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2); padding: 32px;
}
.auth-card .brand { color: var(--c-primary); margin-bottom: 8px; font-size: 18px; }
.auth-card h2 { margin-top: 6px; margin-bottom: 24px; font-size: 22px; }
.auth-card .button { width: 100%; padding: 12px 18px; }
.auth-card .field input { padding: 12px 14px; }
.auth-foot { text-align: center; color: rgba(255,255,255,.7); margin-top: 18px; font-size: 13px; }
.auth-meta { display: flex; justify-content: space-between; margin-top: 16px; font-size: 13px; }
.auth-meta a { text-decoration: none; }

/* ---------- .btn aliases (Phase 2 shorthand) ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
    cursor: pointer; text-decoration: none; font-weight: 600; font-size: 14px; line-height: 1;
}
.btn-primary   { background: var(--c-primary);    color: #fff; }
.btn-primary:hover { background: var(--c-primary-2); color: #fff; }
.btn-secondary { background: #fff; color: var(--c-ink); border-color: var(--c-border); }
.btn-secondary:hover { border-color: var(--c-ink); }
.btn-ghost     { background: transparent; color: var(--c-ink-soft); border-color: var(--c-border); }
.btn-ghost:hover { background: var(--c-bg); color: var(--c-ink); }
.btn-danger    { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.btn-danger:hover { opacity: .88; }
.btn-sm        { padding: 5px 11px; font-size: 12px; }

/* ---------- Page layout helpers ---------- */
.page-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }

.form-section { margin-bottom: 24px; border-bottom: 1px solid var(--c-border); padding-bottom: 20px; }
.form-section:last-of-type { border-bottom: 0; }
.form-section h3 { margin: 0 0 14px; font-size: 15px; color: var(--c-ink-soft); text-transform: uppercase; letter-spacing: .5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }
.form-actions { display: flex; align-items: center; gap: 10px; padding-top: 8px; }

.field-hint { color: var(--c-muted); font-size: 12px; margin-top: 5px; }
.req { color: var(--c-danger); }
.checkbox-label { display: flex !important; align-items: center; gap: 8px; font-weight: normal !important; cursor: pointer; }
.checkbox-label input[type=checkbox] { width: auto; }
.value-display { margin: 0; font-size: 15px; color: var(--c-ink); }

/* ---------- Contact action buttons (tel/sms/whatsapp/email) ---------- */
.contact-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.contact-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
    background: #fff;
    color: var(--c-ink);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s;
    white-space: nowrap;
    min-height: 44px; /* comfortable touch target */
}
.contact-btn:hover { background: var(--c-surface); border-color: #b0b8c4; }
.contact-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ---------- .input shorthand ---------- */
.input {
    display: block; width: 100%; padding: 10px 12px;
    border: 1px solid var(--c-border); border-radius: var(--radius-sm);
    font-size: 15px; background: #fff; color: var(--c-ink);
}
.input:focus { outline: 2px solid var(--c-focus); outline-offset: 2px; }
textarea.input { resize: vertical; }

/* ---------- Search bar ---------- */
.search-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.search-bar .input { max-width: 320px; }

/* ---------- Row actions ---------- */
.row-actions { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
td.row-actions { text-align: right; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 8px; padding: 14px 0 0; justify-content: flex-end; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-error { background: #fde0dd; border: 1px solid #f5b7b1; color: #922010; }
.alert-info   { background: #e7f1fb; border: 1px solid #c7dcf4; color: #1d3a5f; }

/* ---------- Filter tabs ---------- */
.filter-tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 18px; padding-bottom: 2px; border-bottom: 1px solid var(--c-border); }
.tab { padding: 7px 14px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; color: var(--c-ink-soft); text-decoration: none; font-size: 13px; font-weight: 500; }
.tab:hover { background: var(--c-bg); color: var(--c-ink); }
.tab.is-active { background: var(--c-surface); border: 1px solid var(--c-border); border-bottom: 1px solid var(--c-surface); color: var(--c-ink); font-weight: 600; margin-bottom: -1px; }

/* ---------- Booking status bar ---------- */
.booking-status-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.badge-lg { font-size: 14px; padding: 4px 14px; }
.badge.info { background: #dbeafe; color: #1e40af; }

/* ---------- Trades layout ---------- */
.trades-layout { display: grid; grid-template-columns: 1fr 2fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .trades-layout { grid-template-columns: 1fr; } }

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.card-foot { border-top: 1px solid var(--c-border); padding-top: 14px; margin-top: 14px; }

.jobs-group { padding: 12px 0; border-bottom: 1px solid var(--c-border); }
.jobs-group:last-child { border-bottom: 0; }
.jobs-group-title { margin: 0 0 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--c-ink-soft); }
.table-compact td, .table-compact th { padding: 7px 10px; font-size: 13px; }

.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.inline-form .input { flex: 1; }

/* ---------- Topbar actions ---------- */
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Detail list (quote summary) ---------- */
.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.detail-list dt { color: var(--c-ink-soft); font-weight: 600; }
.detail-list dd { margin: 0; }

/* ---------- Quote totals ---------- */
.totals-row td { border-bottom: 0; }
.totals-total td { border-top: 2px solid var(--c-border); }

/* ---------- Line item add form ---------- */
.line-item-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.line-item-form .input { flex: 1; min-width: 80px; }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(10,37,64,.45);
    z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-box {
    background: var(--c-surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2); padding: 28px; width: 100%; max-width: 480px;
}
.modal-box h3 { margin-top: 0; }

/* ---------- Messaging ---------- */
.msg-card .card-head { border-bottom: 1px solid var(--c-border); padding-bottom: 12px; margin-bottom: 0; }
.msg-thread {
    padding: 16px 0; display: flex; flex-direction: column; gap: 12px;
    max-height: 440px; overflow-y: auto;
}
.msg-bubble { max-width: 74%; display: flex; flex-direction: column; }
.msg-own    { align-self: flex-end;   align-items: flex-end; }
.msg-other  { align-self: flex-start; align-items: flex-start; }
.msg-meta   { display: flex; gap: 8px; align-items: baseline; margin-bottom: 3px; font-size: 11px; color: var(--c-ink-soft); }
.msg-own .msg-meta { flex-direction: row-reverse; }
.msg-sender { font-weight: 700; }
.msg-body {
    padding: 8px 14px; border-radius: 14px;
    font-size: 13px; line-height: 1.55; word-break: break-word;
}
.msg-own   .msg-body { background: var(--c-primary); color: #fff; border-bottom-right-radius: 3px; }
.msg-other .msg-body { background: var(--c-bg); border: 1px solid var(--c-border); color: var(--c-ink); border-bottom-left-radius: 3px; }
.msg-compose { border-top: 1px solid var(--c-border); padding-top: 14px; margin-top: 4px; }
.msg-compose-row { display: flex; gap: 8px; align-items: flex-end; }
.msg-compose-row textarea { flex: 1; resize: none; min-height: 44px; }
.msg-page-layout { display: grid; grid-template-columns: 1fr 280px; gap: 24px; align-items: start; }
.msg-aside .card p { margin-bottom: 0; }
@media (max-width: 900px) {
    .msg-page-layout { grid-template-columns: 1fr; }
}

/* ---------- Invoice ---------- */
.invoice-actions {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 10px; margin-bottom: 16px;
}
.invoice-doc { padding: 40px 48px; max-width: 860px; margin: 0 auto; }
.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 24px; }
.invoice-brand { font-size: 20px; font-weight: 700; color: var(--c-ink); margin-bottom: 6px; }
.invoice-address { white-space: pre-line; }
.invoice-from { font-size: 14px; line-height: 1.6; }
.invoice-meta { text-align: right; }
.invoice-title { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; color: var(--c-primary); margin-bottom: 12px; }
.invoice-meta-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--c-ink-soft); padding: 2px 12px 2px 0; text-align: left; }
.invoice-meta-table td { font-size: 14px; font-weight: 600; padding: 2px 0; }
.invoice-divider { border: none; border-top: 1px solid var(--c-border); margin: 20px 0; }
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; font-size: 14px; line-height: 1.6; }
.invoice-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--c-ink-soft); margin-bottom: 4px; font-weight: 700; }
.invoice-lines { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 0; }
.invoice-lines th { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--c-ink-soft); padding: 8px 10px; border-bottom: 2px solid var(--c-border); text-align: left; }
.invoice-lines td { padding: 10px 10px; border-bottom: 1px solid var(--c-border); }
.invoice-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-top: 16px; }
.invoice-total-row { display: flex; gap: 48px; font-size: 14px; }
.invoice-total-row span:first-child { color: var(--c-ink-soft); min-width: 120px; text-align: right; }
.invoice-total-final { font-size: 18px; font-weight: 700; border-top: 2px solid var(--c-border); padding-top: 8px; margin-top: 4px; }
.invoice-notes { font-size: 14px; line-height: 1.6; }

@media print {
    .no-print, .shell-nav, .shell-topbar, .page-actions { display: none !important; }
    .shell-main { padding: 0 !important; }
    .shell-content { padding: 0 !important; }
    .invoice-doc { box-shadow: none !important; border: none !important; padding: 0 !important; max-width: 100% !important; }
    body { background: #fff !important; }
}

/* ---------- Customer chat hub ---------- */
.chat-shell {
    display: grid;
    grid-template-columns: 290px 1fr;
    height: calc(100vh - 145px);
    min-height: 520px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.chat-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--c-border);
    overflow: hidden;
}
.chat-sidebar-head {
    padding: 12px 14px;
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
}
.chat-search-input {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--c-bg);
    color: var(--c-ink);
}
.chat-search-input:focus {
    outline: 2px solid var(--c-focus);
    outline-offset: 2px;
}
.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--c-border);
    text-decoration: none;
    color: inherit;
    transition: background .12s;
}
.chat-item:hover  { background: var(--c-bg); }
.chat-item.is-active { background: #eef3fa; border-left: 3px solid var(--c-primary); padding-left: 11px; }
.chat-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--c-primary-2); color: #fff;
    display: grid; place-items: center;
    font-size: 12px; font-weight: 700;
    flex-shrink: 0;
}
.chat-item.is-active .chat-avatar { background: var(--c-primary); }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-name {
    font-size: 13px; font-weight: 600; color: var(--c-ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-preview {
    font-size: 12px; color: var(--c-ink-soft); margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-time { font-size: 11px; color: var(--c-muted); flex-shrink: 0; }
.chat-main { display: flex; flex-direction: column; overflow: hidden; }
.chat-main-head {
    padding: 14px 20px;
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
}
.chat-main-name { font-size: 15px; font-weight: 600; margin: 0; }
.chat-main-name a { color: var(--c-ink); text-decoration: none; }
.chat-main-name a:hover { text-decoration: underline; }
.chat-main-meta { font-size: 12px; color: var(--c-ink-soft); margin-top: 3px; }
.chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-thread-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--c-muted);
    font-size: 13px;
}
.chat-compose {
    padding: 12px 16px;
    border-top: 1px solid var(--c-border);
    flex-shrink: 0;
}
.chat-compose-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-compose-row textarea { flex: 1; resize: none; min-height: 44px; }
.chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--c-muted);
    font-size: 14px;
    text-align: center;
    flex-direction: column;
}
@media (max-width: 860px) {
    .chat-shell { grid-template-columns: 1fr; height: auto; min-height: unset; }
    .chat-sidebar { max-height: 300px; border-right: none; border-bottom: 1px solid var(--c-border); }
    .chat-main { min-height: 420px; }
}

/* ---------- Calendar legend ---------- */
.cal-legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.legend-label { color: var(--c-ink-soft); margin-right: 6px; }

/* ---------- Booking history ---------- */
.booking-history { border: 1px solid var(--c-border); border-radius: var(--radius); background: #fff; }
.booking-history-summary {
    list-style: none; display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; cursor: pointer; user-select: none;
    font-weight: 600; font-size: 14px; color: var(--c-ink);
}
.booking-history-summary::-webkit-details-marker { display: none; }
.booking-history-summary::before {
    content: '▶'; font-size: 10px; color: var(--c-ink-soft);
    transition: transform 0.15s; display: inline-block;
}
details[open] > .booking-history-summary::before { transform: rotate(90deg); }
.booking-history-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 6px;
    background: var(--c-bg-alt); border-radius: 10px;
    font-size: 11px; font-weight: 700; color: var(--c-ink-soft);
}
.booking-history-body { padding: 4px 16px 16px; border-top: 1px solid var(--c-border); }
.bh-timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.bh-timeline::before {
    content: ''; position: absolute; left: 7px; top: 8px; bottom: 4px;
    width: 2px; background: var(--c-border);
}
.bh-event { display: flex; gap: 14px; align-items: flex-start; padding: 10px 0 2px; }
.bh-dot {
    width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; margin-top: 1px;
    background: #fff; border: 2px solid var(--c-primary); position: relative; z-index: 1;
}
.bh-content { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; flex: 1; }
.bh-label { font-weight: 600; font-size: 14px; }
.bh-detail { font-size: 13px; color: var(--c-ink-soft); }
.bh-meta { font-size: 12px; color: var(--c-muted); width: 100%; margin-top: 1px; }

/* ---------- Workflow health ---------- */
.wf-badge { display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 12px 24px; border-radius: var(--radius); min-width: 110px; }
.wf-badge-red   { background: #fee2e2; border: 1px solid #fca5a5; }
.wf-badge-amber { background: #fef3c7; border: 1px solid #fcd34d; }
.wf-badge-count { font-size: 32px; font-weight: 800; line-height: 1; }
.wf-badge-red   .wf-badge-count { color: #b91c1c; }
.wf-badge-amber .wf-badge-count { color: #92400e; }
.wf-badge-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.wf-badge-red   .wf-badge-label { color: #b91c1c; }
.wf-badge-amber .wf-badge-label { color: #92400e; }

.wf-section { border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.wf-section-red   { border: 1px solid #fca5a5; }
.wf-section-amber { border: 1px solid #fcd34d; }
.wf-section-head {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; font-weight: 600; cursor: pointer;
    list-style: none; user-select: none;
}
.wf-section-red   .wf-section-head { background: #fee2e2; color: #b91c1c; }
.wf-section-amber .wf-section-head { background: #fef3c7; color: #92400e; }
.wf-section-head::-webkit-details-marker { display: none; }
.wf-sev-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.wf-dot-red   { background: #dc2626; }
.wf-dot-amber { background: #d97706; }
.wf-count-pill {
    background: rgba(0,0,0,.12); color: inherit;
    font-size: 12px; font-weight: 700; border-radius: 99px;
    padding: 1px 8px; margin-left: 2px;
}
.wf-chevron { margin-left: auto; transition: transform .2s; }
details[open] .wf-chevron { transform: rotate(180deg); }
.wf-section-body { background: var(--c-surface); }
.wf-section-body .table { margin: 0; }
.wf-section-body .table th { background: var(--c-bg); }

/* Coloured table rows */
.table.table-cards tbody tr.wf-row-red td {
    background: #fff5f5;
    border-top-color: #fca5a5; border-bottom-color: #fca5a5;
}
.table.table-cards tbody tr.wf-row-red td:first-child { border-left-color: #fca5a5; }
.table.table-cards tbody tr.wf-row-red td:last-child  { border-right-color: #fca5a5; }
.table.table-cards tbody tr.wf-row-red[data-href]:hover td {
    background: #fee2e2;
    border-top-color: #f87171; border-bottom-color: #f87171;
}
.table.table-cards tbody tr.wf-row-red[data-href]:hover td:first-child { border-left-color: #f87171; }
.table.table-cards tbody tr.wf-row-red[data-href]:hover td:last-child  { border-right-color: #f87171; }

.table.table-cards tbody tr.wf-row-amber td {
    background: #fffbeb;
    border-top-color: #fde68a; border-bottom-color: #fde68a;
}
.table.table-cards tbody tr.wf-row-amber td:first-child { border-left-color: #fde68a; }
.table.table-cards tbody tr.wf-row-amber td:last-child  { border-right-color: #fde68a; }
.table.table-cards tbody tr.wf-row-amber[data-href]:hover td {
    background: #fef3c7;
    border-top-color: #fcd34d; border-bottom-color: #fcd34d;
}
.table.table-cards tbody tr.wf-row-amber[data-href]:hover td:first-child { border-left-color: #fcd34d; }
.table.table-cards tbody tr.wf-row-amber[data-href]:hover td:last-child  { border-right-color: #fcd34d; }

/* ---------- Alert success (missing from original) ---------- */
.alert-success { background: #dcfce7; border: 1px solid #bbf7d0; color: #15803d; }

/* ---------- Defaults: mobile chrome hidden on desktop ---------- */
.mobile-menu-btn { display: none; }
/* position:fixed takes overlay out of grid flow on all viewports — display:none hides it */
.mobile-overlay  { display: none; position: fixed; inset: 0; z-index: 299; }

/* ---------- Logo size grid (branding page) ---------- */
.logo-size-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ---------- Reduce tap-delay on touch devices ---------- */
a, button, [role="button"], input, select, textarea, label, summary {
    touch-action: manipulation;
}

/* =============================================================================
   RESPONSIVE
   Tablet   ≤ 768 px — icon-only sidebar
   Mobile   ≤ 480 px — off-canvas drawer  (iPhone 13 portrait = 390 px logical)
   ============================================================================= */

/* ── Tablet: collapse sidebar to icon rail ───────────────────────────── */
@media (max-width: 768px) {
    .shell { grid-template-columns: var(--sb-w-collapsed) 1fr; }
    .shell .nav-label, .shell .brand-text,
    .shell .user-info, .shell .signout { display: none; }
    .shell .nav-link  { justify-content: center; }
    .shell .user-card { justify-content: center; }
    .shell .brand img { width: 15px; height: 15px; object-fit: contain; }
    .topbar { padding: 14px 20px; }
    .page   { padding: 20px; }
    /* Icon rail has no room for a collapsible trigger — always show admin links */
    .nav-section-trigger { display: none; }
    details.nav-section > .nav-section-body { display: block !important; }
}

/* ── Mobile: off-canvas drawer, content-first ────────────────────────── */
@media (max-width: 480px) {

    /* 1 ── Shell: single full-width column */
    .shell { grid-template-columns: 1fr !important; }

    /* 2 ── Sidebar: hidden off-canvas, slides in as overlay */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: min(280px, 82vw);
        height: 100vh; height: 100dvh;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform 0.22s cubic-bezier(.4, 0, .2, 1);
        box-shadow: 4px 0 24px rgba(10,37,64,.35);
        overflow-y: auto; overflow-x: hidden;
    }
    /* Always show full labels inside the mobile drawer */
    .sidebar .nav-label,
    .sidebar .brand-text,
    .sidebar .user-info,
    .sidebar .signout { display: initial !important; }
    .sidebar .nav-link    { justify-content: flex-start !important; padding: 11px 16px; }
    .sidebar .user-card   { justify-content: flex-start !important; }
    /* Section trigger always visible in drawer; <details> handles body show/hide */
    .nav-section-trigger { display: flex !important; }
    details.nav-section > .nav-section-body { display: revert !important; }

    /* 3 ── Open state */
    .shell[data-mobile-nav="open"] .sidebar { transform: translateX(0); }

    /* 4 ── Dark overlay backdrop */
    .mobile-overlay {
        background: rgba(10,37,64,.48);
        backdrop-filter: blur(1px);
        -webkit-backdrop-filter: blur(1px);
    }
    .shell[data-mobile-nav="open"] .mobile-overlay { display: block; }

    /* 5 ── Hamburger button */
    .mobile-menu-btn {
        display: flex !important;
        align-items: center; justify-content: center;
        flex-shrink: 0;
        width: 38px; height: 38px;
        background: transparent;
        border: 1px solid var(--c-border);
        border-radius: var(--radius-sm);
        color: var(--c-ink-soft);
        cursor: pointer;
    }
    .mobile-menu-btn:active { background: var(--c-bg); }

    /* Hide the desktop sidebar-toggle on phone (mobile uses mobileMenuBtn) */
    #sidebarToggle { display: none; }

    /* 6 ── Topbar: compact, actions wrap to second row */
    .topbar {
        padding: 10px 14px;
        gap: 8px;
        flex-wrap: wrap;
        row-gap: 6px;
        align-items: center;
    }
    .mobile-menu-btn { order: 0; }
    .page-title { order: 1; flex: 1; font-size: 16px; font-weight: 600; }
    .topbar-actions {
        order: 2;
        flex-basis: 100%;
        display: flex; gap: 6px; flex-wrap: wrap;
        padding-bottom: 4px;
    }
    .topbar-actions .btn { font-size: 11px; padding: 5px 9px; }

    /* 7 ── Page & card padding */
    .page { padding: 12px; padding-bottom: max(16px, env(safe-area-inset-bottom, 16px)); }
    .card { padding: 14px 16px; }

    /* 8 ── Tables: scroll inside their card */
    .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table { min-width: 480px; }
    /* Compact tables don't need the forced min-width */
    .table-compact { min-width: 0; }

    /* 9 ── Stat cards: 2-up */
    .stats-row { gap: 8px; }
    .stat-card  { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 12px 10px; }
    .stat-value { font-size: 24px; }
    .stat-label { font-size: 11px; }

    /* 10 ── Forms: single column */
    .form-row { grid-template-columns: 1fr !important; }

    /* 11 ── Grid helpers */
    .grid.cols-3,
    .grid.cols-4       { grid-template-columns: 1fr !important; }
    .logo-size-grid    { grid-template-columns: 1fr !important; }
    .trades-layout     { grid-template-columns: 1fr !important; }
    .msg-page-layout   { grid-template-columns: 1fr !important; }
    .invoice-parties   { grid-template-columns: 1fr !important; }

    /* 12 ── Modal → bottom sheet */
    .modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }
    .modal-box {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-width: 100%;
        max-height: 88vh; max-height: 88dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
    }

    /* 13 ── Chat: stacked columns */
    .chat-shell { grid-template-columns: 1fr; height: auto; min-height: unset; }
    .chat-sidebar {
        max-height: 260px;
        border-right: none;
        border-bottom: 1px solid var(--c-border);
    }
    .chat-thread { max-height: 360px; padding: 14px; }

    /* 14 ── Invoice: collapse header */
    .invoice-doc    { padding: 16px 12px; }
    .invoice-header { flex-direction: column; gap: 12px; }
    .invoice-meta   { text-align: left; }

    /* 15 ── Filter tabs: scroll not wrap */
    .filter-tabs {
        flex-wrap: nowrap;
        overflow-x: auto; -webkit-overflow-scrolling: touch;
        padding-bottom: 8px;
        scrollbar-width: none;
    }
    .filter-tabs::-webkit-scrollbar { display: none; }
    .tab { white-space: nowrap; }

    /* 16 ── Page-level misc */
    .page-actions         { flex-wrap: wrap; gap: 8px; }
    .booking-status-bar   { flex-wrap: wrap; }
    .search-bar .input    { max-width: 100%; }
    .line-item-form       { flex-direction: column; }
    .line-item-form .input { flex: none; width: 100%; }

    /* 17 ── Auth pages */
    .auth-body { padding: 12px; }
    .auth-card { padding: 24px 18px; }
    .auth-foot { font-size: 12px; }
}
