:root {
    color-scheme: dark;
    --bg: #07111f;
    --bg-soft: #0b1728;
    --panel: rgba(13, 27, 46, 0.92);
    --panel-strong: #10233a;
    --border: rgba(148, 163, 184, 0.18);
    --text: #eef6ff;
    --muted: #91a4ba;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --rx: #22d3ee;
    --tx: #a78bfa;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #fb7185;
    --shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 0%, rgba(14, 165, 233, 0.16), transparent 28rem),
        radial-gradient(circle at 96% 8%, rgba(139, 92, 246, 0.12), transparent 26rem),
        linear-gradient(180deg, #07111f 0%, #081524 100%);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.eyebrow {
    margin: 0 0 0.35rem;
    color: var(--accent);
    font-size: 0.73rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.45rem, 2.2vw, 2.15rem); }
h2 { margin-bottom: 0; font-size: clamp(1.05rem, 1.6vw, 1.35rem); }

.btn {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 11px;
    padding: 0.68rem 1rem;
    color: var(--text);
    font-weight: 750;
    transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible {
    outline: 3px solid rgba(56, 189, 248, 0.24);
    outline-offset: 2px;
}
.btn-primary { background: linear-gradient(135deg, var(--accent-strong), #2563eb); }
.btn-primary:hover { background: linear-gradient(135deg, #38bdf8, #3b82f6); }
.btn-secondary { background: rgba(148, 163, 184, 0.08); border-color: var(--border); }
.btn-secondary:hover { background: rgba(148, 163, 184, 0.15); }
.btn-full { width: 100%; }

input, select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.68rem 0.78rem;
    color: var(--text);
    background: rgba(3, 11, 22, 0.52);
}
select option { background: #0c1a2c; }
label { color: #c9d7e6; font-size: 0.83rem; font-weight: 700; }
small { color: var(--muted); }

/* Login */
.login-body { display: grid; place-items: center; padding: 1.25rem; }
.login-shell { width: min(100%, 430px); }
.login-card {
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: clamp(1.5rem, 5vw, 2.5rem);
    background: linear-gradient(160deg, rgba(16, 35, 58, .98), rgba(8, 21, 36, .96));
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}
.brand-mark { display: flex; align-items: flex-end; gap: 5px; height: 34px; margin-bottom: 1.5rem; }
.brand-mark span { display: block; width: 8px; border-radius: 999px; background: linear-gradient(180deg, var(--rx), var(--accent-strong)); }
.brand-mark span:nth-child(1) { height: 13px; }
.brand-mark span:nth-child(2) { height: 24px; }
.brand-mark span:nth-child(3) { height: 34px; }
.login-subtitle { margin: .7rem 0 1.55rem; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: .7rem; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 5.5rem; }
.password-toggle {
    position: absolute; right: .45rem; top: 50%; transform: translateY(-50%);
    border: 0; border-radius: 8px; padding: .42rem .62rem;
    background: rgba(148, 163, 184, .12); color: #d8e6f5; font-size: .78rem; font-weight: 750;
}
.login-form .btn { margin-top: .4rem; }
.login-foot { margin: 1.35rem 0 0; color: var(--muted); font-size: .8rem; text-align: center; }
.alert { border-radius: 11px; padding: .8rem .9rem; margin-bottom: 1.1rem; font-size: .9rem; }
.alert-error { border: 1px solid rgba(251, 113, 133, .35); background: rgba(159, 18, 57, .18); color: #fecdd3; }

/* Dashboard */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem max(1rem, calc((100vw - 1500px) / 2));
    border-bottom: 1px solid var(--border);
    background: rgba(7, 17, 31, .88);
    backdrop-filter: blur(18px);
}
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.user-chip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #bfd0e2; font-size: .86rem; }
.dashboard { width: min(1500px, calc(100% - 2rem)); margin: 1rem auto 3rem; display: grid; gap: 1rem; }
.panel, .metric-card {
    border: 1px solid var(--border);
    border-radius: 17px;
    background: linear-gradient(155deg, rgba(16, 35, 58, .91), rgba(10, 24, 41, .92));
    box-shadow: 0 14px 38px rgba(0, 0, 0, .15);
}
.control-panel { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.25rem; padding: 1rem; }
.field-group { display: grid; gap: .4rem; min-width: 150px; }
.field-grow { width: min(580px, 100%); }
.connection-state { display: flex; align-items: center; gap: .75rem; min-width: 190px; padding: .7rem .85rem; border-radius: 12px; background: rgba(3, 11, 22, .35); }
.connection-state strong, .connection-state small { display: block; }
.connection-state strong { font-size: .9rem; }
.connection-state small { margin-top: .18rem; font-size: .75rem; }
.status-dot { width: 12px; height: 12px; flex: 0 0 12px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 5px rgba(251, 191, 36, .1); }
.status-dot.is-up { background: var(--success); box-shadow: 0 0 0 5px rgba(52, 211, 153, .1); }
.status-dot.is-down { background: var(--danger); box-shadow: 0 0 0 5px rgba(251, 113, 133, .1); }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1rem; }
.metric-card { min-height: 135px; padding: 1rem; display: flex; flex-direction: column; justify-content: space-between; }
.metric-card span { color: #a9bbce; font-size: .78rem; font-weight: 720; text-transform: uppercase; letter-spacing: .06em; }
.metric-card strong { margin: .65rem 0 .45rem; font-size: clamp(1.2rem, 1.75vw, 1.75rem); line-height: 1.1; overflow-wrap: anywhere; }
.metric-card:nth-child(1) strong, .legend-rx { color: var(--rx); }
.metric-card:nth-child(2) strong, .legend-tx { color: var(--tx); }

.chart-panel, .history-panel, .technical-panel { padding: 1rem; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .8rem; }
.legend-inline { display: inline-flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .78rem; }
.legend-inline i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: .4rem; }
.legend-rx { background: var(--rx); }
.legend-tx { background: var(--tx); }
.chart-wrap { position: relative; width: 100%; overflow: hidden; border-radius: 12px; background: rgba(3, 11, 22, .28); }
.chart-realtime { height: 330px; }
.chart-history { height: 390px; }
canvas { display: block; width: 100%; height: 100%; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 1rem; color: var(--muted); text-align: center; pointer-events: none; }
.chart-empty.is-hidden { display: none; }

.history-heading { align-items: flex-end; }
.filters { display: flex; align-items: flex-end; flex-wrap: wrap; justify-content: flex-end; gap: .65rem; }
.filters .field-group { width: 150px; }
.filter-button { min-width: 110px; }
.period-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: .85rem; }
.period-summary > div, .technical-grid > div { border: 1px solid rgba(148, 163, 184, .12); border-radius: 12px; padding: .8rem; background: rgba(3, 11, 22, .28); }
.period-summary span, .technical-grid span { display: block; color: var(--muted); font-size: .75rem; }
.period-summary strong, .technical-grid strong { display: block; margin-top: .35rem; font-size: 1.05rem; }
.chart-note { min-height: 1.2rem; margin: .65rem 0 0; color: var(--muted); font-size: .78rem; }
.technical-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .75rem; }

@media (max-width: 1200px) {
    .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .technical-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .history-heading { align-items: flex-start; flex-direction: column; }
    .filters { width: 100%; justify-content: flex-start; }
}

@media (max-width: 720px) {
    .topbar { position: static; align-items: flex-start; }
    .topbar-actions { align-items: flex-end; flex-direction: column; }
    .user-chip { display: none; }
    .dashboard { width: min(100% - 1rem, 1500px); margin-top: .5rem; }
    .control-panel { align-items: stretch; flex-direction: column; }
    .connection-state { min-width: 0; }
    .metric-grid, .period-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .technical-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .panel-heading { align-items: flex-start; flex-direction: column; }
    .filters { display: grid; grid-template-columns: 1fr 1fr; }
    .filters .field-group, .filter-button { width: 100%; min-width: 0; }
    .chart-realtime { height: 285px; }
    .chart-history { height: 330px; }
}

@media (max-width: 430px) {
    .metric-grid, .period-summary, .technical-grid, .filters { grid-template-columns: 1fr; }
    .topbar { padding: .85rem; }
    .btn-secondary { padding-inline: .75rem; }
}
