/* Smug Dash — theme + layout (phase 2 shell) */

:root {
    --bg:        #0D0C1F;
    --surface:   #12112A;
    --surface-2: #1A1940;
    --border:    #262550;
    --primary:   #8C8CD0;
    --primary-2: #B3A6EC;
    --accent:    #CACAE6;
    --text:      #FFFFFF;
    --text-dim:  #FFFFFF;
    --muted:     #FFFFFF;
    --good:      #4ADE80;
    --bad:       #F87171;
    --radius:    12px;
    --gap:       16px;
    --topbar-h:  76px;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must win over the explicit display values below
   (an author `display` otherwise overrides the UA [hidden] { display:none } rule). */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    /* Page itself never scrolls horizontally */
    overflow-x: hidden;
}

h1, h2 { font-weight: 600; }

button {
    font-family: inherit;
    cursor: pointer;
}

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

/* ---------- Login ---------- */
.login-overlay {
    position: fixed;
    inset: 0;
    background: radial-gradient(1200px 600px at 50% -10%, #1A1940 0%, var(--bg) 60%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 32px;
    width: 360px;
    max-width: 90vw;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.login-logo { height: 132px; margin-bottom: 18px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { color: var(--text-dim); margin: 0 0 20px; font-size: 13px; }
.login-card input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: var(--primary-2); }
.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.15s ease;
}
.login-card button:hover { background: var(--primary-2); }
.login-msg { color: var(--bad); margin-top: 10px; min-height: 18px; font-size: 13px; }

/* ---------- App shell ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    height: var(--topbar-h);
    flex: 0 0 var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; cursor: pointer; }
.brand-logo { height: 60px; }
.brand-title { font-size: 18px; font-weight: 700; letter-spacing: 0.2px; align-self: flex-end; padding-bottom: 6px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.ghost-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13px;
}
.ghost-btn:hover { border-color: var(--primary-2); color: var(--text); }

/* ---------- Three columns ---------- */
.columns {
    flex: 0 0 auto;
    height: calc(100vh - var(--topbar-h));
    min-height: 0;
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr) 340px;
    gap: var(--gap);
    padding: var(--gap);
}

.widget {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.widget-head {
    flex: 0 0 auto;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.widget-head h2 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); }
.widget-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 16px;
}

.graph-head { justify-content: space-between; gap: 16px; }
.pill-slot { flex: 0 0 auto; min-width: 168px; }
.controls-slot { flex: 0 0 auto; min-width: 168px; display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.graph-title-wrap { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 0; }
.graph-title { font-size: 16px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.graph-optimised .dot { width: 11px; height: 11px; }

/* Live / Forecast pill */
.pill { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--bg); }
.pill-seg {
    appearance: none; border: none; background: transparent; color: var(--text-dim);
    padding: 7px 16px; font-size: 13px; font-weight: 600; cursor: pointer; transition: background 0.12s, color 0.12s;
}
.pill-seg + .pill-seg { border-left: 1px solid var(--border); }
.pill-seg.active { background: var(--primary); color: #fff; }
.pill-seg:disabled { color: #514F7A; cursor: not-allowed; }
.pill-seg:not(.active):not(:disabled):hover { background: var(--surface-2); color: var(--text); }

/* Graph controls (day picker, refresh) */
.controls-slot input[type="date"] {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 6px 9px; font-size: 13px; font-family: inherit;
    color-scheme: dark;
}
.controls-slot input[type="date"]:focus { outline: none; border-color: var(--primary-2); }
.fc-select {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 6px 9px; font-size: 13px; font-family: inherit;
    max-width: 130px;
}
.fc-select:focus { outline: none; border-color: var(--primary-2); }
.icon-btn {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text-dim); padding: 6px 10px; font-size: 13px;
}
.icon-btn:hover { border-color: var(--primary-2); color: var(--text); }
.auto-tag { font-size: 11px; color: var(--muted); white-space: nowrap; }
.auto-tag.live { color: var(--good); }

.chart-wrap { position: relative; width: 100%; height: 100%; min-height: 440px; }
.chart { width: 100%; height: 100%; min-height: 440px; }
.chart-message {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 14px; background: rgba(13,12,31,0.6); border-radius: 8px;
}

.placeholder {
    color: var(--muted);
    font-size: 13px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 18px;
    text-align: center;
    margin-top: 14px;
}

/* ---------- Selector (search + fleet) ---------- */
#selector-body {
    display: flex;
    flex-direction: column;
    overflow: hidden;        /* search stays put; the fleet list scrolls instead */
    padding: 14px;
    gap: 14px;
}
.search { flex: 0 0 auto; }
#site-search {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
}
#site-search:focus { outline: none; border-color: var(--primary-2); }
#selector-status { margin-top: 8px; font-size: 12px; }

.fleet {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.fleet-tabs {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0 8px;
    border-bottom: 1px solid var(--border);
}
.fleet-tab {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 4px 9px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.fleet-tab.active { background: var(--primary); color: #fff; }
.fleet-tab:not(.active):hover { background: var(--surface-2); color: var(--text); }
.fleet-count { margin-left: auto; font-size: 11px; }

.result-list { display: flex; flex-direction: column; gap: 6px; }
#search-results { margin-top: 10px; max-height: 40vh; overflow: auto; }
#fleet-list { flex: 1 1 auto; min-height: 0; overflow: auto; margin-top: 8px; }

.site-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 11px;
    color: var(--text);
    transition: border-color 0.12s ease, background 0.12s ease;
}
.site-row:hover { border-color: var(--primary-2); background: var(--surface-2); }
.site-row.is-selected { border-color: var(--primary-2); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--primary-2); }
.site-row .dot { flex: 0 0 auto; }
.site-row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.site-row-addr { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-row-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-row-brand { flex: 0 0 auto; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }

.list-empty { font-size: 12px; color: var(--muted); padding: 10px 2px; }

/* Stats / detail readout */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--text-dim); }
.kv .v { color: var(--text); font-weight: 600; text-align: right; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #4A4870; }
.dot.on { background: var(--good); box-shadow: 0 0 6px rgba(74,222,128,0.6); }
.freshness-live { display: inline-flex; align-items: center; gap: 6px; color: var(--good); font-weight: 600; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin: 16px 0 6px; }
.section-label:first-child { margin-top: 0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.on  { background: rgba(74,222,128,0.15); color: var(--good); }
.badge.off { background: rgba(110,108,149,0.18); color: var(--muted); }
.feat-val { color: var(--muted); font-size: 11px; margin-left: 8px; }
.kv .v.good { color: var(--good); }
.kv .v.bad { color: var(--bad); }
.kv .v.muted { color: var(--muted); font-weight: 400; }
.smug-bug-id { font-family: monospace; font-size: 11px; word-break: break-all; }

/* Expand-table toggle */
.table-toggle {
    width: 100%; margin-top: 16px; padding: 10px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
    color: var(--text); font-size: 13px; font-weight: 600;
}
.table-toggle:hover { border-color: var(--primary-2); }

/* ---------- Data table (below the layout) ---------- */
.data-table { padding: 0 var(--gap) var(--gap); }
.data-table-inner {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; overflow-x: auto;
}
.data-table h3 { margin: 0 0 12px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); }
.data-table table { width: 100%; border-collapse: collapse; font-size: 12px; white-space: nowrap; }
.data-table th, .data-table td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--border); }
.data-table th:first-child, .data-table td:first-child,
.data-table th:nth-child(2), .data-table td:nth-child(2) { text-align: left; }
.data-table th { background: var(--surface-2); color: var(--text-dim); font-weight: 600; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.pos { color: var(--good); }
.data-table td.neg { color: var(--bad); }
/* Intelligent go-period repriced this import slot to the (cheaper) go rate. */
.data-table td.go { color: var(--good); font-weight: 700; background: rgba(74,222,128,0.12); }

/* Scrollbars */
.widget-body::-webkit-scrollbar { width: 10px; height: 10px; }
.widget-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
.widget-body::-webkit-scrollbar-track { background: transparent; }

/* Narrow screens: stack columns */
@media (max-width: 1100px) {
    .columns {
        grid-template-columns: 1fr;
        grid-auto-rows: minmax(280px, auto);
        overflow: auto;
    }
}
