/* ====================================================================
 * Centralized Maintenance Manager - Design System
 * --------------------------------------------------------------------
 *  1. Design tokens
 *  2. Base & reset
 *  3. Layout (app shell, navbar, footer)
 *  4. Buttons
 *  5. Forms
 *  6. Badges & alerts
 *  7. Dashboard: header, stats, toolbar
 *  8. Dashboard: website cards
 *  9. Dashboard: audit log
 * 10. Modals & code snippets
 * 11. Toasts
 * 12. Auth pages (login & installer)
 * 13. Utilities & accessibility
 * 14. Responsive breakpoints
 * ==================================================================== */

/* 1. Design tokens ---------------------------------------------------- */
:root {
    color-scheme: dark;

    --bg-main: #0a0e17;
    --bg-elevated: #101623;
    --bg-card: rgba(17, 24, 39, 0.88);
    --bg-subtle: rgba(255, 255, 255, 0.03);
    --bg-subtle-hover: rgba(255, 255, 255, 0.07);
    --bg-inset: rgba(0, 0, 0, 0.25);
    --bg-input: #0b101b;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-hover: rgba(255, 255, 255, 0.16);

    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-soft: rgba(99, 102, 241, 0.12);
    --primary-glow: rgba(99, 102, 241, 0.3);
    --primary-text: #a5b4fc;

    --success: #10b981;
    --success-text: #34d399;
    --success-bg: rgba(16, 185, 129, 0.12);
    --success-border: rgba(16, 185, 129, 0.3);

    --danger: #ef4444;
    --danger-text: #f87171;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --danger-border: rgba(239, 68, 68, 0.3);

    --warning: #f59e0b;
    --warning-text: #fbbf24;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --warning-border: rgba(245, 158, 11, 0.35);

    --accent-cyan: #38bdf8;

    --text-title: #f8fafc;
    --text-strong: #cbd5e1;
    --text-body: #94a3b8;
    --text-muted: #64748b;

    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255, 255, 255, 0.1);
    --shadow-modal: 0 25px 50px -12px rgba(0, 0, 0, 0.85);

    --container: 1280px;
    --gutter: 24px;
    --nav-height: 64px;
    --transition: 0.2s ease;
}

/* 2. Base & reset ----------------------------------------------------- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    background-color: var(--bg-main);
    color: var(--text-body);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

body.modal-open { overflow: hidden; }

img, svg { display: block; flex-shrink: 0; }

a { color: inherit; }

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

code, pre { font-family: var(--font-mono); }

h1, h2, h3, h4 {
    color: var(--text-title);
    letter-spacing: -0.02em;
    line-height: 1.25;
}

/* Background ambient glows */
.ambient-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(140px);
    opacity: 0.12;
    pointer-events: none;
    z-index: 0;
}
.ambient-glow-1 { top: -120px; left: -120px; width: 460px; height: 460px; background: #6366f1; }
.ambient-glow-2 { bottom: -120px; right: -120px; width: 520px; height: 520px; background: #06b6d4; }

/* 3. Layout ----------------------------------------------------------- */
.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding-left: var(--gutter);
    padding-right: var(--gutter);
}

.navbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(10, 14, 23, 0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    min-height: var(--nav-height);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    min-width: 0;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #38bdf8);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 0 16px var(--primary-glow);
}

.brand-icon-lg {
    width: 52px;
    height: 52px;
    border-radius: 14px;
}

.brand-text { min-width: 0; }

.brand-text h1 {
    font-size: 1.05rem;
    font-weight: 800;
    white-space: nowrap;
}

.brand-tagline {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.system-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
    font-size: 0.74rem;
    font-weight: 600;
    white-space: nowrap;
}

.live-pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
    animation: pulseGlow 2s infinite;
}

.main-wrapper {
    position: relative;
    z-index: 1;
    flex: 1;
    padding-top: 32px;
    padding-bottom: 56px;
}

.app-footer {
    position: relative;
    z-index: 1;
    border-top: 1px solid var(--border-color);
    padding: 18px 0;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.app-footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

/* 4. Buttons ---------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    box-shadow: 0 4px 14px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 18px var(--primary-glow); }

.btn-secondary {
    background: var(--bg-subtle);
    border-color: var(--border-color);
    color: var(--text-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-subtle-hover); border-color: var(--border-color-hover); color: var(--text-title); }

.btn-ghost-danger {
    background: var(--bg-subtle);
    border-color: var(--border-color);
    color: var(--text-body);
}
.btn-ghost-danger:hover { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }

.btn-block { width: 100%; }
.btn-lg { min-height: 48px; padding: 12px 22px; font-size: 0.95rem; }

.btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border-color);
    background: var(--bg-subtle);
    color: var(--text-body);
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn-sm:hover { background: var(--bg-subtle-hover); border-color: var(--border-color-hover); color: var(--text-title); }
.btn-sm:disabled { opacity: 0.6; cursor: wait; }

.btn-bypass { background: var(--primary-soft); border-color: rgba(99, 102, 241, 0.28); color: var(--primary-text); }
.btn-bypass:hover { background: rgba(99, 102, 241, 0.22); color: #fff; }

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

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--bg-subtle-hover); color: var(--text-title); }

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

.form-group label,
.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-title);
    margin-bottom: 6px;
}

.label-optional {
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 4px;
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.form-hint code {
    font-size: 0.72rem;
    color: var(--accent-cyan);
    background: var(--bg-subtle);
    padding: 1px 5px;
    border-radius: 4px;
}

.form-control {
    width: 100%;
    min-height: 44px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-title);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control::placeholder { color: #475569; }
.form-control:hover { border-color: var(--border-color-hover); }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

select.form-control {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' 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 14px center;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
}
.form-grid .span-2 { grid-column: 1 / -1; }

.input-with-action { position: relative; }
.input-with-action .form-control { padding-right: 48px; }
.input-with-action .btn-icon {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
}

.form-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-title);
    margin: 26px 0 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}
.form-section-title:first-of-type { margin-top: 0; }

.step-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-soft);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: var(--primary-text);
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* 6. Badges & alerts -------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
    border: 1px solid transparent;
}
.badge-live { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.badge-maintenance { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.badge-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.badge-failed { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--warning);
    box-shadow: 0 0 8px var(--warning);
    animation: pulseGlow 1.8s infinite;
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.6; transform: scale(0.95); }
    50% { opacity: 1; transform: scale(1.25); }
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.85rem;
    margin-bottom: 20px;
}
.alert svg { margin-top: 2px; }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert-error { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }

/* 7. Dashboard: header, stats, toolbar -------------------------------- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 28px;
}

.page-header h2 {
    font-size: 1.6rem;
    font-weight: 800;
}

.page-header p {
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
    max-width: 60ch;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(12px);
    text-align: left;
    width: 100%;
    min-width: 0;
    transition: transform var(--transition), border-color var(--transition);
}

button.stat-card:hover { transform: translateY(-2px); border-color: var(--border-color-hover); }

.stat-info { min-width: 0; }

.stat-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    display: block;
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--text-title);
    letter-spacing: -0.02em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.stat-value-sm { font-size: 1.1rem; line-height: 1.6; color: var(--text-strong); }
.stat-value-amber { color: var(--warning-text); }
.stat-value-green { color: var(--success-text); }

.stat-subtext {
    display: block;
    font-size: 0.74rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.stat-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.icon-blue { background: rgba(56, 189, 248, 0.12); color: #38bdf8; }
.icon-amber { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.icon-green { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.icon-purple { background: rgba(99, 102, 241, 0.12); color: #818cf8; }

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 16px;
}

.section-heading h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.section-heading p {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.filter-tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition);
}
.tab-btn:hover { color: var(--text-title); }
.tab-btn.active { background: var(--primary); color: #fff; box-shadow: 0 2px 8px var(--primary-glow); }

.tab-count {
    min-width: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 0.7rem;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.tab-btn.active .tab-count { background: rgba(255, 255, 255, 0.22); }

.search-wrap {
    position: relative;
    width: 280px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    min-height: 40px;
    padding: 9px 14px 9px 38px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-title);
    font-size: 0.85rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.search-input::-webkit-search-cancel-button { filter: invert(0.6); }

/* 8. Dashboard: website cards ----------------------------------------- */
.websites-container {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin-bottom: 40px;
}

.site-card {
    position: relative;
    padding: 18px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(12px);
    min-width: 0;
    transition: border-color 0.25s ease, background 0.25s ease;
}
.site-card:hover { border-color: var(--border-color-hover); }

.site-card.is-active-maintenance {
    border-color: rgba(245, 158, 11, 0.45);
    background: linear-gradient(180deg, rgba(30, 24, 16, 0.9) 0%, rgba(18, 24, 38, 0.95) 100%);
}

.site-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    user-select: none;
}

.site-header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.btn-expand {
    border-color: var(--border-color);
    background: var(--bg-subtle);
}
.btn-expand svg { transition: transform 0.3s ease; }
.site-card.is-expanded .btn-expand { color: var(--text-title); border-color: var(--border-color-hover); }
.site-card.is-expanded .btn-expand svg { transform: rotate(180deg); }
.site-card.is-expanded { border-color: var(--border-color-hover); }
.site-card.is-active-maintenance.is-expanded { border-color: rgba(245, 158, 11, 0.55); }

/* Expandable details (animated height via grid rows) */
.site-card-details {
    display: grid;
    grid-template-rows: 0fr;
    visibility: hidden;
    transition: grid-template-rows 0.3s ease, visibility 0s linear 0.3s;
}

.site-card.is-expanded .site-card-details {
    grid-template-rows: 1fr;
    visibility: visible;
    transition: grid-template-rows 0.3s ease, visibility 0s linear 0s;
}

.site-card-details-inner {
    min-height: 0;
    overflow: hidden;
}

.site-card-details-inner::before {
    content: "";
    display: block;
    height: 1px;
    margin: 18px 0;
    background: var(--border-color);
}

/* Visit counters */
.hit-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
}

.hit-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-subtle);
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.hit-chip-live { color: var(--success-text); }
.hit-chip-diverted { color: var(--warning-text); }

.traffic-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.traffic-card {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    border-left-width: 3px;
    background: var(--bg-elevated);
    min-width: 0;
}
.traffic-live { border-left-color: var(--success); }
.traffic-diverted { border-left-color: var(--warning); }

.traffic-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 6px;
}

.traffic-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.traffic-total {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.traffic-live .traffic-total { color: var(--success-text); }
.traffic-diverted .traffic-total { color: var(--warning-text); }

.traffic-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.counter-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.counter-state {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.76rem;
    font-weight: 600;
}
.counter-on { color: var(--success-text); }
.counter-off { color: var(--text-muted); }

.traffic-hint {
    display: inline-block;
    padding: 0;
    border: none;
    background: none;
    color: var(--primary-text);
    font-size: 0.76rem;
    font-weight: 600;
    text-align: left;
}
.traffic-hint:hover { text-decoration: underline; color: #fff; }

.traffic-breakdown strong { color: var(--text-strong); font-variant-numeric: tabular-nums; }

.site-meta-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1px;
    margin-bottom: 14px;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.meta-item {
    padding: 12px 16px;
    background: var(--bg-elevated);
    min-width: 0;
}

.meta-item dt {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.meta-item dd {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-strong);
    overflow-wrap: anywhere;
}

.site-identity {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.site-avatar {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
    transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.avatar-blue { background: rgba(56, 189, 248, 0.12); border-color: rgba(56, 189, 248, 0.3); color: #38bdf8; }
.avatar-amber { background: rgba(245, 158, 11, 0.15); border-color: rgba(245, 158, 11, 0.4); color: var(--warning-text); }

.site-info-text { min-width: 0; }

.site-title-line {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 10px;
}

.site-title-line h3 {
    font-size: 1.1rem;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.site-sub-links {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-top: 4px;
    font-size: 0.82rem;
    min-width: 0;
}

.domain-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--accent-cyan);
    font-weight: 600;
    text-decoration: none;
    overflow-wrap: anywhere;
}
.domain-tag:hover { text-decoration: underline; }

.dot-separator { color: var(--text-muted); }
.site-desc-tag { color: var(--text-muted); font-size: 0.8rem; overflow-wrap: anywhere; }

.toggle-control-box {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.toggle-text-block { text-align: right; }

.toggle-headline {
    display: block;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--text-title);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.toggle-status-desc {
    display: block;
    font-size: 0.74rem;
    color: var(--text-muted);
}

.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}
.switch input:disabled { cursor: wait; }

.slider {
    position: absolute;
    inset: 0;
    background-color: #334155;
    border-radius: 34px;
    transition: background-color 0.3s, box-shadow 0.3s;
}

.slider::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 4px;
    bottom: 4px;
    background-color: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
}

.switch input:checked + .slider { background-color: var(--warning); box-shadow: 0 0 14px rgba(245, 158, 11, 0.5); }
.switch input:checked + .slider::before { transform: translateX(24px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary-text); outline-offset: 3px; }
.switch input:disabled + .slider { opacity: 0.6; }

.routing-pipeline-box {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 16px;
    padding: 14px 18px;
    margin-bottom: 14px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.pipeline-node { min-width: 0; }
.node-target { text-align: right; }

.node-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.node-value {
    display: block;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-title);
    overflow-wrap: anywhere;
}

.node-link { color: var(--primary-text); text-decoration: none; }
.node-link:hover { text-decoration: underline; }

.pipeline-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    transition: color 0.25s ease;
}

.arrow-badge {
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}

.pipeline-arrow.arrow-diverting { color: var(--warning); }
.pipeline-arrow.arrow-diverting .arrow-badge { background: rgba(245, 158, 11, 0.18); color: var(--warning-text); }

.diagnostic-strip {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 20px;
    padding: 10px 14px;
    margin-bottom: 16px;
    background: var(--bg-subtle);
    border-radius: var(--radius-xs);
    font-size: 0.78rem;
}

.diag-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.diag-label {
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

.diag-val {
    color: var(--text-strong);
    font-weight: 600;
    overflow-wrap: anywhere;
}

.diag-code {
    font-size: 0.74rem;
    color: var(--accent-cyan);
    overflow-wrap: anywhere;
}

.site-card-footer {
    display: flex;
    justify-content: flex-end;
}

.card-btn-group {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.empty-state-card {
    padding: 56px 24px;
    background: var(--bg-card);
    border: 1px dashed var(--border-color-hover);
    border-radius: var(--radius-md);
    text-align: center;
}

.empty-icon {
    width: 60px;
    height: 60px;
    margin-bottom: 16px;
    border-radius: 16px;
    background: var(--bg-subtle);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.empty-state-card h3 { font-size: 1.15rem; margin-bottom: 6px; }

.empty-state-card p {
    max-width: 440px;
    margin: 0 auto 22px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.empty-state-card.compact { padding: 36px 20px; }
.empty-state-card.compact p { margin-bottom: 0; }

/* 9. Dashboard: audit log --------------------------------------------- */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h3 { font-size: 1.1rem; font-weight: 700; }

.panel-header p {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.panel-meta {
    font-size: 0.76rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Audit log scrolls inside its own box instead of stretching the page */
.audit-scroll {
    max-height: 420px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.audit-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.audit-scroll::-webkit-scrollbar-track { background: transparent; }
.audit-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 999px; }
.audit-scroll::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.24); }

.audit-scroll .custom-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #0d1220;
    border-bottom: none;
    box-shadow: inset 0 -1px 0 var(--border-color);
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.82rem;
}

.custom-table th {
    padding: 11px 16px;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.custom-table td {
    padding: 13px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-body);
    vertical-align: top;
}

.custom-table tbody tr:last-child td { border-bottom: none; }
.custom-table tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }

.cell-time { white-space: nowrap; }
.cell-time time { display: block; color: var(--text-strong); font-weight: 600; }
.cell-time small { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted); }

.cell-site strong { color: var(--text-title); font-weight: 600; }

.action-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-subtle);
    color: var(--accent-cyan);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.cell-details {
    font-size: 0.78rem;
    color: var(--text-muted);
    overflow-wrap: anywhere;
    min-width: 260px;
}

.table-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 16px !important;
}

/* 10. Modals & code snippets ------------------------------------------ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 600px;
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-modal);
    animation: modalIn 0.22s ease;
}

.modal-card.modal-wide { max-width: 760px; }

.modal-card > form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }

.modal-header p {
    margin-top: 2px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.modal-accent { color: var(--accent-cyan); }

.modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 24px 4px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }

.snippet-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 14px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow-x: auto;
    scrollbar-width: none;
}
.snippet-tabs::-webkit-scrollbar { display: none; }
.snippet-tabs .tab-btn { flex: 1; justify-content: center; }

.snippet-panel { display: none; }
.snippet-panel.active { display: block; }

.snippet-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.code-box {
    position: relative;
    margin-bottom: 18px;
    background: #070a12;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.code-box pre {
    padding: 44px 16px 16px;
    max-height: 360px;
    overflow: auto;
    font-size: 0.76rem;
    line-height: 1.6;
    color: var(--accent-cyan);
    white-space: pre;
    tab-size: 4;
}

.btn-copy-code {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    transition: background var(--transition);
}
.btn-copy-code:hover { background: rgba(255, 255, 255, 0.16); }

/* 11. Toasts ---------------------------------------------------------- */
.toast-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(400px, calc(100vw - 32px));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    background: #1a2233;
    border: 1px solid var(--border-color);
    border-left-width: 4px;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.84rem;
    pointer-events: auto;
    animation: slideUp 0.3s ease;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.is-leaving { opacity: 0; transform: translateY(16px); }
.toast-icon { font-weight: 800; line-height: 1.5; }
.toast-message { overflow-wrap: anywhere; }

.toast.success { border-left-color: var(--success); }
.toast.success .toast-icon { color: var(--success-text); }
.toast.error { border-left-color: var(--danger); }
.toast.error .toast-icon { color: var(--danger-text); }
.toast.warning { border-left-color: var(--warning); }
.toast.warning .toast-icon { color: var(--warning-text); }

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* 12. Auth pages (login & installer) ---------------------------------- */
.auth-body {
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
}

.auth-shell {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    margin: auto;
}

.auth-shell.auth-wide { max-width: 640px; }

.auth-card {
    padding: 36px 32px;
    background: rgba(18, 24, 38, 0.92);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.auth-header {
    text-align: center;
    margin-bottom: 28px;
}

.auth-header .brand-icon { margin: 0 auto 16px; }

.auth-header h1,
.auth-header h2 {
    font-size: 1.4rem;
    font-weight: 800;
}

.auth-header p {
    margin-top: 6px;
    font-size: 0.86rem;
    color: var(--text-muted);
}

.auth-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.auth-actions { margin-top: 24px; }

/* 13. Utilities & accessibility --------------------------------------- */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-center { text-align: center; }
.mt-0 { margin-top: 0 !important; }

[hidden] { display: none !important; }

:focus-visible {
    outline: 2px solid var(--primary-text);
    outline-offset: 2px;
}

.form-control:focus-visible,
.search-input:focus-visible { outline: none; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 14. Responsive breakpoints ------------------------------------------ */

/* Tablets */
@media (max-width: 900px) {
    :root { --gutter: 20px; }

    .site-header-row { flex-direction: column; align-items: stretch; gap: 14px; }
    .site-header-controls { width: 100%; }
    .toggle-control-box { flex: 1; justify-content: space-between; }
    .toggle-text-block { text-align: left; }
    .btn-expand { width: 44px; height: auto; align-self: stretch; }
    .site-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    .section-heading { align-items: stretch; flex-direction: column; }
    .toolbar { width: 100%; }
    .search-wrap { flex: 1; min-width: 200px; width: auto; }

    .diagnostic-strip { grid-template-columns: minmax(0, 1fr); }
}

/* Large phones / small tablets */
@media (max-width: 720px) {
    :root { --gutter: 16px; --nav-height: 58px; }

    .main-wrapper { padding-top: 22px; padding-bottom: 40px; }

    .brand-tagline { display: none; }
    .system-status-text { display: none; }
    .system-status { padding: 8px; }
    .btn-logout-label { display: none; }

    .page-header { flex-direction: column; align-items: stretch; margin-bottom: 22px; }
    .page-header h2 { font-size: 1.35rem; }
    .page-header .btn { width: 100%; }

    .stats-grid { gap: 10px; margin-bottom: 26px; }
    .stat-card { padding: 14px 16px; }
    .stat-value { font-size: 1.5rem; }
    .stat-value-sm { font-size: 0.95rem; }
    .stat-icon-wrap { width: 36px; height: 36px; border-radius: 10px; }
    .stat-icon-wrap svg { width: 18px; height: 18px; }

    .toolbar { flex-direction: column; align-items: stretch; }
    .filter-tabs { display: flex; width: 100%; overflow-x: auto; scrollbar-width: none; }
    .filter-tabs::-webkit-scrollbar { display: none; }
    .filter-tabs .tab-btn { flex: 1; justify-content: center; }
    .search-wrap { width: 100%; min-width: 0; }

    .site-card { padding: 16px; }

    .routing-pipeline-box { grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px 14px; }
    .node-target { text-align: left; }
    .pipeline-arrow { flex-direction: row; justify-content: flex-start; gap: 8px; }
    .pipeline-arrow svg { transform: rotate(90deg); }

    .card-btn-group {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }
    .card-btn-group .btn-sm { width: 100%; min-height: 40px; }

    /* Audit log: table becomes stacked cards */
    .panel-header { padding: 16px; }
    .audit-scroll { max-height: 480px; }
    .custom-table thead { display: none; }
    .custom-table,
    .custom-table tbody,
    .custom-table tr,
    .custom-table td { display: block; width: 100%; }
    .custom-table tr {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color);
    }
    .custom-table tbody tr:last-child { border-bottom: none; }
    .custom-table tbody tr:hover td { background: transparent; }
    .custom-table td {
        display: grid;
        grid-template-columns: 96px minmax(0, 1fr);
        gap: 10px;
        padding: 5px 0;
        border: none;
        min-width: 0;
    }
    .custom-table td::before {
        content: attr(data-label);
        font-size: 0.68rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
        padding-top: 2px;
    }
    .custom-table td.table-empty { display: block; }
    .custom-table td.table-empty::before { content: none; }
    .cell-time { white-space: normal; }
    .cell-details { min-width: 0; }

    /* Modals become bottom sheets */
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal-card,
    .modal-card.modal-wide {
        max-width: 100%;
        max-height: 92vh;
        max-height: 92dvh;
        border-radius: 18px 18px 0 0;
        border-bottom: none;
    }
    .modal-header { padding: 18px 16px; }
    .modal-body { padding: 16px 16px 4px; }
    .modal-actions {
        flex-direction: column-reverse;
        padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    }
    .modal-actions .btn { width: 100%; }

    .form-grid { grid-template-columns: minmax(0, 1fr); }

    .auth-card { padding: 28px 20px; border-radius: 16px; }
    .auth-header h1,
    .auth-header h2 { font-size: 1.25rem; }

    .app-footer .container { justify-content: center; text-align: center; }

    .toast-container { left: 16px; right: 16px; bottom: 16px; width: auto; }
}

/* Small phones */
@media (max-width: 420px) {
    .stat-card { padding: 12px; }
    .stat-icon-wrap { display: none; }
    .traffic-grid { grid-template-columns: minmax(0, 1fr); }
    .stat-value-sm { font-size: 0.85rem; }
    .card-btn-group { grid-template-columns: minmax(0, 1fr); }
    .toggle-control-box { padding: 10px 12px; }
    .site-avatar { width: 40px; height: 40px; font-size: 0.9rem; }
    .custom-table td { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    .auth-body { padding: 16px 12px; }
}
