/* NexusGPS Admin Console — distinct burgundy theme so admin work feels obviously
   "elevated" vs the everyday fleet app. */
:root {
    --bg-page: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #0f172a;
    --border: #334155;
    --border-strong: #475569;
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --accent: #be123c;         /* burgundy */
    --accent-hover: #9f1239;
    --accent-soft: rgba(190, 18, 60, 0.15);
    --success: #10b981;
    /* Amber is the System page's "answered, but not with a 2xx" — a third state
       between up and down, which is the point of that page. */
    --warning: #f59e0b;
    --danger: #ef4444;
}

* { box-sizing: border-box; }
html, body {
    height: 100%;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text);
}
#app { height: 100%; display: flex; flex-direction: column; }

/* ===== Login screen ===== */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(ellipse at top, #1e293b 0%, #0f172a 60%);
}
.login-card {
    width: 360px;
    background: var(--bg-card);
    padding: 32px 28px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.login-logo {
    text-align: center;
    margin-bottom: 24px;
}
.login-logo i {
    color: var(--accent);
    font-size: 38px;
}

/* NexusGPS wordless logo, tinted to the admin accent (#be123c). The
   source PNG is the same one used in the main app's branding folder;
   filter() chain colorises the cyan/grey hexagon to flat burgundy so
   it matches the admin theme without needing a separate red asset. */
.brand-logo {
    display: inline-block;
    object-fit: contain;
    filter: brightness(0) saturate(100%) invert(15%) sepia(64%) saturate(4853%) hue-rotate(335deg) brightness(89%) contrast(99%);
}
.brand-logo-lg { width: 64px; height: 64px; margin-bottom: 4px; }
.brand-logo-sm { width: 28px; height: 28px; }
.login-logo h1 {
    margin: 8px 0 4px;
    font-size: 1.4rem;
    font-weight: 600;
}
.login-logo p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}
.login-card form { display: flex; flex-direction: column; gap: 6px; }
.login-card label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 8px;
}
.login-card input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 10px;
    color: var(--text);
    font-size: 0.95rem;
}
.login-card input:focus {
    outline: none;
    border-color: var(--accent);
}
.login-error {
    margin-top: 12px;
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
}
.login-error.hidden { display: none; }
.btn-primary {
    margin-top: 16px;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.login-footnote {
    margin-top: 18px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* ===== App shell ===== */
.admin-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}
.admin-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.sidebar-brand {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}
.sidebar-brand i { color: var(--accent); font-size: 1.2rem; }
.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.92rem;
}
.sidebar-nav .nav-item:hover { background: rgba(255,255,255,0.05); }
.sidebar-nav .nav-item.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-nav .nav-item i { width: 18px; text-align: center; }
.sidebar-user {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}
.sidebar-user .user-name { font-weight: 600; }
.sidebar-user .user-email {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-bottom: 8px;
    word-break: break-all;
}
.btn-link {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 0.85rem;
}
.btn-link:hover { color: var(--accent); }

.admin-content {
    flex: 1;
    overflow: auto;
    padding: 24px 28px;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 20px;
}
.page-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-header h2 i { color: var(--accent); }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 48px;
    color: var(--border-strong);
    margin-bottom: 16px;
}
.empty-state h3 { color: var(--text); margin: 0 0 8px; }
.empty-state p { margin: 4px 0; }
.text-muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* ===== Tables ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.data-table thead th {
    background: rgba(255,255,255,0.03);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.data-table code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ===== Pills + status ===== */
.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}
.pill.green { background: rgba(16,185,129,0.15); color: var(--success); }
.pill.grey  { background: rgba(148,163,184,0.15); color: var(--text-muted); }
/* Deleted-tenants states: amber = inside the retention window (restorable),
   red = past it and waiting on the purge job's next scan. */
.pill.amber { background: rgba(217,119,6,0.18);  color: #f0b429; }
.pill.red   { background: rgba(239,68,68,0.15);  color: var(--danger, #ef4444); }

/* ===== Destructive-dialog panel (delete reseller) =====
   Boxed and tinted so the list of what is about to be destroyed reads as a warning
   rather than as body copy. Scrolls: a reseller with 40 client companies must not push
   the Cancel button off screen. */
.danger-panel {
    border: 1px solid rgba(239,68,68,0.35);
    background: rgba(239,68,68,0.06);
    border-radius: 8px;
    padding: 0.9rem 1rem;
    margin-bottom: 1rem;
    max-height: 45vh;
    overflow-y: auto;
}
.danger-panel h4 {
    margin: 0.9rem 0 0.35rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}
.danger-panel ul { margin: 0; padding-left: 1.15rem; font-size: 0.88rem; }
.danger-panel li { margin-bottom: 0.25rem; }
.danger-panel p  { margin: 0; font-size: 0.9rem; line-height: 1.5; }

.muted { color: var(--text-muted); font-size: 0.85rem; }

/* The type-DELETE gate. Monospace + letter-spacing so the typed word is unmistakable. */
#delGate {
    width: 100%;
    padding: 8px 10px;
    margin-top: 0.35rem;
    border-radius: 6px;
    border: 1px solid var(--border, rgba(148,163,184,0.3));
    background: var(--bg-input);
    color: var(--text-primary, #e2e8f0);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0.08em;
}
/* Solid danger button for the delete dialogs. Only `.btn-icon.btn-danger` existed
   before (a hover colour for table icons), so a `.btn-danger` in a modal footer
   rendered as an unstyled browser button. Mirrors .btn-primary's box, red fill. */
button.btn-danger {
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.3;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
    background: var(--danger);
    color: #fff;
    border: 1px solid transparent;
}
button.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
/* Keep the icon-button variant transparent — it is a table affordance, not a CTA. */
.btn-icon.btn-danger { background: transparent; color: var(--text-muted); padding: 4px 6px; }
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Buttons + chrome row ===== */
/* All three controls share font + padding so they line up visually.
   We use padding-based sizing (not fixed height) because <select> ignores
   flexbox styling — its native render does its own height. */
.btn-primary,
.btn-secondary {
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.3;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    box-sizing: border-box;
    font-family: inherit;
}
/* Inside modals primary loses its top margin so it sits flush with cancel */
.modal-card .btn-primary { margin-top: 0; }

.btn-secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: rgba(255,255,255,0.04); }
.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.95rem;
    margin: 0 2px;
}
.btn-icon:hover { color: var(--accent); background: rgba(255,255,255,0.05); }
.btn-icon.btn-danger:hover { color: var(--danger); }
.filter-select {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.9rem;
    line-height: 1.3;
    font-family: inherit;
    box-sizing: border-box;
    margin-right: 0;
}

.page-actions { display: flex; align-items: center; gap: 8px; }

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-backdrop.open { display: flex; }
.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 460px;
    max-width: 92vw;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-body {
    padding: 16px 18px;
    overflow-y: auto;
}
.form-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.form-grid label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 8px;
}
.form-grid input,
.form-grid select,
.form-grid textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 0.92rem;
    font-family: inherit;
}
.form-grid input:focus,
.form-grid select:focus { outline: none; border-color: var(--accent); }
.form-grid hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0 6px 0;
}
.form-grid h4 { margin: 6px 0; color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ===== Stats / System ===== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}
.stat-card .val { font-size: 1.6rem; font-weight: 600; color: var(--accent); }
.stat-card .lbl { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
.service-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.service-list li {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 14px;
    display: flex;
    gap: 8px;
    align-items: center;
}
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }
.empty-state.error i { color: var(--danger); }

/* System page health rows. The name takes the slack so the state and the detail
   (HTTP status, latency) stay right-aligned and scannable down the column. */
.service-row .service-name { flex: 1; }
.service-row .service-state { font-size: 0.85rem; font-weight: 600; }
.service-row .service-detail {
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    min-width: 0;
}
/* A row that is not deployed is not a failure — it must not read as one. Dimmed
   whole-row, so it recedes next to the services that are actually being checked. */
.service-row.not-deployed { opacity: 0.55; }

/* ===== Toasts ===== */
#toastHost {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 10px 16px;
    border-radius: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.9rem;
    min-width: 220px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }
