/*
 * Guide Wave admin portal. English, LTR. Uses logical properties so no RTL-specific rules.
 *
 * Brand palette, shared with the PWA and the Android app: every shade derives from the
 * logo's #125CFD. See /shared/brand/README.md.
 */

:root {
    --primary: #125CFD;
    --primary-dark: #0E45BE;
    /* The sidebar is on screen for a whole shift — raw #125CFD over that area is fatiguing. */
    --deep: #0A338B;
    --secondary: #719DFE;
    --accent: #FF8C42;

    --bg: #f4f6f8;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1a2733;
    --text-muted: #64748b;

    --ok: #0f766e;
    --ok-bg: #ccfbf1;
    --warn: #92400e;
    --warn-bg: #fef3c7;
    --danger: #991b1b;
    --danger-bg: #fee2e2;
    --neutral: #475569;
    --neutral-bg: #e2e8f0;

    --radius: 10px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
    --sidebar-width: 250px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

button, input, select { font-family: inherit; font-size: inherit; }

/* ---------------- Login ---------------- */

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(160deg, var(--primary) 0%, var(--deep) 100%);
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(7, 43, 65, 0.25);
}

.login-card h1 { font-size: 1.5rem; color: var(--primary); margin-bottom: 0.25rem; }
.login-card .sub { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.75rem; }

/* Blue lockup — the card is white; the sidebar uses the white one. */
.login-logo { display: block; width: 190px; height: auto; margin: 0 auto 0.5rem; }

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; }
.field input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}
.field input:focus { outline: 2px solid var(--secondary); outline-offset: 1px; border-color: transparent; }

/* ---------------- Buttons ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; font-weight: 600; }
.btn-secondary { background: var(--primary-dark); }
.btn-secondary:hover { background: var(--deep); }
.btn-accent { background: var(--accent); color: #4a2409; }
.btn-accent:hover { background: #f07a2c; }
.btn-danger { background: #b91c1c; }
.btn-danger:hover { background: #991b1b; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }

/* ---------------- Layout ---------------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--deep);
    color: #C8D8FF;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
}

.brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.brand strong { color: #fff; font-size: 1.05rem; display: block; }
.brand span { font-size: 0.75rem; color: #8FA9F0; }

/* White lockup — the sidebar is deep blue. */
.brand .brand-logo { display: block; width: 150px; height: auto; margin-bottom: 0.35rem; }

.nav { padding: 0.75rem; flex: 1; overflow-y: auto; }
.nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    color: #C8D8FF;
    text-decoration: none;
    font-size: 0.92rem;
    margin-bottom: 0.15rem;
}
.nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav .ico { width: 18px; text-align: center; opacity: 0.9; }

.sidebar-foot {
    padding: 0.9rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.85rem;
}
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot .roles { color: #8FA9F0; font-size: 0.75rem; margin-bottom: 0.6rem; }

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

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.topbar h1 { font-size: 1.2rem; color: var(--primary); }
.topbar .hint { font-size: 0.8rem; color: var(--text-muted); }

.content { padding: 1.5rem; flex: 1; }

/* ---------------- Cards & stats ---------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1.25rem;
}
.card-head {
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.card-head h2 { font-size: 1rem; color: var(--primary); }
.card-body { padding: 1.1rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--secondary);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
}
.stat.is-warn { border-inline-start-color: var(--accent); }
.stat.is-ok { border-inline-start-color: var(--ok); }
.stat .label { font-size: 0.8rem; color: var(--text-muted); }
.stat .value { font-size: 1.75rem; font-weight: 700; color: var(--primary); line-height: 1.2; }

/* ---------------- Tables ---------------- */

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
    text-align: start;
    padding: 0.7rem 1.1rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 700;
    white-space: nowrap;
}
tbody td { padding: 0.75rem 1.1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
td .actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.85em; }

/* ---------------- Badges ---------------- */

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }

.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip {
    background: #eef2f6;
    border: 1px solid var(--border);
    color: var(--neutral);
    border-radius: 6px;
    padding: 0.1rem 0.45rem;
    font-size: 0.72rem;
    font-family: ui-monospace, Consolas, monospace;
}
.chip-on { background: #e0f2fe; border-color: #7dd3fc; color: #075985; }

/* ---------------- Filters, states, toast ---------------- */

.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.filters select, .filters input {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.empty, .loading { padding: 2.5rem 1rem; text-align: center; color: var(--text-muted); }
.spinner {
    width: 26px; height: 26px; margin: 0 auto 0.6rem;
    border: 3px solid var(--border);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert { padding: 0.7rem 0.9rem; border-radius: var(--radius); font-size: 0.88rem; margin-bottom: 1rem; }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-info { background: #e0f2fe; color: #075985; }

.toast {
    position: fixed;
    inset-block-end: 1.25rem;
    inset-inline-start: 1.25rem;
    background: var(--primary);
    color: #fff;
    padding: 0.7rem 1.1rem;
    border-radius: var(--radius);
    box-shadow: 0 8px 20px rgba(7, 43, 65, 0.3);
    z-index: 50;
    font-size: 0.9rem;
    animation: rise 0.2s ease-out;
}
.toast.is-error { background: #b91c1c; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------------- Modal ---------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 25, 38, 0.55);
    display: grid;
    place-items: center;
    padding: 1rem;
    z-index: 40;
}
.modal {
    background: var(--surface);
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 48px rgba(7, 43, 65, 0.3);
}
.modal-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 1.05rem; color: var(--primary); }
.modal-body { padding: 1.25rem; }
.modal-foot { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: 0.5rem; justify-content: flex-start; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.4rem; }
.perm-grid label {
    display: flex; align-items: center; gap: 0.45rem;
    font-size: 0.82rem; padding: 0.3rem 0.4rem; border-radius: 6px; cursor: pointer;
}
.perm-grid label:hover { background: var(--bg); }
.perm-grid code { font-family: ui-monospace, Consolas, monospace; font-size: 0.78rem; }

/* ---------------- Responsive ---------------- */

@media (max-width: 860px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
    .nav { display: flex; flex-wrap: wrap; gap: 0.25rem; }
    .nav a { margin: 0; }
    .content { padding: 1rem; }
}

/* ---------------- company portal additions ---------------- */

.muted { color: var(--text-muted); }

/* consumption meter */
.meter {
    height: 12px;
    background: var(--neutral-bg);
    border-radius: 999px;
    overflow: hidden;
}
.meter-fill {
    height: 100%;
    background: var(--ok);
    border-radius: 999px;
    transition: width .3s ease;
}
.meter-fill.is-warn { background: var(--warn); }
.meter-fill.is-danger { background: var(--danger); }

/* plan cards */
.plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}
.plan-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: .6rem;
}
.plan-card.is-current {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary) inset;
}
.plan-head { display: flex; justify-content: space-between; align-items: center; }
.plan-price { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.plan-feats { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .35rem; font-size: .86rem; color: var(--text-muted); }
.plan-feats li::before { content: '✓ '; color: var(--ok); font-weight: 700; }
.plan-card .btn { margin-top: auto; }

/* daily bar chart */
.chart-scroll { overflow-x: auto; }
.bar-chart { width: 100%; height: auto; }
.bar-chart .bar { fill: var(--primary); }
.bar-chart .bar-empty { fill: var(--neutral-bg); }
.bar-chart .bar-lbl { fill: var(--text-muted); font-size: 10px; text-anchor: middle; }
.bar-chart .axis { stroke: var(--border); stroke-width: 1; }

/* recorded route map (self-contained SVG) */
.route-meta { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-bottom: .7rem; font-size: .9rem; }
.route-map { width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.route-bg { fill: var(--bg); }
.route-line { fill: none; stroke: var(--primary); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.route-dot { fill: var(--primary); opacity: .5; }
.route-start { fill: var(--ok); stroke: #fff; stroke-width: 2; }
.route-end { fill: var(--danger); stroke: #fff; stroke-width: 2; }
.route-legend { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-top: .6rem; font-size: .84rem; color: var(--text-muted); }
.route-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: .3rem; }
.route-legend .dot-start { background: var(--ok); }
.route-legend .dot-end { background: var(--danger); }

/* pager */
.pager { display: flex; align-items: center; gap: 1rem; justify-content: center; }
