/* ══════════════════════════════════════════════════════════════════════
   Fleet-Eye Design System
   Shared tokens + base components for dashboard.html and share.html.
   Clean, neutral SaaS aesthetic — light surfaces, restrained shadows,
   one accent color, no emoji/gradients-as-decoration.
   ══════════════════════════════════════════════════════════════════════ */

:root {
    /* Surfaces */
    --bg: #eef1f7;
    --surface: #ffffff;
    --surface-2: #f4f6fa;
    --surface-sunken: #e9edf4;
    --overlay: rgba(15, 23, 42, 0.55);

    /* Borders */
    --border: #d3dae4;
    --border-strong: #97a3b6;

    /* Text */
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-on-accent: #ffffff;

    /* Accent (primary brand action color) */
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #eef2ff;
    --accent-soft-border: #c7d2fe;
    --accent-text: #4338ca;

    /* Semantic */
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --success-soft-border: #bbf7d0;
    --success-text: #15803d;

    --warning: #d97706;
    --warning-soft: #fffbeb;
    --warning-soft-border: #fde68a;
    --warning-text: #b45309;

    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --danger-soft-border: #fecaca;
    --danger-text: #b91c1c;

    --info: #0284c7;
    --info-soft: #f0f9ff;
    --info-soft-border: #bae6fd;
    --info-text: #0369a1;

    --purple: #7c3aed;
    --purple-soft: #f5f3ff;
    --purple-soft-border: #ddd6fe;
    --purple-text: #6d28d9;

    /* Status — offline is red: a vehicle that stopped reporting is a
       problem to notice, not a neutral state to fade out. */
    --status-online: #16a34a;
    --status-connecting: #d97706;
    --status-offline: #dc2626;
    --status-offline-soft: var(--danger-soft);
    --status-offline-soft-border: var(--danger-soft-border);
    --status-offline-text: var(--danger-text);

    /* Navigation chrome follows the active theme */
    --navbar-bg: #ffffff;
    --navbar-border: #d3dae4;
    --navbar-text: #0f172a;
    --navbar-text-muted: #64748b;

    /* Map surfaces */
    --map-bg: #e9edf4;
    --marker-label-bg: #ffffff;
    --marker-label-text: #0f172a;

    /* Geometry */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.09);
    --shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
    --shadow-lg: 0 24px 64px rgba(15, 23, 42, 0.22);

    /* Motion */
    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

    /* Font */
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SFMono-Regular", Menlo, Monaco, Consolas, monospace;

    color-scheme: light;
}

/* ══════════════════════════════════════════════════════════════════════
   Dark theme
   Everything above is expressed as tokens, so the dark theme is a
   re-declaration of those tokens rather than a parallel stylesheet.
   Applied via <html data-theme="dark">; `data-theme="light"` pins light
   so the OS preference below can't override an explicit choice.
   ══════════════════════════════════════════════════════════════════════ */
:root[data-theme="dark"] {
    --bg: #0a0f1a;
    --surface: #131c2e;
    --surface-2: #182236;
    --surface-sunken: #1e2940;
    --overlay: rgba(2, 6, 23, 0.72);

    --border: #29344a;
    --border-strong: #414f6a;

    --text: #f1f5f9;
    --text-secondary: #c3cddc;
    --text-muted: #8d9bb0;
    --text-on-accent: #ffffff;

    --accent: #6366f1;
    --accent-hover: #7c7ff5;
    --accent-soft: rgba(99, 102, 241, 0.18);
    --accent-soft-border: rgba(129, 140, 248, 0.42);
    --accent-text: #b3bcff;

    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.15);
    --success-soft-border: rgba(74, 222, 128, 0.34);
    --success-text: #6ee7a0;

    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, 0.15);
    --warning-soft-border: rgba(251, 191, 36, 0.34);
    --warning-text: #fbbf24;

    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, 0.16);
    --danger-soft-border: rgba(248, 113, 113, 0.36);
    --danger-text: #fca5a5;

    --info: #38bdf8;
    --info-soft: rgba(56, 189, 248, 0.15);
    --info-soft-border: rgba(125, 211, 252, 0.34);
    --info-text: #7dd3fc;

    --purple: #a78bfa;
    --purple-soft: rgba(167, 139, 250, 0.16);
    --purple-soft-border: rgba(196, 181, 253, 0.34);
    --purple-text: #c4b5fd;

    --status-online: #22c55e;
    --status-connecting: #f59e0b;
    --status-offline: #ef4444;

    /* The navbar lifts off the page instead of matching it */
    --navbar-bg: #131c2e;
    --navbar-border: #29344a;
    --navbar-text: #f8fafc;
    --navbar-text-muted: #8d9bb0;

    --map-bg: #0a0f1a;
    --marker-label-bg: #1e2940;
    --marker-label-text: #f1f5f9;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.62);

    color-scheme: dark;
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

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

/* Thin, unobtrusive scrollbars everywhere */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    /* .btn is used on <a> as well as <button> (the dashboard's nav links to
       Places and Share links), so the anchor underline has to go. */
    text-decoration: none;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.btn:hover { border-color: var(--text-muted); background: var(--surface-2); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--surface); color: var(--text-secondary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-soft-border); }
.btn-danger:hover { background: var(--danger); color: #ffffff; border-color: var(--danger); }

.btn-accent { background: var(--info-soft); color: var(--info-text); border-color: var(--info-soft-border); }
.btn-accent:hover { background: var(--info); color: #ffffff; border-color: var(--info); }

.btn-success { background: var(--success-soft); color: var(--success-text); border-color: var(--success-soft-border); }
.btn-success:hover { background: var(--success); color: #ffffff; border-color: var(--success); }

.btn-warning { background: var(--warning-soft); color: var(--warning-text); border-color: var(--warning-soft-border); }
.btn-warning:hover { background: var(--warning); color: #ffffff; border-color: var(--warning); }

.btn-purple { background: var(--purple-soft); color: var(--purple-text); border-color: var(--purple-soft-border); }
.btn-purple:hover { background: var(--purple); color: #ffffff; border-color: var(--purple); }

.btn-sm { min-height: 30px; padding: 5px 10px; font-size: 12px; border-radius: var(--radius-sm); }

/* ── Forms ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea,
.search-box,
.custom-select {
    width: 100%;
    min-height: 40px;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.form-group input::placeholder,
.search-box::placeholder { color: var(--text-muted); }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.search-box:focus,
.custom-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.custom-select {
    padding-right: 34px;
    background-image: url('data:image/svg+xml;charset=UTF-8,%3csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%2394a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"%3e%3cpolyline points="6 9 12 15 18 9"%3e%3c/polyline%3e%3c/svg%3e');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* ── Banners ───────────────────────────────────────────────────────── */
.error-message, .success-message {
    display: none;
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13.5px;
    line-height: 1.45;
}

.error-message { background: var(--danger-soft); color: var(--danger-text); border: 1px solid var(--danger-soft-border); }
.success-message { background: var(--success-soft); color: var(--success-text); border: 1px solid var(--success-soft-border); }

.info-box {
    background: var(--info-soft);
    border: 1px solid var(--info-soft-border);
    border-radius: var(--radius-sm);
    padding: 12px 13px;
    margin-top: 12px;
}

.info-box p { font-size: 12px; color: var(--info-text); line-height: 1.55; }

.section-description { font-size: 12.5px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.55; }

/* ── Spinner ───────────────────────────────────────────────────────── */
.spinner {
    width: 30px;
    height: 30px;
    margin: 0 auto 12px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: fe-spin 0.75s linear infinite;
}

@keyframes fe-spin { to { transform: rotate(360deg); } }
@keyframes fe-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fe-slide-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.loading { display: none; text-align: center; padding: 40px; color: var(--text-muted); }

/* ── Modal chrome ──────────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--overlay);
    backdrop-filter: blur(4px);
    animation: fe-fade-in 0.15s var(--ease);
    overflow: auto;
}

.modal-content {
    background: var(--surface);
    margin: 32px auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 92%;
    max-width: 560px;
    max-height: calc(100vh - 64px);
    box-shadow: var(--shadow-lg);
    animation: fe-slide-up 0.2s var(--ease);
    display: flex;
    flex-direction: column;
}

.fe-visually-hidden {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Dialog widths — one scale instead of per-modal inline max-widths */
.modal-content.modal-sm { max-width: 440px; }
.modal-content.modal-md { max-width: 560px; }
.modal-content.modal-lg { max-width: 680px; }
.modal-content.modal-xl { max-width: 900px; }

.label-optional { color: var(--text-muted); font-weight: 400; }

.history-modal { background: rgba(15, 23, 42, 0.7); }
.history-modal .modal-content {
    margin: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    animation: none;
}

.modal-header {
    padding: 18px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h2 { font-size: 1.05rem; font-weight: 700; color: var(--text); letter-spacing: -0.2px; }

.close {
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.close:hover { color: var(--text); background: var(--surface-sunken); }

.modal-body { padding: 22px; overflow-y: auto; flex: 1; min-height: 0; color: var(--text-secondary); }

.modal-footer {
    padding: 15px 22px;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    flex-shrink: 0;
}

/* ── Collapsible sections ──────────────────────────────────────────── */
.collapsible-section { margin-top: 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

.collapsible-header {
    background: var(--surface-2);
    padding: 13px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: background 0.15s var(--ease);
}

.collapsible-header:hover { background: var(--surface-sunken); }
.collapsible-header h3 { font-size: 13.5px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.collapsible-header h3 svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }

.collapsible-arrow { color: var(--text-muted); transition: transform 0.2s var(--ease); display: inline-flex; }
.collapsible-arrow.open { transform: rotate(90deg); }

.collapsible-content { max-height: 0; overflow: hidden; transition: max-height 0.3s var(--ease); }
.collapsible-content.open { max-height: 800px; transition: max-height 0.5s var(--ease); }
.collapsible-body { padding: 18px 15px; background: var(--surface); }

/* ── Badges / pills ────────────────────────────────────────────────── */
.role-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.3px;
    background: var(--accent-soft);
    color: var(--accent-text);
    border: 1px solid var(--accent-soft-border);
}

.info-badge { display: inline-block; padding: 2px 9px; border-radius: var(--radius-sm); font-size: 11px; font-weight: 600; }
.badge-udp { background: var(--info-soft); color: var(--info-text); }
.badge-tcp { background: var(--success-soft); color: var(--success-text); }
.badge-offline { background: var(--surface-sunken); color: var(--text-muted); }

.empty-state {
    padding: 28px 18px;
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    font-size: 13.5px;
}

/* ══════════════════════════════════════════════════════════════════════
   Modal building blocks
   Shared pieces the dialogs are assembled from, so their markup carries
   classes instead of one-off inline styles.
   ══════════════════════════════════════════════════════════════════════ */

/* Lead-in paragraph at the top of a dialog body */
.modal-intro {
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Prev / range / next strip above a chart */
.modal-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.modal-toolbar-range {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    text-align: center;
    min-width: 0;
}

/* Titled chart container */
.chart-card { margin-top: 16px; }
.chart-card-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.chart-card canvas { max-width: 100%; }

/* "Nothing to show" state inside a dialog */
.modal-empty {
    padding: 44px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13.5px;
}

/* Tinted checkbox row (feature toggles in the device form) */
.check-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.check-row input[type="checkbox"] {
    width: 16px; height: 16px;
    margin-top: 1px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--accent);
}
.check-row label {
    margin: 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.check-row .check-hint {
    display: block;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.45;
}
.check-row-success { background: var(--success-soft); border-color: var(--success-soft-border); }
.check-row-success input[type="checkbox"] { accent-color: var(--success); }
.check-row-warning { background: var(--warning-soft); border-color: var(--warning-soft-border); }
.check-row-warning input[type="checkbox"] { accent-color: var(--warning); }
.check-row-info { background: var(--info-soft); border-color: var(--info-soft-border); }
.check-row-info input[type="checkbox"] { accent-color: var(--info); }

/* Two fields side by side, stacking on narrow screens */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

.label-req { color: var(--danger); font-weight: 700; }

/* Field label inside the wiring / fuel sub-forms */
.wiring-label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Button + status text on one line */
.inline-action { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.inline-action-status { font-size: 12px; color: var(--text-muted); }
.inline-action-status.is-ok { color: var(--success-text); font-weight: 600; }
.inline-action-status.is-warn { color: var(--warning-text); font-weight: 600; }
.inline-action-status.is-err { color: var(--danger-text); font-weight: 600; }

/* Right-aligned unit picker above the range table */
.unit-row { display: flex; justify-content: flex-end; align-items: center; gap: 9px; margin-bottom: 10px; }
.unit-row label { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.unit-row select { width: auto; min-width: 130px; }

/* Piecewise fuel range editor */
.range-head,
.fuel-range-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 30px;
    gap: 6px;
    align-items: center;
}
.range-head {
    margin-bottom: 6px;
    padding: 0 2px;
}
.range-head span {
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-muted);
}
.fuel-range-row { margin-bottom: 6px; }
.fuel-range-row input {
    width: 100%;
    min-height: 34px;
    padding: 6px 8px;
    font-size: 13px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    outline: none;
    font-variant-numeric: tabular-nums;
}
.fuel-range-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.range-remove {
    display: grid; place-items: center;
    width: 30px; height: 30px;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: transparent; color: var(--text-muted); cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.range-remove:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft-border); }

.btn-add-range {
    display: flex; align-items: center; justify-content: center; gap: 7px;
    width: 100%; margin-top: 4px; padding: 9px;
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.btn-add-range:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }

/* Live terminal readings inside the wiring section */
.wiring-live { margin-bottom: 18px; }
.wiring-live-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sensor-value-sm { font-size: 15px !important; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); display: inline-block; flex-shrink: 0; }
.live-age { font-size: 11px; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--text-muted); }

/* Helper text under a field */
.field-hint {
    display: block;
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 5px;
    line-height: 1.45;
}

/* Small-caps section heading inside a dialog body */
.modal-subhead {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Read-only derived values (fuel API panel) */
.derived-panel {
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}
.derived-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.derived-grid .k {
    display: block;
    font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
    text-transform: uppercase; color: var(--text-muted);
}
.derived-grid .v {
    display: block; font-size: 17px; font-weight: 700; color: var(--text);
    font-variant-numeric: tabular-nums; margin-top: 2px;
}
.derived-grid .v-sm { font-size: 13px; }
.derived-divider { height: 1px; background: var(--border); margin: 12px 0; }
.derived-basis { font-size: 11px; color: var(--text-muted); margin-top: 10px; line-height: 1.45; }

/* Scrollable pick list (devices to share) */
.pick-list {
    max-height: 190px;
    overflow-y: auto;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 4px;
}
.form-group .pick-row {
    display: flex; align-items: center; gap: 9px;
    padding: 7px 8px; border-radius: 5px;
    margin: 0;
    font-size: 13px; color: var(--text); cursor: pointer;
}
.pick-row:hover { background: var(--surface-sunken); }
.form-group .pick-row input[type="checkbox"] {
    width: 16px; height: 16px; min-height: 0;
    margin: 0; padding: 0;
    cursor: pointer; accent-color: var(--accent); flex: 0 0 16px;
}
.pick-row > span { min-width: 0; line-height: 1.35; }
.pick-row .pick-sub { color: var(--text-muted); font-size: 12px; }

/* Copyable link result */
.link-result {
    padding: 14px;
    background: var(--success-soft);
    border: 1px solid var(--success-soft-border);
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
}
.link-result-title {
    display: flex; align-items: center; gap: 7px;
    font-size: 12.5px; font-weight: 700; color: var(--success-text); margin-bottom: 9px;
}
.link-result-row { display: flex; gap: 8px; }
.link-result-row input {
    flex: 1; min-width: 0;
    font-size: 12.5px; padding: 8px 10px;
    border: 1px solid var(--success-soft-border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font-family: var(--font-mono);
}

/* Existing share links */
.share-item {
    padding: 11px 13px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-muted);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.share-item-active { border-left-color: var(--success); }
.share-item-revoked { border-left-color: var(--danger); }
.share-item-expired { border-left-color: var(--text-muted); }

.share-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.share-item-info { min-width: 0; }
.share-item-title { font-size: 13px; font-weight: 700; color: var(--text); }
.share-item-status {
    display: inline-block; margin-left: 7px;
    font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
    padding: 2px 7px; border-radius: var(--radius-pill);
    background: var(--surface-sunken); color: var(--text-muted);
}
.share-item-active .share-item-status { background: var(--success-soft); color: var(--success-text); }
.share-item-revoked .share-item-status { background: var(--danger-soft); color: var(--danger-text); }
.share-item-devices { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.share-item-expiry { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.share-item-link { display: flex; gap: 6px; margin-top: 9px; }
.share-item-link input {
    flex: 1; min-width: 0;
    font-size: 12px; padding: 6px 9px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* ── App shell (standalone signed-in pages: Places, Share links) ──── */
.app-topbar {
    min-height: 72px;
    padding: 12px 22px;
    background: var(--navbar-bg);
    color: var(--navbar-text);
    border-bottom: 1px solid var(--navbar-border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 18px; flex-wrap: wrap;
}
.app-topbar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.app-back {
    width: 34px; height: 34px; flex: 0 0 auto;
    display: grid; place-items: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--navbar-border);
    color: var(--navbar-text-muted);
    text-decoration: none;
}
.app-back:hover { color: var(--navbar-text); background: var(--navbar-hover, rgba(148,163,184,.14)); }
.app-back svg { width: 17px; height: 17px; }

.app-brand-mark {
    width: 40px; height: 40px; flex: 0 0 auto;
    display: grid; place-items: center;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    border: 1px solid var(--accent-soft-border);
    color: var(--accent);
}
.app-brand-mark svg { width: 22px; height: 22px; }

.app-heading { min-width: 0; }
.app-heading h1 {
    font-size: 1.05rem; font-weight: 750; color: var(--navbar-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-subtitle { margin-top: 2px; font-size: 11.5px; color: var(--navbar-text-muted); }

.app-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.app-nav-link {
    padding: 7px 13px; border-radius: var(--radius-pill);
    font-size: 13px; font-weight: 600; text-decoration: none;
    color: var(--navbar-text-muted);
    border: 1px solid transparent;
}
.app-nav-link:hover { color: var(--navbar-text); background: var(--navbar-hover, rgba(148,163,184,.14)); }
.app-nav-link.is-active {
    color: var(--accent-text);
    background: var(--accent-soft);
    border-color: var(--accent-soft-border);
}

.app-topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.app-user { color: var(--navbar-text); font-size: 13px; font-weight: 600; }

/* Page body under the top bar */
.app-page { max-width: 1120px; margin: 0 auto; padding: 24px 22px 60px; }
.app-page-intro { font-size: 13.5px; color: var(--text-secondary); line-height: 1.55; margin-bottom: 22px; max-width: 70ch; }

.app-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 22px;
}
.app-card-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.app-card-sub { font-size: 12.5px; color: var(--text-muted); margin-bottom: 16px; }

/* Two-column split: form on the left, live map on the right */
.app-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 22px; align-items: start; }

@media (max-width: 900px) {
    .app-split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
    .app-topbar { padding: 10px 14px; gap: 10px; }
    .app-topbar-brand { flex: 1 1 100%; }
    .app-nav { flex: 1 1 100%; }
    .app-nav-link { flex: 1 1 auto; text-align: center; }
    .app-topbar-actions { flex: 1 1 100%; }
    .app-page { padding: 16px 14px 48px; }
    .app-card { padding: 15px; }
}

/* ── Geofence picker (search + map + radius) ──────────────────────── */
.geofence-search { position: relative; }

/* Nominatim matches, floated over the map below so the list never pushes
   the map out of view while the user is scanning it */
.geofence-results {
    display: none;
    position: absolute;
    top: calc(100% + 4px); left: 0; right: 0;
    z-index: 1200;
    max-height: 260px; overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}
.geofence-results.open { display: block; }

.geofence-result {
    padding: 9px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.geofence-result:last-child { border-bottom: none; }
.geofence-result:hover,
.geofence-result.active { background: var(--surface-sunken); }
.geofence-result-name { font-size: 13px; font-weight: 600; color: var(--text); }
.geofence-result-full {
    font-size: 11.5px; color: var(--text-muted); margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.geofence-results-msg { padding: 11px 12px; font-size: 12.5px; color: var(--text-muted); }

.geofence-map-wrap {
    position: relative;
    height: 300px;
    margin-bottom: 18px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
#geofencePickMap { width: 100%; height: 100%; cursor: crosshair; }

.geofence-map-hint {
    position: absolute; left: 10px; bottom: 10px; z-index: 500;
    padding: 5px 10px; border-radius: var(--radius-pill);
    background: var(--surface); border: 1px solid var(--border-strong);
    font-size: 11.5px; color: var(--text-secondary);
    pointer-events: none;
    box-shadow: var(--shadow);
}

.geofence-radius-slider { width: 100%; accent-color: var(--accent); margin: 4px 0 8px; }
.geofence-radius-row { display: flex; align-items: center; gap: 10px; }
.geofence-radius-row input[type="number"] { width: 110px; flex-shrink: 0; }
.geofence-radius-row .field-hint { margin: 0; }

.geofence-coords {
    font-family: var(--font-mono); font-size: 11.5px;
    color: var(--text-muted);
    padding: 7px 10px; margin-bottom: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

@media (max-width: 640px) {
    .geofence-map-wrap { height: 240px; }
    .geofence-radius-row { flex-direction: column; align-items: stretch; }
    .geofence-radius-row input[type="number"] { width: 100%; }
}

/* ── Geofences (Places & Visits) ──────────────────────────────────── */
.geofence-item {
    padding: 11px 13px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.geofence-item-off { border-left-color: var(--text-muted); opacity: 0.72; }

.geofence-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.geofence-info { min-width: 0; }
.geofence-name { font-size: 13px; font-weight: 700; color: var(--text); }
.geofence-badge {
    display: inline-block; margin-left: 7px;
    font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
    padding: 2px 7px; border-radius: var(--radius-pill);
    background: var(--surface-sunken); color: var(--text-muted);
}
.geofence-badge-inside { background: var(--success-soft); color: var(--success-text); }
.geofence-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; font-family: var(--font-mono); }
.geofence-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* The counts that answer "how many times has anyone been here" */
.geofence-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.geofence-stat {
    flex: 1 1 90px; min-width: 0;
    padding: 7px 9px; border-radius: var(--radius-sm);
    background: var(--surface); border: 1px solid var(--border);
}
.geofence-stat-v { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.2; }
.geofence-stat-k {
    font-size: 10px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase;
    color: var(--text-muted); margin-top: 2px;
}

/* Per-vehicle breakdown, revealed by "Visits" */
.geofence-detail { margin-top: 11px; padding-top: 10px; border-top: 1px dashed var(--border); }
.geofence-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.geofence-table th {
    text-align: left; padding: 5px 7px;
    font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
    color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.geofence-table td { padding: 5px 7px; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
.geofence-table td:first-child { color: var(--text); font-weight: 600; }
.geofence-table .num { text-align: right; font-family: var(--font-mono); }
.geofence-detail-title {
    font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
    color: var(--text-muted); margin: 12px 0 6px;
}
.geofence-log-wrap { max-height: 220px; overflow-y: auto; }

/* Fence label drawn on the map circle */
.geofence-map-label {
    background: none; border: none;
    font-size: 11px; font-weight: 700; color: var(--text);
    text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface), 0 0 3px var(--surface);
    white-space: nowrap; pointer-events: none;
}

@media (max-width: 640px) {
    .geofence-head { flex-direction: column; }
    .geofence-actions { width: 100%; }
    .geofence-actions .btn { flex: 1; }
}

/* ── Places activity workspace ───────────────────────────────────── */
.places-page { width: 100%; max-width: none; min-height: 100vh; padding: 0; background: var(--surface); }
.places-app-shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }
.places-content { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; background: var(--surface); }
.places-hero {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 24px;
    min-height: 104px; margin: 0; padding: 22px 30px; border-bottom: 1px solid var(--border);
}
.places-hero h2, .place-manager-head h2 {
    font-size: clamp(24px, 2.4vw, 34px); line-height: 1.1; letter-spacing: -0.03em;
    color: var(--text); margin-bottom: 7px;
}
.places-hero p, .place-manager-head p { color: var(--text-secondary); font-size: 13.5px; line-height: 1.5; }
.places-eyebrow {
    margin-bottom: 8px; color: var(--accent-text); font-size: 10.5px; font-weight: 800;
    letter-spacing: .12em; text-transform: uppercase;
}

.activity-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    padding: 11px 30px; margin: 0; background: var(--surface); border: 0; border-bottom: 1px solid var(--border);
    border-radius: 0; box-shadow: none;
}
.activity-presets { display: flex; gap: 3px; }
.activity-preset {
    min-height: 34px; padding: 6px 12px; border: 0; border-radius: var(--radius-sm);
    background: transparent; color: var(--text-muted); font-size: 12.5px; font-weight: 650; cursor: pointer;
}
.activity-preset:hover { color: var(--text); background: var(--surface-2); }
.activity-preset.is-active { color: var(--accent-text); background: var(--accent-soft); }
.activity-range { display: flex; align-items: center; gap: 8px; }
.activity-range label {
    display: flex; align-items: center; gap: 7px; color: var(--text-muted);
    font-size: 10.5px; font-weight: 750; text-transform: uppercase; letter-spacing: .04em;
}
.activity-range input { min-height: 34px; padding: 6px 9px; font-size: 12px; }
.activity-range-arrow { color: var(--text-muted); }

.activity-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.activity-stat {
    display: flex; align-items: center; gap: 12px; min-width: 0; padding: 15px 16px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.activity-stat-primary { border-color: var(--accent-soft-border); background: var(--accent-soft); }
.activity-stat-icon {
    display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto;
    color: var(--accent-text); border-radius: 9px; background: var(--surface);
}
.activity-stat-icon svg { width: 17px; height: 17px; }
.activity-stat div { min-width: 0; }
.activity-stat strong {
    display: block; color: var(--text); font-size: 21px; line-height: 1.05;
    letter-spacing: -0.025em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.activity-stat span:last-child {
    display: block; margin-top: 4px; color: var(--text-muted); font-size: 10.5px;
    font-weight: 700; text-transform: uppercase; letter-spacing: .045em; white-space: nowrap;
}

.activity-workspace { display: grid; grid-template-columns: minmax(260px, .72fr) minmax(0, 1.8fr); gap: 14px; align-items: start; }
.activity-groups-card, .activity-events-card, .managed-places, .place-manager {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.activity-groups-card { overflow: hidden; }
.activity-events-card { min-width: 0; overflow: hidden; }
.activity-section-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    padding: 16px 17px 13px;
}
.activity-section-head h3 { color: var(--text); font-size: 14px; line-height: 1.35; }
.activity-section-head p { margin-top: 3px; color: var(--text-muted); font-size: 11.5px; }
.activity-section-head select, .activity-sort-row select { min-height: 32px; padding: 5px 27px 5px 9px; font-size: 11.5px; }
.activity-count-badge {
    display: inline-grid; place-items: center; min-width: 24px; min-height: 22px; padding: 2px 7px;
    border-radius: var(--radius-pill); background: var(--surface-sunken); color: var(--text-secondary);
    font-size: 11px; font-weight: 750; vertical-align: 1px;
}
.activity-sort-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 9px 17px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
    background: var(--surface-2); color: var(--text-muted); font-size: 11px; font-weight: 700;
}
.activity-groups { max-height: 580px; overflow-y: auto; }
.activity-group {
    display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center;
    width: 100%; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--border);
    background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.activity-group:last-child { border-bottom: 0; }
.activity-group:hover { background: var(--surface-2); }
.activity-group.is-active { background: var(--accent-soft); box-shadow: inset 3px 0 var(--accent); }
.activity-group-icon {
    display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
    color: var(--accent-text); background: var(--accent-soft);
}
.activity-group.is-active .activity-group-icon { background: var(--surface); }
.activity-group-name { display: block; font-size: 12.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-group-sub { display: block; margin-top: 3px; color: var(--text-muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-group-total { text-align: right; }
.activity-group-total strong { display: block; font-size: 15px; }
.activity-group-total span { display: block; margin-top: 2px; color: var(--text-muted); font-size: 9.5px; text-transform: uppercase; }

.activity-events-head { border-bottom: 1px solid var(--border); }
.activity-events { max-height: 620px; overflow: auto; }
.activity-event {
    display: grid; grid-template-columns: 108px minmax(155px, 1fr) minmax(135px, .85fr) 104px;
    gap: 14px; align-items: center; padding: 13px 17px; border-bottom: 1px solid var(--border);
}
.activity-event:last-child { border-bottom: 0; }
.activity-event:hover { background: var(--surface-2); }
.activity-event-type { display: flex; align-items: center; gap: 8px; font-size: 11.5px; font-weight: 750; }
.activity-event-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--info); box-shadow: 0 0 0 4px var(--info-soft); }
.activity-event.is-departure .activity-event-dot { background: var(--purple); box-shadow: 0 0 0 4px var(--purple-soft); }
.activity-event-main strong, .activity-event-place strong { display: block; color: var(--text); font-size: 12.5px; }
.activity-event-main span, .activity-event-place span { display: block; margin-top: 3px; color: var(--text-muted); font-size: 10.5px; }
.activity-event-time { text-align: right; }
.activity-event-time strong { display: block; color: var(--text); font-family: var(--font-mono); font-size: 11.5px; }
.activity-event-time span { display: block; margin-top: 3px; color: var(--text-muted); font-size: 10px; }
.activity-empty { padding: 52px 24px; color: var(--text-muted); text-align: center; font-size: 13px; line-height: 1.55; }
.activity-empty-icon { margin: 0 auto 12px; color: var(--text-muted); }
.activity-empty-icon svg { width: 28px; height: 28px; }
.activity-limit-note { padding: 9px 17px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 10.5px; background: var(--surface-2); }
.activity-limit-note:empty { display: none; }

/* Flat, list-first variant: one permanent rail and one event table. */
.places-sidebar {
    position: relative; display: flex; flex-direction: column; min-height: 100vh; overflow: hidden;
    background: var(--surface); border-right: 1px solid var(--border);
}
.places-sidebar-brand {
    display: flex; flex-direction: column; align-items: stretch; gap: 13px; min-height: 104px; padding: 18px;
    border-bottom: 1px solid var(--border);
}
.places-sidebar-back { color: var(--text-muted); font-size: 10.5px; font-weight: 650; text-decoration: none; }
.places-sidebar-back:hover { color: var(--text); }
.places-sidebar-title { display: flex; align-items: center; gap: 10px; }
.places-sidebar-brand-icon {
    display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 auto;
    border-radius: 8px; color: var(--accent-text); background: var(--accent-soft);
}
.places-sidebar-brand-icon svg { width: 21px; height: 21px; }
.places-sidebar-brand strong { display: block; color: var(--text); font-size: 14px; }
.places-sidebar-section {
    padding: 15px 14px 7px; color: var(--text-muted); font-size: 9.5px; font-weight: 800;
    letter-spacing: .08em; text-transform: uppercase;
}
.places-sidebar-head {
    display: flex; align-items: center; justify-content: space-between; padding: 13px 14px 7px;
    color: var(--text-muted); font-size: 9.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
}
.place-nav-row { position: relative; border-bottom: 1px solid var(--border); }
.place-nav-row:last-child { border-bottom: 0; }
.place-nav-item {
    display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 9px; align-items: center;
    width: 100%; min-height: 57px; padding: 9px 38px 9px 12px; border: 0; border-bottom: 1px solid var(--border);
    background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.place-nav-link { text-decoration: none; }
#placeHistoryNav { padding-right: 12px; }
.place-nav-item:hover, .place-nav-row:hover { background: var(--surface-2); }
.place-nav-item.is-active, .place-nav-row.is-active { background: var(--accent-soft); box-shadow: inset 3px 0 var(--accent); }
.place-nav-icon {
    display: grid; place-items: center; width: 30px; height: 30px; color: var(--text-muted);
    border-radius: 8px; background: var(--surface-2);
}
.is-active .place-nav-icon { color: var(--accent-text); background: var(--surface); }
.place-nav-item strong { display: block; overflow: hidden; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.place-nav-item small { display: block; margin-top: 3px; overflow: hidden; color: var(--text-muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.place-nav-edit {
    position: absolute; top: 50%; right: 8px; display: grid; place-items: center; width: 27px; height: 27px;
    transform: translateY(-50%); border: 0; border-radius: 6px; background: transparent; color: var(--text-muted); cursor: pointer;
}
.place-nav-edit:hover { color: var(--text); background: var(--surface-sunken); }
.place-nav-empty { padding: 18px 12px; color: var(--text-muted); font-size: 10.5px; text-align: center; }
.places-sidebar > #placeSidebarList { min-height: 0; max-height: calc(100vh - 430px); overflow-y: auto; }
.places-sidebar-add {
    display: flex; align-items: center; justify-content: center; gap: 7px; width: calc(100% - 24px);
    min-height: 36px; margin: 14px 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
    background: transparent; color: var(--text-secondary); font-size: 11.5px; font-weight: 650; cursor: pointer;
}
.places-sidebar-add:hover { color: var(--accent-text); border-color: var(--accent); background: var(--accent-soft); }
.places-sidebar-add span { display: flex; }
.places-sidebar-spacer { flex: 1 1 auto; min-height: 24px; }
.places-sidebar-links { padding: 10px 10px; border-top: 1px solid var(--border); }
.places-sidebar-links a {
    display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 8px 10px;
    border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 11.5px; font-weight: 650; text-decoration: none;
}
.places-sidebar-links a:hover { color: var(--text); background: var(--surface-2); }
.places-sidebar-links span { display: flex; color: var(--text-muted); }
.places-sidebar-footer { padding: 13px 18px 16px; border-top: 1px solid var(--border); }
.places-sidebar-footer > strong { display: block; overflow: hidden; color: var(--text); font-size: 11.5px; text-overflow: ellipsis; white-space: nowrap; }
.places-sidebar-footer > div { display: flex; gap: 12px; margin-top: 8px; }
.places-sidebar-footer button { padding: 0; border: 0; background: transparent; color: var(--text-muted); font-size: 10.5px; cursor: pointer; }
.places-sidebar-footer button:hover { color: var(--text); }
.activity-list-card {
    display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; min-height: 0;
    overflow: hidden; background: var(--surface); border: 0;
    border-radius: 0; box-shadow: none;
}
.activity-list-tools {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.activity-type-tabs { display: flex; gap: 6px; }
.activity-type-tab {
    min-height: 34px; padding: 6px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--text-secondary); font-size: 12px; font-weight: 650; cursor: pointer;
}
.activity-type-tab:hover { border-color: var(--border-strong); color: var(--text); }
.activity-type-tab.is-active { color: var(--accent-text); border-color: var(--accent-soft-border); background: var(--accent-soft); }
.activity-list-controls { display: flex; align-items: center; gap: 8px; }
.activity-list-controls select { min-height: 36px; padding: 6px 30px 6px 10px; font-size: 12px; }
.activity-search-box {
    display: flex; align-items: center; gap: 7px; width: min(260px, 40vw); height: 36px;
    padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.activity-search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.activity-search-box span { display: flex; color: var(--text-muted); }
.activity-search-box input { width: 100%; min-height: 0; padding: 0; border: 0; outline: 0; background: transparent; font-size: 12px; }
.activity-table-head, .activity-event {
    display: grid; grid-template-columns: 145px 110px minmax(170px, 1fr) minmax(170px, 1fr) 100px;
    gap: 16px; align-items: center;
}
.activity-table-head {
    padding: 11px 17px; color: var(--accent-text); background: var(--accent-soft);
    border-bottom: 1px solid var(--accent-soft-border); font-size: 10.5px; font-weight: 800;
    letter-spacing: .035em; text-transform: uppercase;
}
.activity-list-card .activity-events { flex: 1 1 auto; min-height: 0; max-height: none; overflow: auto; }
.activity-list-card .activity-event { padding: 14px 17px; }
.activity-list-card .activity-event-time { text-align: left; }
.activity-list-card .activity-event-time strong { font-family: var(--font); font-size: 12px; }
.activity-event-duration { color: var(--text-secondary); font-family: var(--font-mono); font-size: 11.5px; text-align: right; }
.activity-list-footer {
    display: flex; flex: 0 0 auto; justify-content: space-between; gap: 16px; padding: 11px 17px;
    border-top: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); font-size: 10.5px;
}
.activity-list-footer strong { color: var(--text-secondary); }

/* Saved places lives on its own management page. */
.saved-places-card { background: var(--surface); border-top: 1px solid var(--border); }
.saved-places-table-head, .saved-place-row {
    display: grid; grid-template-columns: minmax(220px, 1.7fr) minmax(150px, 1fr) 80px 90px minmax(150px, 1fr) 132px;
    gap: 18px; align-items: center;
}
.saved-places-table-head {
    padding: 12px 30px; color: var(--accent-text); background: var(--accent-soft);
    border-bottom: 1px solid var(--accent-soft-border); font-size: 10.5px; font-weight: 800;
    letter-spacing: .035em; text-transform: uppercase;
}
.saved-place-row { min-height: 72px; padding: 12px 30px; border-bottom: 1px solid var(--border); }
.saved-place-row:hover { background: var(--surface-2); }
.saved-place-row.is-paused { opacity: .66; }
.saved-place-name { display: flex; align-items: center; gap: 11px; min-width: 0; }
.saved-place-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto; border-radius: 8px; color: var(--accent-text); background: var(--accent-soft); }
.saved-place-name strong, .saved-place-fence strong { display: block; overflow: hidden; color: var(--text); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.saved-place-name small, .saved-place-fence small { display: block; margin-top: 4px; overflow: hidden; color: var(--text-muted); font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.saved-place-number { color: var(--text); font-family: var(--font-mono); font-size: 12px; font-weight: 700; text-align: center; }
.saved-place-last { color: var(--text-secondary); font-family: var(--font-mono); font-size: 10.5px; }
.saved-place-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* Share-link management page. */
.share-list-card { flex: 1 1 auto; min-height: 0; background: var(--surface); border-top: 1px solid var(--border); }
.share-table-head, .share-table-row {
    display: grid; grid-template-columns: minmax(190px, 1.1fr) minmax(190px, 1.25fr) 150px 90px minmax(240px, 1.5fr) 82px;
    gap: 16px; align-items: center;
}
.share-table-head {
    padding: 12px 30px; color: var(--accent-text); background: var(--accent-soft);
    border-bottom: 1px solid var(--accent-soft-border); font-size: 10.5px; font-weight: 800;
    letter-spacing: .035em; text-transform: uppercase;
}
.share-table-row { min-height: 76px; padding: 12px 30px; border-bottom: 1px solid var(--border); }
.share-table-row:hover { background: var(--surface-2); }
.share-table-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.share-table-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto; border-radius: 8px; color: var(--accent-text); background: var(--accent-soft); }
.share-table-name strong { display: block; overflow: hidden; color: var(--text); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.share-table-name small { display: block; margin-top: 3px; color: var(--text-muted); font-size: 10px; }
.share-table-devices { overflow: hidden; color: var(--text-secondary); font-size: 11.5px; line-height: 1.4; text-overflow: ellipsis; }
.share-table-expiry { color: var(--text-secondary); font-family: var(--font-mono); font-size: 10.5px; }
.share-table-url { display: flex; align-items: center; gap: 6px; min-width: 0; }
.share-table-url input { min-width: 0; height: 32px; padding: 5px 8px; font-family: var(--font-mono); font-size: 10px; }
.share-table-url > span { color: var(--text-muted); }
.share-table-actions { display: flex; justify-content: flex-end; }

.share-create-overlay, .share-result-overlay {
    position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center;
    padding: 28px; background: var(--overlay); backdrop-filter: blur(5px); animation: fe-fade-in .15s var(--ease);
}
.share-create-dialog {
    width: min(900px, 100%); max-height: calc(100vh - 56px); overflow-y: auto; padding: 24px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-lg);
}
.share-create-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(280px, .85fr); gap: 24px; }
.share-create-error { margin: -4px 0 18px; }
.share-create-grid #shareDeviceList { max-height: 360px; }
.share-result-dialog {
    width: min(520px, 100%); padding: 28px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); box-shadow: var(--shadow-lg); text-align: center;
}
.share-result-icon { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 14px; border-radius: 50%; color: var(--success); background: var(--success-soft); }
.share-result-dialog h2 { color: var(--text); font-size: 20px; }
.share-result-dialog > p { margin: 7px 0 18px; color: var(--text-secondary); font-size: 12.5px; line-height: 1.5; }
.share-result-dialog .link-result-row { margin-bottom: 14px; }

@media (max-width: 1050px) {
    .saved-places-table-head, .saved-place-row { grid-template-columns: minmax(190px, 1.5fr) 120px 65px 75px 120px; }
    .saved-places-table-head span:nth-child(5), .saved-place-last { display: none; }
    .share-table-head, .share-table-row { grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) 135px 80px minmax(210px, 1fr); }
    .share-table-head span:last-child, .share-table-actions { display: none; }
}

@media (max-width: 760px) {
    .places-app-shell { grid-template-columns: 1fr; min-height: 0; }
    .places-content { min-height: calc(100vh - 58px); padding: 0; }
    .places-sidebar { min-height: 0; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
    .places-sidebar-brand, .places-sidebar-head, .places-sidebar-section, .places-sidebar-spacer, .places-sidebar-links, .places-sidebar-footer { display: none; }
    .places-sidebar > #placeHistoryNav, .places-sidebar > #savedPlacesNav, .places-sidebar > #placeShareNavLink { display: inline-flex; flex: 0 0 auto; vertical-align: top; }
    .places-sidebar > #placeHistoryNav { width: 145px; border-bottom: 0; border-right: 1px solid var(--border); }
    .places-sidebar > #savedPlacesNav { width: 165px; border-bottom: 0; border-right: 1px solid var(--border); }
    .places-sidebar > #placeShareNavLink { width: 155px; border-bottom: 0; border-right: 1px solid var(--border); }
    .activity-list-tools { align-items: stretch; }
    .activity-type-tabs { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
    .activity-list-controls { width: 100%; }
    .activity-search-box { width: auto; flex: 1; }
    .activity-table-head { display: none; }
    .activity-list-card .activity-event {
        grid-template-columns: 95px minmax(0, 1fr) 72px; gap: 9px 12px; align-items: start;
    }
    .activity-list-card .activity-event-type { grid-column: 2; grid-row: 1; }
    .activity-list-card .activity-event-main { grid-column: 2; grid-row: 2; }
    .activity-list-card .activity-event-place { grid-column: 2 / -1; grid-row: 3; }
    .activity-list-card .activity-event-duration { grid-column: 3; grid-row: 1; }
    .activity-list-footer { flex-direction: column; gap: 4px; }
    .activity-list-card .activity-events { min-height: 260px; max-height: none; }
    .saved-places-table-head { display: none; }
    .saved-place-row { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 14px; }
    .saved-place-fence, .saved-place-number, .saved-place-last { display: none; }
    .saved-place-actions { grid-column: 2; grid-row: 1; }
    .share-table-head { display: none; }
    .share-table-row { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 14px; padding: 14px; }
    .share-table-name { grid-column: 1; grid-row: 1; }
    .share-table-row > div:nth-child(4) { grid-column: 2; grid-row: 1; }
    .share-table-devices { grid-column: 1 / -1; grid-row: 2; }
    .share-table-expiry { grid-column: 1 / -1; grid-row: 3; }
    .share-table-url { grid-column: 1 / -1; grid-row: 4; }
    .share-table-actions { display: flex; grid-column: 1 / -1; grid-row: 5; justify-content: stretch; }
    .share-table-actions .btn { width: 100%; }
    .share-create-overlay, .share-result-overlay { padding: 0; align-items: stretch; }
    .share-create-dialog { width: 100%; max-height: 100vh; min-height: 100vh; border-radius: 0; }
    .share-create-grid { grid-template-columns: 1fr; }
    .share-result-dialog { width: 100%; margin: auto 14px; }
}

.place-manager-overlay {
    position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center;
    padding: 28px; background: var(--overlay); backdrop-filter: blur(5px); animation: fe-fade-in .15s var(--ease);
}
body.place-manager-open { overflow: hidden; }
.place-manager {
    position: relative; width: min(1120px, 100%); max-height: calc(100vh - 56px); overflow-y: auto;
    padding: 22px; box-shadow: var(--shadow-lg); animation: fe-slide-up .18s var(--ease);
}
.place-manager-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.place-manager-head h2 { font-size: 23px; }
.place-manager-close {
    display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
    color: var(--text-muted); cursor: pointer;
}
.place-manager-close:hover { color: var(--text); border-color: var(--border-strong); }
.place-manager .geofence-map-wrap { height: 460px; margin: 0; }
.place-form-actions { margin-top: 18px; }
.managed-places { margin-top: 14px; padding-bottom: 8px; }
.managed-places > .activity-section-head { border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.managed-places .geofence-item { margin: 0 9px 8px; padding: 13px 14px; background: var(--surface-2); }
.managed-place-summary {
    display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 10px; padding-top: 10px;
    border-top: 1px solid var(--border); color: var(--text-muted); font-size: 10.5px;
}
.managed-place-summary strong { color: var(--text-secondary); font-weight: 700; }

@media (max-width: 1100px) {
    .activity-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
    .activity-workspace { grid-template-columns: 1fr; }
    .activity-groups { max-height: 300px; }
    .activity-events { max-height: 560px; }
    .place-manager .geofence-map-wrap { height: 340px; }
}
@media (max-width: 640px) {
    .places-page { padding: 0; }
    .places-hero { min-height: 0; padding: 16px 14px; align-items: stretch; flex-direction: column; }
    .places-hero .btn { width: 100%; }
    .activity-toolbar { align-items: stretch; padding: 10px 14px; }
    .activity-presets { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; }
    .activity-preset { padding-inline: 5px; }
    .activity-range { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; }
    .activity-range label { display: block; }
    .activity-range input { width: 100%; margin-top: 4px; }
    .activity-summary { grid-template-columns: 1fr 1fr; }
    .activity-stat { padding: 12px; }
    .activity-stat:last-child { grid-column: 1 / -1; }
    .activity-event { grid-template-columns: 90px minmax(0, 1fr) 82px; gap: 9px; padding: 12px; }
    .activity-event-place { grid-column: 2 / -1; grid-row: 2; }
    .activity-events-head { align-items: center; }
    .place-manager-overlay { padding: 0; align-items: stretch; }
    .place-manager { width: 100%; max-height: 100vh; min-height: 100vh; padding: 16px; border-radius: 0; }
    .place-manager .geofence-map-wrap { height: 280px; }
    .managed-places .geofence-actions { display: grid; grid-template-columns: repeat(2, 1fr); }
}

/* Divider + heading before a secondary list in a dialog */
.modal-section { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }
.modal-section-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 12px; }

/* Fixed-height wrapper so Chart.js can size a canvas on first open */
.sensor-hist-chart { position: relative; height: 220px; }

/* Inline state words inside data rows / sensor tiles */
.val-ok { color: var(--success-text); font-weight: 700; }
.val-bad { color: var(--danger-text); font-weight: 700; }
.val-warn { color: var(--warning-text); font-weight: 700; }
.val-muted { color: var(--text-muted); }

/* Empty/failure line inside a narrow sidebar column */
.side-empty { padding: 8px 2px; font-size: 12.5px; color: var(--text-muted); }

/* Expandable README under the firmware list */
.readme-box { margin-top: 14px; }
.readme-box-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.readme-box-head strong { font-size: 12.5px; color: var(--text); }

/* Result panel (OTA success / failure) */
.result-box {
    margin-top: 16px;
    padding: 20px;
    text-align: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.result-box-success { background: var(--success-soft); border-color: var(--success-soft-border); }
.result-box-error { background: var(--danger-soft); border-color: var(--danger-soft-border); }
.result-box-icon { display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.result-box-success .result-box-icon { color: var(--success); }
.result-box-error .result-box-icon { color: var(--danger); }
.result-box-title { font-size: 15.5px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.result-box-msg { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

@media (max-width: 640px) {
    .derived-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; gap: 0; }
    .modal-toolbar { flex-wrap: wrap; }
    .modal-toolbar-range { order: -1; width: 100%; }
    .modal-toolbar .btn { flex: 1; }
    .link-result-row { flex-wrap: wrap; }
    .link-result-row .btn { width: 100%; }
    .wiring-live-grid { grid-template-columns: repeat(2, 1fr); }

    /* Stack the range editor into labelled rows — a 5-column numeric grid
       is unusable at phone widths. */
    .range-head { display: none; }
    .fuel-range-row {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 10px;
        margin-bottom: 10px;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--surface-2);
    }
    .fuel-range-row input { min-height: 38px; }
    .fuel-range-row input::placeholder { color: var(--text-muted); }
    .range-remove { grid-column: 1 / -1; width: 100%; height: 34px; border-color: var(--border); }
}

/* ── Info rows (device info modal etc.) ───────────────────────────── */
.info-section { margin-bottom: 20px; }
.info-section h3 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    gap: 12px;
}
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text-muted); flex-shrink: 0; }
.info-value { font-weight: 600; color: var(--text); text-align: right; word-break: break-all; }

/* ── Sensor tiles ──────────────────────────────────────────────────── */
.sensor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.sensor-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.sensor-card .sensor-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); margin-bottom: 4px; }
.sensor-card .sensor-value { font-size: 18px; font-weight: 700; color: var(--text); }
.sensor-card .sensor-unit { font-size: 12px; font-weight: 400; color: var(--text-muted); margin-left: 3px; }

/* ── README / code viewer ─────────────────────────────────────────── */
.readme-container {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    margin-top: 12px;
}

/* ── Toasts ────────────────────────────────────────────────────────── */
#fe-toast-root {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 32px));
    pointer-events: none;
}

.fe-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-muted);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13.5px;
    color: var(--text);
    animation: fe-slide-up 0.2s var(--ease);
}

.fe-toast svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.fe-toast-msg { flex: 1; line-height: 1.4; }
.fe-toast-close { flex-shrink: 0; cursor: pointer; color: var(--text-muted); padding: 2px; border-radius: 4px; }
.fe-toast-close:hover { color: var(--text); background: var(--surface-sunken); }

.fe-toast-success { border-left-color: var(--success); }
.fe-toast-success svg { color: var(--success); }
.fe-toast-error { border-left-color: var(--danger); }
.fe-toast-error svg { color: var(--danger); }
.fe-toast-warning { border-left-color: var(--warning); }
.fe-toast-warning svg { color: var(--warning); }
.fe-toast-info { border-left-color: var(--info); }
.fe-toast-info svg { color: var(--info); }

.fe-toast-leaving { animation: fe-toast-out 0.15s var(--ease) forwards; }
@keyframes fe-toast-out { to { opacity: 0; transform: translateY(-6px) scale(0.98); } }

/* ── Confirm dialog ────────────────────────────────────────────────── */
.fe-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 5000;
    background: var(--overlay);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fe-fade-in 0.15s var(--ease);
}

.fe-confirm-box {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 22px;
    animation: fe-slide-up 0.18s var(--ease);
}

.fe-confirm-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin-bottom: 14px;
    background: var(--danger-soft);
    color: var(--danger);
}

.fe-confirm-icon svg { width: 20px; height: 20px; }
.fe-confirm-box.fe-confirm-neutral .fe-confirm-icon { background: var(--accent-soft); color: var(--accent); }

.fe-confirm-title { font-size: 15.5px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.fe-confirm-message { font-size: 13.5px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 20px; }
.fe-confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

@media (max-width: 640px) {
    #fe-toast-root { left: 16px; right: 16px; top: 12px; max-width: none; }
}
