:root {
    /* Core palette */
    --color-bg: #050a1a;
    --color-surface-1: #0f1729;
    --color-surface-2: #16213d;
    --color-surface-3: #1f2d52;
    --color-border: rgba(148, 163, 184, 0.2);
    --color-border-strong: rgba(148, 163, 184, 0.4);
    --color-text-primary: #f9fbff;
    --color-text-secondary: rgba(226, 232, 240, 0.72);
    --color-muted: rgba(148, 163, 184, 0.6);
    --color-inverse: #070a12;

    --color-accent: #f59f0b;
    --color-accent-strong: #f97316;
    --color-positive: #22c55e;
    --color-warning: #fbbf24;
    --color-destructive: #ef4444;
    --color-info: #38bdf8;

    /* Typography */
    --font-sans: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;

    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.5rem;
    --font-size-2xl: 2rem;

    /* Radius */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    /* Shadow */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.4);
    --shadow-md: 0 12px 30px rgba(15, 23, 42, 0.28);
    --shadow-lg: 0 28px 60px rgba(7, 16, 36, 0.4);

    /* Spacing scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
}

/* Scrollbar polish */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top, rgba(59, 130, 246, 0.08), transparent 45%), var(--color-bg);
    color: var(--color-text-primary);
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

a:hover,
a:focus {
    color: var(--color-accent);
}

/* Top navigation */
.top-nav {
    backdrop-filter: blur(18px);
    background: rgba(15, 23, 42, 0.86);
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-nav__inner {
    width: min(1140px, 94vw);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-2);
    gap: var(--space-4);
}

.top-nav__brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 700;
    letter-spacing: 0.08em;
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-pill);
    background: rgba(59, 130, 246, 0.12);
    color: rgba(191, 219, 254, 0.92);
    line-height: 1;
    white-space: nowrap;
}

.top-nav__logo {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    flex-shrink: 0;
}

.top-nav__brand span {
    display: inline-block;
}

.top-nav__links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.top-nav__link {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-pill);
    color: var(--color-text-secondary);
    transition: background 0.18s ease, color 0.18s ease;
}

.top-nav__link:hover,
.top-nav__link:focus {
    background: rgba(59, 130, 246, 0.16);
    color: var(--color-text-primary);
}

.top-nav__link.is-active {
    background: rgba(245, 159, 11, 0.16);
    color: var(--color-accent);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Layout helpers */
.app-shell {
    width: min(1120px, 92vw);
    margin: 0 auto;
    padding: var(--space-6) var(--space-4) var(--space-10);
}

.app-shell--wide {
    width: min(1320px, 94vw);
}

.control-room-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 960px) minmax(0, 1fr);
    grid-template-areas: "left main right";
    align-items: start;
    gap: var(--space-6);
    padding: var(--space-6) var(--space-4) var(--space-10);
    margin: 0 auto;
    width: min(1680px, 100%);
    box-sizing: border-box;
}

.control-room-main-col {
    grid-area: main;
    display: flex;
    justify-content: center;
}

.control-room-main {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
}

.control-room-side {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.control-room-side--left {
    grid-area: left;
}

.control-room-side--right {
    grid-area: right;
}

@media (max-width: 1280px) {
    .control-room-grid {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "main"
            "left"
            "right";
        gap: var(--space-4);
    }

    .control-room-main {
        max-width: none;
    }
}

@media (max-width: 768px) {
    .control-room-grid {
        padding: var(--space-4) var(--space-3) var(--space-8);
    }
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.page-header__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.page-header__action {
    margin-top: var(--space-3);
}

@media (max-width: 640px) {
    .page-header__action {
        width: 100%;
    }
}

.page-header__eyebrow {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--color-muted);
    margin-bottom: var(--space-2);
}

.page-header__title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 var(--space-2);
}

.page-header__subtitle {
    margin: 0;
    color: var(--color-text-secondary);
}

.page-grid {
    display: grid;
    gap: var(--space-6);
    align-items: stretch;
}

.page-grid--two {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.page-grid--two>* {
    height: 100%;
}

.page-grid--two>section {
    margin-top: 0;
}

section+section {
    margin-top: var(--space-6);
}

.surface,
.card,
.panel {
    background: linear-gradient(135deg, rgba(30, 41, 73, 0.84), rgba(17, 24, 39, 0.92)) padding-box,
        linear-gradient(135deg, rgba(242, 201, 76, 0.24), rgba(14, 165, 233, 0.14)) border-box;
    border: 1px solid transparent;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6);
}

.surface--flat {
    background: var(--color-surface-1);
    border: 1px solid var(--color-border);
    box-shadow: none;
}

.surface--accent {
    border-color: rgba(245, 159, 11, 0.38);
    box-shadow: var(--shadow-md);
}

.surface__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.surface__title {
    font-size: var(--font-size-lg);
    margin: 0;
}

.surface__caption {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    margin: 0;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.stack-lg {
    gap: var(--space-5);
}

.chart-panel {
    gap: var(--space-3);
}

.chart-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.chart-panel__title {
    font-size: var(--font-size-lg);
    margin: 0;
}

.chart-panel__actions {
    display: flex;
    gap: var(--space-2);
}

.chart {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.chart--stacked {
    gap: var(--space-4);
}

.chart__series {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
}

.chart__series-title {
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.chart__group {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: var(--space-2);
}

.chart__group--stacked {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.chart__group-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    width: 100%;
    gap: var(--space-2);
}

.chart__label {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.chart__bar {
    position: relative;
    width: 100%;
    height: 10px;
    border-radius: var(--radius-pill);
    background: rgba(148, 163, 184, 0.16);
    overflow: hidden;
}

.chart__bar-fill {
    position: absolute;
    inset: 0;
    width: 0;
    background: linear-gradient(90deg, rgba(245, 159, 11, 0.8), rgba(249, 115, 22, 0.85));
    border-radius: var(--radius-pill);
    transition: width 0.24s ease;
}

.chart__bar-fill--engine {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.85), rgba(16, 185, 129, 0.85));
}

.chart__bar-fill--good {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.85), rgba(22, 163, 74, 0.9));
}

.chart__bar-fill--warning {
    background: linear-gradient(90deg, rgba(249, 168, 37, 0.9), rgba(234, 179, 8, 0.9));
}

.chart__bar-fill--critical {
    background: linear-gradient(90deg, rgba(248, 113, 113, 0.9), rgba(239, 68, 68, 0.95));
}

.chart__bar-fill--budget {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.85), rgba(56, 189, 248, 0.85));
}

.chart__bar-fill--profit {
    background: linear-gradient(90deg, rgba(249, 115, 22, 0.85), rgba(245, 59, 9, 0.85));
}

.chart__value {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
}

.chart-toggle-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 320px;
    overflow-y: auto;
    padding-right: var(--space-2);
}

.chart-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.chart-toggle__input {
    width: 16px;
    height: 16px;
    accent-color: var(--color-accent);
}

.chart-toggle__label {
    line-height: 1.3;
}

.channel-summary {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
}

.channel-summary__row {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-size-sm);
    gap: var(--space-2);
}

.channel-summary__label {
    color: var(--color-text-secondary);
}

.channel-summary__value {
    font-family: var(--font-mono);
}

.row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.toolbar__actions {
    display: flex;
    gap: var(--space-2);
}

/* Form controls */
label {
    font-weight: 600;
    font-size: var(--font-size-sm);
}

input,
select,
textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface-2);
    color: var(--color-text-primary);
    font: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: rgba(56, 189, 248, 0.7);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

input[disabled],
select[disabled],
textarea[disabled] {
    background: rgba(245, 159, 11, 0.08);
    color: var(--color-text-secondary);
    border-color: rgba(148, 163, 184, 0.4);
    opacity: 1;
    cursor: not-allowed;
}

input.bg-gray-700:disabled,
select.bg-gray-700:disabled,
textarea.bg-gray-700:disabled {
    background: rgba(245, 159, 11, 0.18) !important;
    color: var(--color-text-secondary) !important;
}

.form-grid {
    display: grid;
    gap: var(--space-4);
}

.form-grid--cols-2 {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-grid--cols-3 {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.form-toggle {
    font-size: var(--font-size-sm);
}

.form-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--color-accent);
    border-radius: 4px;
}

.form-toggle .helper-text {
    font-size: var(--font-size-sm);
    margin: 0;
}

.form-lock-note {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    border-left: 3px solid var(--color-accent);
    background: rgba(245, 159, 11, 0.12);
    color: var(--color-text-secondary);
}

.form-lock-note strong {
    color: var(--color-accent);
}

form hr {
    margin: var(--space-4) 0;
}

.helper-text {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

/* Buttons */
button,
.btn {
    appearance: none;
    border: none;
    border-radius: var(--radius-pill);
    padding: var(--space-2) var(--space-4);
    font-weight: 600;
    letter-spacing: 0.01em;
    background: var(--color-accent);
    color: var(--color-inverse);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button:hover,
.btn:hover {
    background: var(--color-accent-strong);
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(249, 115, 22, 0.24);
}

button:active,
.btn:active {
    transform: translateY(0);
}

button[disabled],
.btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.btn--subtle {
    background: rgba(148, 163, 184, 0.18);
    color: var(--color-text-primary);
    box-shadow: none;
}

.btn--subtle:hover {
    background: rgba(148, 163, 184, 0.28);
    box-shadow: none;
}

.btn--ghost {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    box-shadow: none;
}

.btn--ghost:hover {
    border-color: rgba(56, 189, 248, 0.6);
    color: var(--color-info);
}

.btn--danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.btn--danger:hover {
    box-shadow: 0 10px 24px rgba(239, 68, 68, 0.35);
}

.btn--success {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

/* Badges & pills */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0 var(--space-2);
    height: 1.75rem;
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    background: rgba(148, 163, 184, 0.16);
    color: var(--color-text-secondary);
}

.badge--accent {
    background: rgba(245, 159, 11, 0.15);
    color: var(--color-accent);
}

.badge--success {
    background: rgba(34, 197, 94, 0.16);
    color: var(--color-positive);
}

.badge--danger {
    background: rgba(239, 68, 68, 0.16);
    color: var(--color-destructive);
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface-2);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table thead {
    background: rgba(15, 23, 42, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: var(--font-size-xs);
    color: var(--color-muted);
}

.table th,
.table td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    vertical-align: middle;
}

.table tbody tr {
    transition: background 0.18s ease;
}

.table tbody tr:hover {
    background: rgba(59, 130, 246, 0.07);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table__numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.table__monospace {
    font-family: var(--font-mono);
}

.state-up {
    color: var(--color-positive);
}

.state-down {
    color: var(--color-destructive);
}

/* Dialogs */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 26, 0.76);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    padding: var(--space-4);
}

.modal {
    background: var(--color-surface-1);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(148, 163, 184, 0.18);
    width: min(420px, 95vw);
    padding: var(--space-6);
    box-shadow: var(--shadow-lg);
    position: relative;
}

.modal h2 {
    margin-top: 0;
    font-size: var(--font-size-lg);
}

.modal .close {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
}

/* Login layout helper */
.page-centered {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
}

.auth-card {
    width: min(420px, 92vw);
    background: rgba(15, 23, 42, 0.88);
    border-radius: var(--radius-lg);
    padding: var(--space-8) var(--space-6);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(56, 189, 248, 0.14);
}

.auth-card h1 {
    margin: 0 0 var(--space-4);
    font-size: var(--font-size-xl);
}

.auth-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.auth-actions .btn {
    flex: 1;
}

.auth-card__submit {
    align-self: center;
    min-width: 11rem;
}

/* Cards inside dense grids */
.mini-stat {
    padding: var(--space-4);
    background: rgba(30, 64, 175, 0.12);
    border-radius: var(--radius);
    border: 1px solid rgba(56, 189, 248, 0.18);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.mini-stat__value {
    font-size: var(--font-size-xl);
    font-family: var(--font-mono);
}

/* Responsive tweaks */
@media (max-width: 768px) {
    .app-shell {
        padding: var(--space-5) var(--space-3) var(--space-8);
    }

    .surface,
    .card,
    .panel {
        padding: var(--space-5);
    }

    .toolbar {
        align-items: stretch;
    }

    .toolbar__actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* Server monitoring layout helpers */
[v-cloak] {
    display: none;
}

.log-picker {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: stretch;
}

.log-button {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 180px;
    background-color: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(71, 85, 105, 0.8);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    text-align: left;
    gap: 0.25rem;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.log-button:hover {
    border-color: rgba(129, 140, 248, 0.9);
    transform: translateY(-1px);
}

.log-button--active {
    border-color: rgba(250, 204, 21, 0.9);
    box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.3);
}

.log-viewer {
    min-height: 320px;
    overflow-y: auto;
    background-color: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(71, 85, 105, 0.6);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    font-family: "Fira Code", "Source Code Pro", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.log-viewer__pre {
    margin: 0;
    white-space: pre-wrap;
}

.log-viewer-card {
    grid-column: 1 / -1;
    width: min(90vw, 1800px);
    margin: 0 auto;
    padding-left: var(--space-6);
    padding-right: var(--space-6);
    box-sizing: border-box;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Tailwind utility overrides for legacy templates */
.bg-gray-900 {
    background: var(--color-bg) !important;
}

.bg-gray-800 {
    background: var(--color-surface-1) !important;
}

.bg-gray-700 {
    background: var(--color-surface-2) !important;
}

.bg-gray-600 {
    background: rgba(148, 163, 184, 0.12) !important;
}

.border-gray-700,
.border-gray-600,
.border-gray-500 {
    border-color: var(--color-border) !important;
}

.text-gray-400 {
    color: var(--color-text-secondary) !important;
}

.text-gray-200 {
    color: var(--color-text-primary) !important;
}

.text-yellow-300,
.text-yellow-400 {
    color: var(--color-accent) !important;
}

.text-blue-300 {
    color: var(--color-info) !important;
}

.text-green-400 {
    color: var(--color-positive) !important;
}

.text-red-400 {
    color: var(--color-destructive) !important;
}

.bg-yellow-500,
.bg-yellow-600,
.hover\:bg-yellow-600:hover,
.hover\:bg-yellow-500:hover {
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-strong)) !important;
    color: var(--color-inverse) !important;
}

.bg-green-600,
.bg-green-500,
.hover\:bg-green-700:hover,
.hover\:bg-green-600:hover {
    background: linear-gradient(135deg, #22c55e, #16a34a) !important;
    color: #051221 !important;
}

.bg-red-600,
.hover\:bg-red-700:hover {
    background: linear-gradient(135deg, #ef4444, #dc2626) !important;
}

.text-red-500 {
    color: rgba(248, 113, 113, 0.92) !important;
}
