/* ═══════════════════════════════════════════════════════════════════════════
   BMS Dashboard v2 — Unified CSS v068
   Replaces app.css + bms_compact_ui_055.css + bms_dense_ui_056.css
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
    --bg:         #f0f2f7;
    --surface:    #ffffff;
    --border:     #e2e8f2;
    --ink:        #111827;
    --muted:      #6b7280;
    --brand:      #141f35;
    --accent:     #c0392b;
    --accent-hov: #a93226;
    --good:       #16a34a;
    --good-bg:    #f0fdf4;
    --warn:       #d97706;
    --warn-bg:    #fffbeb;
    --bad:        #dc2626;
    --bad-bg:     #fef2f2;
    --info:       #2563eb;
    --info-bg:    #eff6ff;
    --radius:     10px;
    --radius-lg:  14px;
    --shadow:     0 1px 4px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.04);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
p { margin: 0 0 10px; line-height: 1.5; }
p:last-child { margin-bottom: 0; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; font-weight: 700; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
pre { white-space: pre-wrap; overflow: auto; }
textarea { resize: vertical; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 210px;
    flex-shrink: 0;
    background: var(--brand);
    color: #e9eef7;
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.brand {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -.3px;
    color: #fff;
    padding: 4px 8px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    margin-bottom: 10px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar a {
    display: block;
    text-decoration: none;
    padding: 8px 10px;
    border-radius: 8px;
    color: #c8d3e8;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.sidebar a:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar a.active { background: rgba(255,255,255,.14); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 12px;
    flex-shrink: 0;
}
.userbar { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 13px; }

.content { padding: 18px 20px; flex: 1; }

/* ── Grid ────────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid.two  { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
}
.card:last-child { margin-bottom: 0; }

/* Metric cards */
.metric span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 6px;
}
.metric strong { display: block; font-size: 28px; font-weight: 800; line-height: 1.1; }
.link-card { text-decoration: none; color: inherit; cursor: pointer; }
.link-card:hover { border-color: var(--accent); transform: translateY(-1px); transition: transform .15s, border-color .15s; }

/* Sub-card */
.sub-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-top: 12px;
}
.sub-card span { display: block; margin-bottom: 4px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
label { display: grid; gap: 4px; margin-bottom: 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
input, select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    background: var(--surface);
    transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
    line-height: 1.3;
}
button:hover, .button:hover { background: var(--accent-hov); }
.button.ghost { background: #eef1f8; color: var(--ink); }
.button.ghost:hover { background: #e2e8f2; }
.button.mini, button.mini { padding: 4px 8px; font-size: 11px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; border-bottom: 1px solid var(--border); padding: 8px 10px; vertical-align: top; line-height: 1.4; }
th { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fafbfd; }
.inactive-row { opacity: .65; }

/* ── Badges & status ─────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
    background: #eef1f8;
    color: var(--ink);
    white-space: nowrap;
}
.badge.good  { background: var(--good-bg);  color: var(--good); }
.badge.warn  { background: var(--warn-bg);  color: var(--warn); }
.badge.bad   { background: var(--bad-bg);   color: var(--bad); }
.badge.info  { background: var(--info-bg);  color: var(--info); }
.badge.muted { background: #f1f5f9; color: var(--muted); }
.badge.alert { background: #fef3c7; color: #92400e; }

/* ── Filters & filter actions ────────────────────────────────────────────── */
.filters,
.jobs-filters,
.frequency-filters,
.collections-filters,
.collections-filters-v2 {
    display: grid;
    gap: 10px;
    align-items: end;
    margin-bottom: 12px;
}
.filters                { grid-template-columns: 1.5fr 1fr 1fr auto; }
.jobs-filters           { grid-template-columns: 1.4fr 1fr 1fr 1fr auto; }
.frequency-filters      { grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr auto; }
.collections-filters    { grid-template-columns: 1.5fr 1fr auto; }
.collections-filters-v2 { grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr auto; }
.filter-actions { display: flex; gap: 8px; align-items: center; }

/* ── Detail grid (job/location header tiles) ─────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}
.detail-grid > div {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}
.detail-grid span { display: block; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.detail-grid strong { display: block; font-size: 15px; font-weight: 700; line-height: 1.2; }

/* ── Alerts & flash ──────────────────────────────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--bad-bg);
    border: 1px solid #fecaca;
    margin-bottom: 14px;
    font-size: 13px;
}
.alert.good { background: var(--good-bg); border-color: #bbf7d0; }

/* ── Misc helpers ────────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
.small-note { font-size: 12px; line-height: 1.35; color: var(--muted); }
.location-subline, .address-line { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.25; }
.service-address, .address-block { font-size: 12px; color: var(--muted); line-height: 1.35; }
.checkline { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 600; font-size: 13px; }
.checkline input[type="checkbox"] { width: auto; }
.checkline.small { font-size: 12px; margin-bottom: 4px; }
.inactive-mini { font-size: 11px; padding: 3px 6px; margin-top: 3px; }
.table-actions { display: flex; gap: 8px; align-items: center; }
.quick-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.quick-links a { text-decoration: none; background: #eef1f8; color: var(--ink); border-radius: 999px; padding: 5px 10px; font-weight: 700; font-size: 12px; }
.quick-links a:hover { background: #e2e8f2; }
.collection-quick-links { margin: 8px 0 10px; }
.login-card { max-width: 400px; margin: 60px auto; }
.inline-form { display: grid; grid-template-columns: 130px 70px auto; gap: 8px; align-items: center; margin: 8px 0 12px; }
.inline-form select, .inline-form input { padding: 8px; font-size: 13px; }
.mini-form { display: grid; gap: 5px; min-width: 170px; }
.mini-form select, .mini-form input { font-size: 13px; padding: 7px 8px; }

/* ── Flags ───────────────────────────────────────────────────────────────── */
.flag-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.flag-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 7px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    border: 1px solid rgba(0,0,0,.08);
    background: #eef1f7;
    color: #334155;
    margin-top: 2px;
}
.flag-red    { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.flag-yellow { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.flag-green  { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.flag-blue   { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.flag-orange { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.flag-purple { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.flag-gray   { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.flag-list { display: grid; gap: 6px; margin-bottom: 10px; }
.flag-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.flag-item:last-child { border-bottom: 0; }
.flag-form { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; align-items: end; margin-top: 10px; }
.flag-form label { margin: 0; }

/* ── Payroll ─────────────────────────────────────────────────────────────── */
.payroll-period-form,
.payroll-employee-form,
.payroll-select-form { grid-template-columns: 1fr 1fr auto; }
.payroll-adjustment-form,
.payroll-double-form { grid-template-columns: 1fr 1.4fr 1fr auto; }
.payroll-jobs-table td { vertical-align: top; }
.payroll-stub h3 { margin-top: 16px; margin-bottom: 6px; }
.payroll-job-list { margin-top: 6px; display: grid; gap: 4px; }
.payroll-job-list li { padding-bottom: 4px; }
.payroll-row-selected { background: #f0fdf4; }

/* ── Job tools ───────────────────────────────────────────────────────────── */
.bms050-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.bms050-mini-note { font-size: 11px; margin-top: 2px; line-height: 1.25; color: var(--muted); }
.bms050-desc-card { padding-top: 12px; padding-bottom: 12px; }
.bms050-desc-view { min-height: 0; max-height: 200px; overflow: auto; padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.3; background: #f8fafc; border: 1px solid var(--border); }
.bms050-panel { margin-top: 8px; padding: 10px; border-radius: var(--radius-lg); background: #f8fafc; border: 1px solid var(--border); }
.bms050-items { display: grid; gap: 8px; }
.bms050-line { border-radius: 10px; padding: 8px; background: var(--surface); border: 1px solid var(--border); }
.bms050-line-grid { display: grid; grid-template-columns: minmax(160px,2fr) 70px 90px minmax(130px,1.2fr) 100px 95px auto; gap: 7px; align-items: end; }
.bms050-line-grid label { font-size: 11px; margin: 0 0 2px; }
.bms050-line-grid input, .bms050-line-grid select, .bms050-line-grid textarea { padding: 6px 7px; border-radius: 7px; font-size: 13px; }
.bms050-line-total { font-size: 13px; padding: 6px 0; }
.bms050-add-box { margin-top: 8px; padding: 10px; border-radius: 10px; background: #f8fafc; border: 1px dashed var(--border); }
.bms050-alert { padding: 8px 10px; border-radius: 8px; margin: 6px 0; font-size: 12px; background: var(--bad-bg); color: var(--bad); }
.bms050-alert.good { background: var(--good-bg); color: var(--good); }
.bms-photos-wrap h3 { font-size: 14px; font-weight: 700; }

/* ── Tax ─────────────────────────────────────────────────────────────────── */
.bms-tax-card, .tax-card { padding: 12px 14px; }

/* ── Location page ───────────────────────────────────────────────────────── */
.location-hero h2 { margin: 0 0 4px; font-size: 20px; }
.location-hero .sub-card { margin-top: 8px; padding: 10px; }

/* ── Collections ─────────────────────────────────────────────────────────── */
.mini-form select, .mini-form input { font-size: 13px; padding: 7px 8px; }

/* ── Details element (collapsible) ──────────────────────────────────────── */
details.card > summary { list-style: none; cursor: pointer; }
details.card > summary::-webkit-details-marker { display: none; }

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .quick-links, .bms050-actions, .filter-actions,
    form, button:not(.print-keep), .button:not(.print-keep) { display: none !important; }
    .app-shell { display: block; }
    .content { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; padding: 10px; }
    .main { margin: 0; }
}

/* ── Mobile / tablet ─────────────────────────────────────────────────────── */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--ink);
    flex-direction: column;
    gap: 5px;
}
.nav-toggle span { display: block; width: 20px; height: 2px; background: currentColor; border-radius: 2px; transition: transform .2s, opacity .2s; }
.nav-toggle.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.is-open span:nth-child(2) { opacity: 0; }
.nav-toggle.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 999; }
.sidebar-overlay.is-open { display: block; }

@media (max-width: 768px) {
    .nav-toggle { display: flex; }
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; width: 250px;
        z-index: 1000; transform: translateX(-100%); transition: transform .25s ease; overflow-y: auto;
    }
    .sidebar.is-open { transform: translateX(0); }
    .app-shell { display: block; }
    .topbar { position: sticky; top: 0; z-index: 100; padding: 0 14px; height: 50px; }
    .content { padding: 12px; }
    .grid.four { grid-template-columns: repeat(2, 1fr) !important; }
    .grid.two  { grid-template-columns: 1fr !important; }
    .detail-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .filters, .jobs-filters, .frequency-filters,
    .collections-filters, .collections-filters-v2,
    .payroll-period-form, .payroll-employee-form, .payroll-select-form,
    .payroll-adjustment-form, .payroll-double-form { grid-template-columns: 1fr !important; }
    .bms050-line-grid { grid-template-columns: 1fr 1fr !important; }
    .bms050-line-grid > div:first-child { grid-column: 1 / -1 !important; }
    .hide-mobile { display: none !important; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar { width: 190px; }
    .content { padding: 16px; }
    .grid.four { grid-template-columns: repeat(2, 1fr) !important; }
    .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .filters, .jobs-filters, .frequency-filters,
    .collections-filters-v2 { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 1024px) {
    .sidebar a { padding: 10px; font-size: 14px; }
    button, .button { min-height: 40px; }
    input, select, textarea { font-size: 16px !important; }
}

@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .topbar { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
        .content { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    }
}

/* ── 056 dense UI overrides (merged in) ──────────────────────────────────── */
.bms052-flags-wrap { gap: 12px; }
.bms052-flag-card h2 { margin-bottom: 7px; }
.bms052-local-badge { padding: 3px 7px; font-size: 11px; }
.bms052-note { font-size: 11px; margin-top: 4px; line-height: 1.25; }
.bms052-form { margin-top: 9px; padding-top: 9px; gap: 7px; display: grid; }
.bms052-row { display: flex; gap: 8px; }
.bms052-form select, .bms052-form input, .bms052-form textarea,
.bms052-admin-form select, .bms052-admin-form input { padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.bms052-form textarea { min-height: 36px; }
.bms052-flags-wrap { display: grid; gap: 12px; }
.bms053-status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: 8px; }
.bms053-tile { border-radius: 10px; padding: 8px 10px; background: #f8fafc; border: 1px solid var(--border); }
.bms053-label { font-size: 10px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; display: block; }
.bms053-value { font-size: 14px; font-weight: 600; line-height: 1.2; }
.bms053-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.bms053-pill { padding: 3px 7px; font-size: 11px; border-radius: 999px; }
.bms053-note { margin-top: 7px; padding: 8px 10px; font-size: 12px; line-height: 1.3; background: #f8fafc; border-radius: 8px; border: 1px solid var(--border); }
.bms053-time-table { margin-top: 6px; font-size: 12px; }
.bms053-time-table th, .bms053-time-table td { padding: 5px 6px; }
.bms053-total-line { font-size: 12px; margin-top: 6px; }
.bms053-muted { font-size: 12px; color: var(--muted); line-height: 1.3; }
.bms050-panel-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.bms050-loading { padding: 8px 10px; font-size: 12px; color: var(--muted); }
.bms050-remove-row { display: flex; margin-top: 6px; gap: 8px; }
.bms050-small-button { padding: 5px 8px; font-size: 12px; }
.bms050-desc-form { margin-top: 8px; }
.bms050-desc-form textarea { min-height: 100px; font-size: 13px; }
.bms050-desc-card h2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bms053-card-tight { padding: 12px 14px; }
.bms053-card-tight h2 { font-size: 16px; margin-bottom: 8px; }
.active-toggle { margin: 0; }
.active-toggle .checkline { margin-bottom: 0; }
.payroll-mini { min-width: 220px; max-width: 300px; }
.employee-claim-table th, .employee-claim-table td { vertical-align: top; }
.employee-claim-table input[type="text"], .employee-claim-table input:not([type]), .employee-claim-table select { min-width: 140px; }
.employee-claim-table td:first-child { text-align: center; }
.employee-claim-table .checkline { display: block; margin-bottom: 4px; }
