/* 7x7 Fleet Operator Portal - styling matches the Manus wireframe:
   dark sidebar, amber/gold accent, card-based dashboard, right-hand cart panel. */

:root {
    --ink: #14161a;
    --sidebar-bg: #14161a;
    --sidebar-text: #cfd3d8;
    --accent: #e8a33d;
    --accent-dark: #c8842a;
    --bg: #f4f5f7;
    --card-bg: #ffffff;
    --border: #e6e8eb;
    --text: #1c1f24;
    --text-muted: #6b7280;
    --green: #1f9d55;
    --blue: #3b82f6;
    --purple: #8b5cf6;
    --red: #e0403e;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { text-decoration: none; color: inherit; }

.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr 300px;
    min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.brand-mark {
    background: var(--accent);
    color: #1c1f24;
    font-weight: 700;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-name { font-weight: 600; color: #fff; }
.brand-sub { font-size: 12px; color: #9aa1ab; }

.fleet-account {
    background: #1e2128;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 18px;
}

.fleet-account-label { font-size: 10px; letter-spacing: .06em; color: #8b93a0; margin-bottom: 6px; }
.fleet-account-name { font-weight: 600; color: #fff; }
.fleet-account-meta { font-size: 12px; color: #9aa1ab; margin: 2px 0 6px; }
.fleet-account-badge { font-size: 11px; color: var(--accent); }

.nav-links { list-style: none; margin: 0; padding: 0; flex: 1; }
.nav-links li { margin-bottom: 4px; }

.nav-link {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 14px;
}

.nav-link:hover { background: #1e2128; }

.nav-link.active {
    background: var(--accent);
    color: #1c1f24;
    font-weight: 600;
}

.sidebar-footer { padding-top: 16px; border-top: 1px solid #262a32; }
.signout-link { color: #9aa1ab; font-size: 13px; }
.signout-link:hover { color: #fff; }

/* MAIN COLUMN */
.main-column { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-title { font-size: 20px; font-weight: 700; }
.page-subtitle { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.account-chip { display: flex; align-items: center; gap: 10px; }
.account-chip-text { text-align: right; }
.account-chip-name { font-size: 13px; font-weight: 600; }
.account-chip-email { font-size: 12px; color: var(--text-muted); }
.account-chip-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--ink); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}

.content { padding: 24px 28px; }

/* Generic card */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.card-title { font-size: 12px; letter-spacing: .06em; color: var(--text-muted); font-weight: 700; margin-bottom: 6px; }
.card-heading { font-size: 18px; font-weight: 700; margin: 0 0 4px; }

/* Page/card header rows (title block + action button(s)) - a shared class instead of the
   inline style="display:flex;..." these used to have, specifically so the ≤768px rule below
   can actually override it. Inline styles win over an external stylesheet without !important,
   so this couldn't be fixed by CSS alone while it stayed inline. */
.page-header-row { display: flex; justify-content: space-between; align-items: flex-start; }

/* Alert banners */
.alert-banner {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-radius: 10px; margin-bottom: 12px; font-size: 14px;
}
.alert-banner.danger { background: #fdecec; color: #7a1f1e; border: 1px solid #f6c9c8; }
.alert-banner.info { background: #f0edfc; color: #3d2f7a; border: 1px solid #ddd4f8; }
.alert-banner a.alert-action { font-weight: 700; text-decoration: underline; white-space: nowrap; margin-left: 12px; }

/* Stat cards row */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: block; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
.stat-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.stat-icon { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; font-size: 14px; }
.stat-icon.total { background: #eef1f5; color: #4b5563; }
.stat-icon.certified { background: #e6f7ec; color: var(--green); }
.stat-icon.progress { background: #e8f0fe; color: var(--blue); }
.stat-icon.awaiting { background: #f0edfc; color: var(--purple); }
.stat-icon.expired { background: #fdecec; color: var(--red); }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* Two-column dashboard layout */
.dash-columns { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }

.health-bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; margin: 12px 0; }
.health-seg.certified { background: var(--green); }
.health-seg.progress { background: var(--blue); }
.health-seg.awaiting { background: var(--purple); }
.health-seg.expired { background: var(--red); }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); margin-bottom: 16px; flex-wrap: wrap; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.legend-dot.certified { background: var(--green); }
.legend-dot.progress { background: var(--blue); }
.legend-dot.awaiting { background: var(--purple); }
.legend-dot.expired { background: var(--red); }

.driver-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); text-decoration: none; color: inherit; margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 6px; }
.driver-row:first-of-type { border-top: none; }
.driver-row:hover { background: var(--bg, #f4f5f7); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #eef1f5; color: #4b5563; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0; }
.driver-name { font-weight: 600; font-size: 14px; flex: 1; }

.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.badge.certified { background: #e6f7ec; color: var(--green); }
.badge.progress { background: #e8f0fe; color: var(--blue); }
.badge.awaiting { background: #f0edfc; color: var(--purple); }
.badge.expired { background: #fdecec; color: var(--red); }
.badge.pending { background: #f3f4f6; color: #6b7280; }
.badge.needs-renewal { background: #fdf3e3; color: var(--accent-dark); }

.view-all-link { display: block; margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--text); }

.quick-actions { display: flex; flex-direction: column; gap: 8px; }
.quick-action-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--card-bg); font-size: 14px; font-weight: 600; cursor: pointer; text-align: left;
}
.quick-action-btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.quick-action-btn:hover { border-color: var(--accent); }

.activity-item { padding: 10px 0; border-top: 1px solid var(--border); font-size: 13px; }
.activity-item:first-of-type { border-top: none; }
.activity-time { color: var(--text-muted); font-size: 12px; }

/* Tables (Drivers / Billing) */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; font-size: 11px; letter-spacing: .04em; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }

/* Drivers table's mobile-only detail-disclosure cell (see .data-table's ≤768px rules below
   for the counterpart .desktop-only-cell) - hidden by default/desktop. */
.mobile-only-cell { display: none; }

.filter-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-tab {
    padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px;
    background: var(--card-bg); cursor: pointer;
}
.filter-tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.search-input, .text-input {
    width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 14px;
}

/* -webkit-appearance:none strips native OS control chrome from <input type=submit/button> -
   without it, iOS Safari in particular can render these with a native text color that ignores
   the inherited/CSS `color`, making unstyled-color buttons (like .btn-outline below) render
   with invisible text even though the button itself is fully visible and clickable. */
.btn { -webkit-appearance: none; appearance: none; display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid var(--border); background: #fff; color: var(--text); }
.btn-dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-outline { background: #fff; color: var(--text); }
.btn-link { background: none; border: none; color: var(--accent-dark); font-weight: 700; padding: 0; }
.btn-danger-outline { color: var(--red); border-color: #f6c9c8; background: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }

.inline-panel { background: #fbf8f2; border: 1px solid #f0e3c9; border-radius: 10px; padding: 16px; margin-bottom: 18px; }

.toggle {
    position: relative; display: inline-block; width: 40px; height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; cursor: pointer; inset: 0; background: #d1d5db; border-radius: 999px; transition: .15s;
}
.toggle-slider:before {
    content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .15s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(18px); }

.row-between { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--border); }
.row-between:first-of-type { border-top: none; }

/* Pricing cards */
.pricing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.pricing-card { border: 1px solid var(--border); border-radius: 12px; padding: 18px; position: relative; }
.pricing-card.featured { border-color: var(--accent); background: #fffaf1; }
.pricing-badge { position: absolute; top: -10px; right: 14px; background: var(--accent); color: #1c1f24; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.pricing-tier { font-size: 11px; letter-spacing: .06em; color: var(--text-muted); font-weight: 700; }
.pricing-price { font-size: 28px; font-weight: 800; margin: 6px 0 2px; }
.pricing-detail { font-size: 12px; color: var(--text-muted); }

/* RIGHT: License Cart panel */
.cart-panel {
    background: var(--card-bg);
    border-left: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.cart-header { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.cart-count { background: var(--ink); color: #fff; font-size: 11px; border-radius: 999px; padding: 1px 8px; }
.cart-subheader { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }

.cart-section { margin-bottom: 14px; }
.cart-section-label { font-size: 11px; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; margin-bottom: 8px; }

.cart-line { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.cart-line-avatar { width: 30px; height: 30px; border-radius: 50%; background: #eef1f5; color: #4b5563; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.cart-line-text { flex: 1; min-width: 0; }
.cart-line-name { font-size: 13px; font-weight: 600; }
.cart-line-email { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-line-price { font-size: 13px; font-weight: 700; }
.cart-line-remove { flex-shrink: 0; color: var(--text-muted); font-size: 12px; text-decoration: none; padding: 2px 4px; border-radius: 4px; }
.cart-line-remove:hover { color: #dc2626; background: #fdecec; }

.cart-empty { font-size: 13px; color: var(--text-muted); padding: 20px 0; text-align: center; }

.cart-summary { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }
.cart-rate-note { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.cart-summary-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; }
.cart-summary-total { font-weight: 800; font-size: 15px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }

.cart-payment { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 12px 0; color: var(--text-muted); }

.cart-promo-entry { display: flex; gap: 6px; margin: 10px 0; }
.cart-promo-entry .text-input { flex: 1; min-width: 0; }
.cart-promo-applied { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0; padding: 8px 10px; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; font-size: 12px; color: #166534; }
.cart-promo-applied strong { font-weight: 700; }
.cart-promo-error { font-size: 12px; color: #dc2626; margin: 4px 0 0; }
.cart-discount-row { color: #1f9d55; font-weight: 600; }
.cart-custom-pricing { margin: 12px 0; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: #fffaf1; }
.cart-custom-pricing .cart-rate-note { margin-bottom: 8px; }
.cart-custom-pricing .form-field { margin-bottom: 0; }

.btn-confirm-pay {
    width: 100%; background: var(--ink); color: #fff; border: none; border-radius: 8px;
    padding: 12px; font-size: 14px; font-weight: 700; cursor: pointer; margin-top: 6px;
}
.btn-confirm-pay:disabled { opacity: .4; cursor: not-allowed; }

.btn-clear-cart { display: block; text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 10px; }

/* Auth pages */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--ink); padding: 20px; }
.auth-card { background: #fff; border-radius: 14px; padding: 36px; width: 100%; max-width: 380px; }
.auth-title { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.auth-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 22px; }
.auth-field { margin-bottom: 14px; }
.auth-field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; }
.auth-error { background: #fdecec; color: #7a1f1e; border: 1px solid #f6c9c8; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.auth-submit { width: 100%; background: var(--ink); color: #fff; border: none; border-radius: 8px; padding: 12px; font-weight: 700; cursor: pointer; margin-top: 6px; }
.auth-footer { text-align: center; font-size: 13px; margin-top: 16px; color: var(--text-muted); }

/* MOBILE NAV (hamburger + off-canvas sidebar) - hidden by default, shown ≤768px */
.hamburger-btn { display: none; }
.topbar-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.sidebar-overlay { display: none; }

@media (max-width: 1100px) {
    .app-shell { grid-template-columns: 220px 1fr; }
    .cart-panel {
        /* Checkout (cart review + Confirm & Pay) must stay reachable below 1100px - stack it
           below the main content instead of hiding it. grid-column:1/-1 forces CSS Grid's
           auto-placement algorithm to bump it onto a new full-width row, since it can't fit
           in row 1 alongside the sidebar+main-column tracks. No JS/markup needed for this. */
        display: flex;
        grid-column: 1 / -1;
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

@media (max-width: 768px) {
    .app-shell { grid-template-columns: 1fr; }

    .hamburger-btn {
        display: inline-flex; align-items: center; justify-content: center;
        width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 8px;
        background: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0;
    }
    .account-chip-text { display: none; } /* avatar-only on mobile - saves topbar space */

    .sidebar {
        position: fixed; top: 0; left: 0; width: 260px; height: 100vh;
        z-index: 1000; overflow-y: auto; transform: translateX(-100%);
        transition: transform .2s ease; box-shadow: 2px 0 12px rgba(0,0,0,.25);
    }
    .app-shell.nav-open .sidebar { transform: translateX(0); }

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

    /* Grids - stack to a single (or 2-up for short stat tiles) column */
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .dash-columns { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .row-between { flex-wrap: wrap; gap: 8px; }
    .inline-panel input[type=file] { max-width: 100%; }
    .page-header-row { flex-direction: column; align-items: flex-start; gap: 10px; }

    /* Bigger tap targets for the small action buttons (Remind/Edit/Delete, Make Default, Add
       to Cart, etc.) - desktop's compact .btn-sm (~26-28px tall) is fine for a mouse, but
       under Apple's/Google's ~44px minimum tap-target guidance for touch. Mobile-only, so
       desktop density is untouched. min-width keeps icon-only buttons (the trash/Delete icon)
       from staying narrow even with taller padding. */
    .btn-sm { min-height: 44px; min-width: 44px; padding: 10px 14px; font-size: 13px; }

    /* Data tables (Drivers, Billing invoice history) - card-style rows instead of a wide
       table. Requires each <td> to carry a data-label attribute (see Drivers.aspx/Billing.aspx). */
    .data-table thead { display: none; }
    .data-table tr { display: block; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 8px; }
    .data-table td { display: block; border-bottom: none; padding: 6px 4px; }
    .data-table td::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 700; color: var(--text-muted); }
    .data-table td.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; }

    /* Drivers table only: Phone/Email/Enrolled/Expiration move into a tap-to-expand disclosure
       instead of being shown as separate stacked fields - swap which cell is visible. */
    .data-table td.desktop-only-cell { display: none; }
    .data-table td.mobile-only-cell { display: block; padding-top: 2px; }

    .mobile-detail-toggle summary {
        cursor: pointer; font-size: 12px; font-weight: 700; color: var(--accent-dark);
        list-style: none;
    }
    .mobile-detail-toggle summary::-webkit-details-marker { display: none; }
    .mobile-detail-toggle summary::after { content: ' \25be'; }
    .mobile-detail-toggle[open] summary::after { content: ' \25b4'; }
    .mobile-detail-body { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 13px; }
    .mobile-detail-body > div { padding: 3px 0; }
    .mobile-detail-label { display: inline-block; min-width: 70px; font-weight: 700; color: var(--text-muted); font-size: 11px; text-transform: uppercase; }
}
