/* ========================================================================
   Dashboard — dark, futuristic, accessible theme
   - Slightly bigger base font (17px)
   - High contrast (severity colours vs card bg >= 4.5:1)
   - Focus always visible
   - Color never the only channel (every severity has a label + dot)
   - Respects prefers-reduced-motion
   ======================================================================== */

/* ----------------------------- Fonts (local) ---------------------------- */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('../fonts/InterVariable.woff2') format('woff2-variations'),
         url('../fonts/InterVariable.woff2') format('woff2');
}

@font-face {
    font-family: 'Orbitron';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/Orbitron-400.woff2') format('woff2');
}

@font-face {
    font-family: 'Orbitron';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/Orbitron-700.woff2') format('woff2');
}

/* ----------------------------- Tokens ----------------------------------- */
:root {
    --bg-0: #06080f;          /* page background */
    --bg-1: #0a0e1a;          /* card background */
    --bg-2: #111728;          /* nested card */
    --bg-3: #161d33;          /* hover/active */
    --border: #1f2740;
    --border-strong: #2a3656;

    --sev-err:  #ff5b5f;      /* red  */
    --sev-warn: #ffd60a;      /* yellow */
    --sev-info: #f5f7ff;      /* white */
    --sev-ok:   #34d27a;      /* green */

    --text:    #e7ecf5;
    --muted:   #98a1b8;
    --focus:   #66d9ff;
    --accent:  #66d9ff;

    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Orbitron', var(--font-body);

    --fs-base: 1.0625rem;     /* 17px */
    --fs-h1:   2rem;
    --fs-h2:   1.375rem;
    --fs-h3:   1.125rem;
    --fs-small: 0.875rem;

    --radius:   0.75rem;
    --radius-sm: 0.5rem;

    --glow: 0 0 0.75rem rgba(102, 217, 255, 0.18);
    --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 8px 24px rgba(0, 0, 0, 0.45);

    --tx: 160ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ----------------------------- Base ------------------------------------- */
* {
    box-sizing: border-box;
}

html, body {
    background: var(--bg-0);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--fs-base);
    line-height: 1.55;
    margin: 0;
    padding: 0;
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(102, 217, 255, 0.06), transparent 60%),
        radial-gradient(1000px 500px at 110% 10%, rgba(255, 90, 95, 0.05), transparent 60%),
        var(--bg-0);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    letter-spacing: 0.02em;
    line-height: 1.2;
    margin: 0;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

p {
    margin: 0;
}

.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}

/* Focus is always visible. High contrast. */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 0.25rem;
}

/* ----------------------------- Header ----------------------------------- */
.app-header {
    padding: 1.5rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    background:
        linear-gradient(180deg, rgba(255,255,255,0.02), transparent),
        var(--bg-0);
}

.app-header-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-start;
    justify-content: space-between;
    max-width: 1400px;
    margin: 0 auto;
}

.app-brand {
    flex: 1 1 auto;
    min-width: 240px;
}

.app-name {
    font-size: var(--fs-h1);
    color: var(--text);
    text-shadow: 0 0 0.5rem rgba(102, 217, 255, 0.25);
}

.app-tagline {
    color: var(--muted);
    font-size: var(--fs-base);
    margin-top: 0.25rem;
}

.app-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-end;
}

.status-legend {
    display: inline-flex;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-1);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-size: var(--fs-small);
    color: var(--muted);
}

.lang-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--fs-small);
    color: var(--muted);
}

.lang-label {
    margin-right: 0.25rem;
}

.lang-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    padding: 0.2rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: var(--bg-1);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: var(--fs-small);
    transition: background var(--tx), border-color var(--tx);
}

.lang-chip:hover {
    text-decoration: none;
    background: var(--bg-3);
    border-color: var(--border-strong);
}

.lang-chip.is-active {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: var(--glow);
}

.app-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 1400px;
    margin: 0.75rem auto 0;
    color: var(--muted);
    font-size: var(--fs-small);
}

.last-update {
    display: inline-flex;
    align-items: baseline;
    gap: 0.4rem;
}

.last-update-label {
    color: var(--muted);
}

#last-update {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

#spinner.htmx-indicator {
    opacity: 0;
    transition: opacity var(--tx);
}

#spinner.htmx-indicator.htmx-request {
    opacity: 1;
}

/* ----------------------------- Main grid -------------------------------- */
.app-main {
    padding: 1.25rem;
    max-width: 1400px;
    margin: 0 auto;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 768px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* ----------------------------- Cards ------------------------------------ */
.card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    transition: border-color var(--tx), transform var(--tx);
}

.card:hover {
    border-color: var(--border-strong);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
}

.server-card .card-header {
    position: relative;
}

.server-card {
    border-left-width: 3px;
}

.server-card.sev-err  { border-left-color: var(--sev-err);  }
.server-card.sev-warn { border-left-color: var(--sev-warn); }
.server-card.sev-info { border-left-color: var(--sev-info); }
.server-card.sev-ok   { border-left-color: var(--sev-ok);   }

.server-name, .vm-name {
    font-size: var(--fs-h2);
    color: var(--text);
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vm-name {
    font-size: var(--fs-h3);
    color: var(--text);
}

.server-label, .vm-label {
    color: var(--muted);
    font-family: var(--font-body);
    font-size: var(--fs-small);
    font-weight: 400;
    letter-spacing: 0;
    text-transform: uppercase;
}

.server-id, .vm-id {
    font-family: var(--font-display);
    letter-spacing: 0.04em;
    overflow: hidden;
    text-overflow: ellipsis;
}

.severity-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    font-size: var(--fs-small);
    font-weight: 600;
    border: 1px solid transparent;
    background: var(--bg-3);
    color: var(--text);
    white-space: nowrap;
}

.badge-dot {
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0.5rem currentColor;
}

.severity-badge.sev-err  { color: var(--sev-err);  border-color: rgba(255, 91, 95, 0.35);  background: rgba(255, 91, 95, 0.08);  }
.severity-badge.sev-warn { color: var(--sev-warn); border-color: rgba(255, 214, 10, 0.35); background: rgba(255, 214, 10, 0.08); }
.severity-badge.sev-info { color: var(--sev-info); border-color: rgba(245, 247, 255, 0.25); background: rgba(245, 247, 255, 0.05); }
.severity-badge.sev-ok   { color: var(--sev-ok);   border-color: rgba(52, 210, 122, 0.35);  background: rgba(52, 210, 122, 0.08);  }

.card-body {
    padding: 0.75rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.messages {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ----------------------------- VM sub-card ------------------------------ */
.vm-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.vm-card .card-header {
    padding: 0.6rem 0.75rem;
    background: var(--bg-3);
}

.vm-card .messages {
    padding: 0.5rem 0.75rem 0.75rem;
}

/* ----------------------------- Messages --------------------------------- */
.msg {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    background: var(--bg-1);
    border: 1px solid transparent;
    font-variant-numeric: tabular-nums;
}

.msg:hover {
    background: var(--bg-2);
}

.msg-time {
    color: var(--muted);
    font-size: var(--fs-small);
    white-space: nowrap;
}

.msg-time time {
    color: var(--muted);
}

.msg-text {
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.msg-simple.sev-err  .msg-text { color: var(--sev-err);  }
.msg-simple.sev-warn .msg-text { color: var(--sev-warn); }
.msg-simple.sev-info .msg-text { color: var(--sev-info); }
.msg-simple.sev-ok   .msg-text { color: var(--sev-ok);   }

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

.msg-simple .msg-time {
    grid-column: 1;
    grid-row: 1;
}

.msg-simple .msg-text {
    grid-column: 2;
    grid-row: 1;
}

/* ----------------------------- Meter ------------------------------------ */
.msg-meter {
    grid-template-columns: 1fr;
    gap: 0.4rem;
    padding: 0.55rem 0.7rem;
    background: var(--bg-2);
}

.meter-label {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
}

.meter-source {
    color: var(--accent);
    font-family: var(--font-display);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: var(--fs-small);
    white-space: nowrap;
}

.meter-sep {
    color: var(--muted);
}

.meter-desc {
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    font-size: var(--fs-small);
}

.msg-meter.sev-err  .meter-desc { color: var(--sev-err);  }
.msg-meter.sev-warn .meter-desc { color: var(--sev-warn); }
.msg-meter.sev-info .meter-desc { color: var(--sev-info); }
.msg-meter.sev-ok   .meter-desc { color: var(--sev-ok);   }

.meter-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.6rem;
    font-size: var(--fs-small);
    color: var(--muted);
}

.meter-value {
    color: var(--sev-ok);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-width: 3.5ch;
    text-align: right;
}

.msg-meter.meter-over .meter-value {
    color: var(--sev-warn);
}

.meter-bar {
    position: relative;
    height: 0.5rem;
    background: var(--sev-err);
    border-radius: 999px;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.meter-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--sev-ok) 0%, #6cf2a3 100%);
    box-shadow: 0 0 0.5rem var(--sev-ok);
    transition: width 320ms cubic-bezier(0.2, 0.7, 0.2, 1);
    border-radius: 999px;
}

.meter-max {
    color: var(--sev-err);
    font-variant-numeric: tabular-nums;
    min-width: 3.5ch;
    text-align: left;
}

.msg-time {
    justify-self: end;
}

.msg-meter .msg-time {
    grid-column: 1;
    grid-row: 3;
    justify-self: end;
}

/* ----------------------------- Empty state ------------------------------ */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 1rem;
    color: var(--sev-ok);
}

.check-glow {
    width: 5rem;
    height: 5rem;
    color: var(--sev-ok);
    filter: drop-shadow(0 0 0.75rem var(--sev-ok));
    animation: pulse 2.4s ease-in-out infinite;
}

.empty-text {
    margin-top: 1rem;
    color: var(--sev-ok);
    font-family: var(--font-display);
    letter-spacing: 0.05em;
    font-size: var(--fs-h2);
}

@keyframes pulse {
    0%, 100% { transform: scale(1);   opacity: 1;   }
    50%      { transform: scale(1.04); opacity: 0.85; }
}

/* ----------------------------- Footer ----------------------------------- */
.app-footer {
    text-align: center;
    padding: 1.5rem 1rem 2rem;
    color: var(--muted);
    font-size: var(--fs-small);
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

/* ----------------------------- Bootstrap tooltip tweaks ----------------- */
.tooltip {
    font-size: var(--fs-small);
}

.tooltip-inner {
    background: var(--bg-3);
    color: var(--text);
    border: 1px solid var(--border-strong);
    max-width: 28rem;
    text-align: left;
}

/* ----------------------------- Spinner ---------------------------------- */
.spinner-border {
    width: 1rem;
    height: 1rem;
    border-width: 0.15rem;
}

/* ----------------------------- Reduced motion --------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
    .check-glow {
        animation: none;
    }
}

/* ----------------------------- Mobile fine-tuning ----------------------- */
@media (max-width: 480px) {
    .app-name { font-size: 1.5rem; }
    .server-name, .vm-name { font-size: 1.1rem; }
    .card-header { padding: 0.7rem 0.8rem; }
    .meter-value, .meter-max { min-width: 3ch; }
}
