/* WifiSpy provisioning UI — dark theme, single-page. */

:root {
    --bg:           #0e1116;
    --bg-card:      #161b22;
    --bg-soft:      #1f2531;
    --border:       #2a313d;
    --border-soft:  #232936;
    --text:         #e6edf3;
    --text-muted:   #8b97a7;
    --text-dim:     #6b7585;
    --accent:       #58a6ff;
    --accent-soft:  rgba(88,166,255,.15);
    --ok:           #56d364;
    --warn:         #f0a050;
    --err:          #f85149;
    --radius:       10px;
    --radius-sm:    6px;
    --mono:         ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}

* { box-sizing: border-box; }

html, body { background: var(--bg); color: var(--text);
             font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
             font-size: 14px; line-height: 1.45; margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); background: var(--bg-soft);
       padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.mono { font-family: var(--mono); }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.row { display: inline-flex; gap: .5rem; align-items: center; }

/* --- top bar ----------------------------------------------------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .85rem 1.25rem; border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #131820 0%, #0e1116 100%);
}
.topbar-brand { display: flex; align-items: baseline; gap: .65rem; }
.topbar-brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: .02em; }
.tagline { font-size: 12px; }
.logo-dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #7ec7ff, #1f6feb);
    box-shadow: 0 0 12px rgba(88,166,255,.6);
}
.topbar-actions { display: flex; align-items: center; gap: .85rem; }
.topbar-actions input[type=password] {
    background: var(--bg-soft); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius-sm);
    padding: .35rem .55rem; font-size: 12px; min-width: 180px;
}
.inline-label { display: flex; align-items: center; gap: .35rem; }

/* --- buttons / badges ------------------------------------------- */
button { font: inherit; cursor: pointer; border-radius: var(--radius-sm);
         padding: .5rem .9rem; border: 1px solid transparent;
         transition: background .12s, border-color .12s; }
button:disabled { opacity: .45; cursor: not-allowed; }

.primary { background: var(--accent); color: #0a1320;
           border-color: var(--accent); font-weight: 600; }
.primary:hover:not(:disabled) { background: #79bbff; }

.ghost { background: transparent; color: var(--text);
         border-color: var(--border); }
.ghost:hover:not(:disabled) { background: var(--bg-soft);
                              border-color: #3a4452; }

.icon-btn { padding: .35rem .55rem; font-size: 14px; line-height: 1; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px;
         font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
         font-weight: 600; }
.badge-off { background: #2a313d; color: var(--text-muted); }
.badge-on  { background: rgba(86,211,100,.18); color: var(--ok); }
.badge-warn{ background: rgba(240,160,80,.18);  color: var(--warn); }

.conn-block { display: flex; align-items: center; gap: .35rem; }
.conn-substate { font-size: 11px; color: var(--text-dim); }

/* --- hero -------------------------------------------------------- */
.hero { padding: 2.25rem 1.25rem 1.5rem; }
.hero-card {
    max-width: 760px; margin: 0 auto;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 2.25rem 2rem;
    box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.hero-inner { display: flex; flex-direction: column; align-items: center;
              text-align: center; gap: 1rem; }
.hero-icon {
    width: 64px; height: 64px; border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #79bbff, #1f6feb);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 30px rgba(88,166,255,.35);
}
.hero-icon-dot {
    width: 16px; height: 16px; border-radius: 50%; background: #fff;
    opacity: .9;
}
.hero-title { margin: .25rem 0 0; font-size: 1.5rem; max-width: 28ch; }
.hero-sub { margin: 0; max-width: 50ch; color: var(--text-muted); }
.hero-sub-soft { color: var(--text-dim); font-size: 13px; }
.hero-btn { padding: .7rem 1.4rem; font-size: 15px; margin-top: .25rem; }
.hero-btn-icon { margin-right: .35rem; }
.hero-status { margin: 0; min-height: 1.2em; }

.hero-features {
    list-style: none; padding: 0; margin: 1rem 0 .25rem; width: 100%;
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: .75rem;
}
.hero-features li {
    background: var(--bg-soft); border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm); padding: .75rem .85rem;
    display: flex; gap: .65rem; align-items: flex-start; text-align: left;
}
.hero-feat-icon { font-size: 18px; line-height: 1; flex-shrink: 0; }
@media (max-width: 720px) {
    .hero-features { grid-template-columns: 1fr; }
    .hero-card { padding: 1.5rem 1rem; }
}
.hero-help { margin-top: .75rem; width: 100%; text-align: left; }
.hero-help summary { cursor: pointer; color: var(--text-muted); }
.hero-help ul { color: var(--text-muted); margin: .5rem 0 0 1rem; padding: 0; }

/* --- layout ------------------------------------------------------ */
.layout {
    display: none; padding: 1rem 1.25rem;
    grid-template-columns: 1fr 1fr; gap: 1rem; max-width: 1100px; margin: 0 auto;
}
.layout.show { display: grid; }
.card-wide { grid-column: 1 / -1; }

.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.15rem;
}
.card-header { display: flex; justify-content: space-between;
               align-items: center; margin-bottom: .65rem; }
.card-header h2 { margin: 0; font-size: 1rem; letter-spacing: .02em; }

/* --- collapsible cards (<details class="card-collapsible">) -------- */
.card-collapsible { padding: 0; }
.card-collapsible > summary {
    cursor: pointer; padding: .75rem 1.15rem; margin: 0;
    list-style: none; user-select: none;
}
.card-collapsible > summary::-webkit-details-marker { display: none; }
.card-collapsible > summary:hover { background: rgba(255,255,255,.02); }
.card-collapsible[open] > summary {
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 0;
}
.card-collapsible > .card-body { padding: .85rem 1.15rem 1rem; }
.card-caret {
    display: inline-block; color: var(--text-dim); transition: transform .15s;
    font-size: 14px; margin-left: .35rem;
}
.card-collapsible[open] > summary .card-caret { transform: rotate(90deg); }

.wifi-controls { margin-bottom: .65rem; }
.log-toolbar   { margin-bottom: .55rem; }

/* status KV table */
.kv { display: grid; grid-template-columns: 110px 1fr;
      column-gap: .9rem; row-gap: .35rem; margin: 0; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; }

/* wifi list */
.wifi-list { list-style: none; margin: 0; padding: 0;
             border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
             max-height: 320px; overflow: auto; }
.wifi-list li { padding: .55rem .8rem; border-bottom: 1px solid var(--border-soft);
                display: flex; justify-content: space-between; align-items: center;
                cursor: pointer; gap: .5rem; }
.wifi-list li:last-child { border-bottom: none; }
.wifi-list li:hover { background: var(--bg-soft); }
.wifi-list .wifi-empty { color: var(--text-muted); cursor: default; }
.wifi-list .wifi-empty:hover { background: transparent; }
.wifi-ssid { font-weight: 500; }
.wifi-meta { color: var(--text-dim); font-size: 12px; font-family: var(--mono); }
.wifi-in-use::after {
    content: "in use"; font-size: 10px; margin-left: .5rem;
    color: var(--ok); border: 1px solid currentColor;
    border-radius: 4px; padding: 0 4px;
}

.hidden-net { margin-top: .75rem; }
.hidden-net summary { cursor: pointer; color: var(--text-muted); }
.hidden-net summary .caret { display: inline-block; transition: transform .15s; }
.hidden-net[open] summary .caret { transform: rotate(90deg); }
.hidden-net-body { padding-top: .5rem; }

.hint { margin: 0 0 .5rem; }

/* --- log --------------------------------------------------------- */
.log-section { padding: 1rem 1.25rem 2rem; max-width: 1100px;
               margin: 0 auto; }
.log-panel {
    background: #0a0d12; border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm); padding: .55rem .65rem;
    height: 260px; overflow: auto;
    font-family: var(--mono); font-size: 12px; line-height: 1.5;
}
.log-row { display: block; }
.log-ts  { color: var(--text-dim); margin-right: .35rem; }
.log-lvl { font-weight: bold; margin-right: .35rem; }
.log-extra {
    background: #060a0e; margin: .25rem 0 .5rem 4ch;
    padding: .35rem .5rem; border-radius: 4px;
    color: var(--text-muted); font-size: 11px; white-space: pre-wrap;
}

/* --- modal ------------------------------------------------------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.55);
    display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 0; min-width: 360px;
    max-width: 95vw;
}
.modal-header { display: flex; justify-content: space-between; align-items: center;
                padding: .9rem 1.1rem; border-bottom: 1px solid var(--border-soft); }
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-body { padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .85rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem;
                 margin-top: .25rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field-label { color: var(--text-muted); font-size: 12px; }
.field input[type=text], .field input[type=password] {
    background: var(--bg-soft); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius-sm);
    padding: .5rem .65rem; font: inherit;
}
.field-row { display: flex; align-items: center; gap: .5rem; }
.pass-wrap { display: flex; gap: .35rem; }
.pass-wrap input { flex: 1; }
.pass-toggle { background: transparent; color: var(--text-muted);
               border: 1px solid var(--border); border-radius: var(--radius-sm);
               padding: 0 .6rem; font-size: 12px; }
.modal-error {
    display: flex; gap: .6rem; align-items: flex-start;
    background: rgba(248,81,73,.1); border: 1px solid rgba(248,81,73,.4);
    color: var(--err); border-radius: var(--radius-sm); padding: .55rem .7rem;
}
.modal-error-icon { font-size: 16px; }
.modal-error-title { font-weight: 600; font-size: 13px; }
.modal-error-msg { font-size: 12px; color: var(--text-muted); }

[hidden] { display: none !important; }

/* --- state pill (inline status indicator) ----------------------- */
.state-pill {
    display: inline-block; padding: 1px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 600; letter-spacing: .04em;
    text-transform: uppercase;
}
.state-pill-off  { background: #2a313d; color: var(--text-muted); }
.state-pill-on   { background: rgba(86,211,100,.18);  color: var(--ok); }
.state-pill-warn { background: rgba(240,160,80,.18);  color: var(--warn); }
.state-pill-err  { background: rgba(248,81,73,.18);   color: var(--err); }

/* --- card-internal text inputs (creds editor) ------------------- */
.card .field { display: flex; flex-direction: column; gap: .25rem;
               margin-top: .55rem; }
.card .field input[type=text],
.card .field input[type=password] {
    background: var(--bg-soft); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius-sm);
    padding: .45rem .6rem; font: inherit; font-family: var(--mono); font-size: 12px;
}
.card-actions { flex-wrap: wrap; }

/* --- phase list (modal connect progress) ------------------------ */
.phase-list {
    list-style: none; margin: .25rem 0 0; padding: 0;
    display: flex; flex-direction: column; gap: .35rem;
    font-size: 13px;
}
.phase-list li {
    display: flex; align-items: center; gap: .55rem;
    color: var(--text-muted);
}
.phase-dot {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
    background: var(--border); border: 1px solid var(--border);
    flex-shrink: 0;
}
.phase-active        { color: var(--text); }
.phase-active .phase-dot {
    background: var(--warn);
    box-shadow: 0 0 0 4px rgba(240,160,80,.18);
    animation: phase-pulse 1.2s infinite;
}
.phase-done          { color: var(--text); }
.phase-done .phase-dot { background: var(--ok); border-color: var(--ok); }
.phase-fail          { color: var(--err); }
.phase-fail .phase-dot { background: var(--err); border-color: var(--err); }
@keyframes phase-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(240,160,80,.35); }
    70%  { box-shadow: 0 0 0 8px rgba(240,160,80,0);   }
    100% { box-shadow: 0 0 0 0   rgba(240,160,80,0);   }
}

/* --- tabs ------------------------------------------------------- */
.tabs {
    max-width: 1100px; margin: 1rem auto 0; padding: 0 1.25rem;
    display: flex; gap: .25rem; border-bottom: 1px solid var(--border);
}
.tab {
    background: transparent; color: var(--text-muted);
    border: 1px solid transparent; border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    padding: .5rem 1rem; font-weight: 600; font-size: 13px;
    cursor: pointer; position: relative; top: 1px;
}
.tab:hover { color: var(--text); }
.tab-active {
    background: var(--bg-card); color: var(--text);
    border-color: var(--border);
}

.panel { display: block; }
.panel-inner {
    max-width: 1100px; margin: 0 auto;
    padding: 1rem 1.25rem;
}

/* --- GPIO table ------------------------------------------------- */
.gpio-table { width: 100%; border-collapse: collapse; }
.gpio-table th, .gpio-table td {
    text-align: left; padding: .5rem .65rem;
    border-bottom: 1px solid var(--border-soft);
    font-size: 13px;
}
.gpio-table th {
    color: var(--text-dim); font-weight: 500; font-size: 11px;
    text-transform: uppercase; letter-spacing: .04em;
}
.gpio-table td.mono { font-family: var(--mono); }
.gpio-row-reserved { color: var(--text-dim); }
.gpio-row-reserved td { font-style: italic; }
.gpio-mode-select,
.gpio-level-btn {
    background: var(--bg-soft); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: .25rem .55rem; font: inherit; font-size: 12px;
}
.gpio-mode-select:disabled,
.gpio-level-btn:disabled { opacity: .55; cursor: not-allowed; }
.gpio-level-high { color: var(--ok); }
.gpio-level-low  { color: var(--text-muted); }
.gpio-level-btn  { font-family: var(--mono); min-width: 60px; }

/* --- UART terminal --------------------------------------------- */
.uart-toolbar {
    flex-wrap: wrap; gap: .85rem; margin-bottom: .75rem;
}
.uart-toolbar select {
    background: var(--bg-soft); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: .25rem .4rem; font: inherit; font-size: 12px;
}
.uart-scrollback {
    background: #060a0e; border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm); padding: .55rem .7rem;
    height: 320px; overflow-y: auto; overflow-x: hidden;
    font-size: 12px; line-height: 1.5; white-space: pre-wrap;
    word-break: break-all;
}
.uart-line-rx { color: var(--text); }
.uart-line-tx { color: var(--accent); }
.uart-line-sys{ color: var(--text-dim); font-style: italic; }
.uart-input { display: flex; gap: .5rem; margin-top: .65rem; }
.uart-input input[type=text] {
    flex: 1; background: var(--bg-soft); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius-sm);
    padding: .5rem .65rem; font: inherit; font-family: var(--mono); font-size: 13px;
}

/* --- network scan ----------------------------------------------- */
.net-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem .85rem;
    margin-bottom: .85rem;
}
.net-ports-field { grid-column: 1 / -1; }
.net-actions { grid-column: 1 / -1; flex-wrap: wrap; }
.net-form input[type=text] {
    background: var(--bg-soft); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius-sm);
    padding: .45rem .6rem; font: inherit; font-family: var(--mono); font-size: 12px;
}
.net-progress {
    margin: .55rem 0 1rem;
    display: flex; flex-direction: column; gap: .25rem;
}
.net-progress-bar {
    height: 6px; background: var(--bg-soft); border-radius: 3px; overflow: hidden;
}
.net-progress-fill {
    height: 100%; width: 0%; background: var(--accent);
    transition: width .15s linear;
}
.net-table { width: 100%; border-collapse: collapse; }
.net-table th, .net-table td {
    text-align: left; padding: .45rem .65rem;
    border-bottom: 1px solid var(--border-soft);
    font-size: 13px; vertical-align: top;
}
.net-table th {
    color: var(--text-dim); font-weight: 500; font-size: 11px;
    text-transform: uppercase; letter-spacing: .04em;
}
.net-table td.mono { font-family: var(--mono); }
.net-ports-list { display: flex; flex-wrap: wrap; gap: .25rem; }
.net-port-chip {
    background: rgba(86,211,100,.15); color: var(--ok);
    border: 1px solid rgba(86,211,100,.4);
    border-radius: 4px; padding: 1px 6px; font-family: var(--mono);
    font-size: 11px;
}
.net-pending { color: var(--text-dim); font-style: italic; }

/* --- Wiegand sniffer ------------------------------------------- */
.wg-form {
    display: grid; grid-template-columns: 1fr 1fr 1fr;
    gap: .65rem .85rem; margin-bottom: .85rem;
}
.wg-actions { grid-column: 1 / -1; flex-wrap: wrap; }
.wg-form input[type=number], .wg-form select {
    background: var(--bg-soft); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius-sm);
    padding: .45rem .6rem; font: inherit; font-family: var(--mono); font-size: 12px;
}
.wg-table { width: 100%; border-collapse: collapse; }
.wg-table th, .wg-table td {
    text-align: left; padding: .45rem .65rem;
    border-bottom: 1px solid var(--border-soft);
    font-size: 13px;
}
.wg-table th {
    color: var(--text-dim); font-weight: 500; font-size: 11px;
    text-transform: uppercase; letter-spacing: .04em;
}
.wg-table td.mono { font-family: var(--mono); }
@media (max-width: 720px) { .wg-form { grid-template-columns: 1fr; } }
.wg-decoders {
    display: flex; flex-wrap: wrap; gap: .55rem 1rem;
    padding: .5rem .65rem; margin-bottom: .65rem;
    background: var(--bg-soft); border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
}
.wg-tag {
    display: inline-block; padding: 0 6px; margin-right: .35rem;
    border-radius: 4px; font-size: 10px; font-weight: 600;
    background: var(--bg-soft); color: var(--text-muted);
    border: 1px solid var(--border);
}
.wg-tag-ok   { background: rgba(86,211,100,.15); color: var(--ok);  border-color: rgba(86,211,100,.4); }
.wg-tag-bad  { background: rgba(248,81,73,.15);  color: var(--err); border-color: rgba(248,81,73,.4); }

/* --- XIAO ESP32-S3 pinout SVG ---------------------------------- */
.xiao-pinout {
    display: flex; flex-direction: column; align-items: center;
    background: var(--bg-soft); border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: .75rem;
    margin-bottom: .85rem;
}
.xiao-svg { width: 100%; max-width: 380px; height: auto; display: block; }
.xiao-board { fill: #0a4f3d; stroke: #2d8a6e; stroke-width: 1.5; }
.xiao-mcu   { fill: #0e0f12; stroke: #2a313d; stroke-width: 1; }
.xiao-mcu-label { font-family: var(--mono); font-size: 9px; fill: var(--text-dim); }
.xiao-usb   { fill: #888; stroke: #555; stroke-width: 1; }
.xiao-usb-label { font-size: 10px; fill: #111; font-family: var(--mono); font-weight: 600; }

.xiao-pin   { fill: #d9b85c; stroke: #8a7138; stroke-width: 1; }
.xiao-pin-label { font-family: var(--mono); font-size: 11px;
                  fill: #eef3e8; font-weight: 600; }
.xiao-pin-sub   { font-family: var(--mono); font-size: 10px;
                  fill: var(--text-dim); }

.xiao-pin.xiao-pin-tx  { fill: #58a6ff; stroke: #58a6ff; }
.xiao-pin.xiao-pin-rx  { fill: #56d364; stroke: #56d364; }
.xiao-pin.xiao-pin-wg0 { fill: #f0a050; stroke: #f0a050; }
.xiao-pin.xiao-pin-wg1 { fill: #f85149; stroke: #f85149; }
.xiao-pin.xiao-pin-sel { fill: #c8b1ff; stroke: #c8b1ff; }

.xiao-chip { font-family: var(--mono); font-size: 11px; font-weight: 700; }
.xiao-chip.xiao-pin-tx  { fill: var(--accent); }
.xiao-chip.xiao-pin-rx  { fill: var(--ok); }
.xiao-chip.xiao-pin-wg0 { fill: var(--warn); }
.xiao-chip.xiao-pin-wg1 { fill: var(--err); }
.xiao-chip.xiao-pin-sel { fill: #c8b1ff; }

.xiao-caption { margin-top: .5rem; text-align: center; }
.xiao-state { transition: fill .12s, stroke .12s; }
.xiao-state-letter { font-family: var(--mono); font-size: 9px;
                     fill: var(--text-dim); font-weight: 700; }

/* --- GPIO function badges (TX/RX/Wiegand/etc.) ----------------- */
.gpio-func-badge {
    display: inline-block; padding: 1px 7px; border-radius: 4px;
    font-family: var(--mono); font-size: 11px; font-weight: 600;
    letter-spacing: .02em; border: 1px solid currentColor;
}
.gpio-func-tx  { background: rgba(88,166,255,.15); color: var(--accent); }
.gpio-func-rx  { background: rgba(86,211,100,.15); color: var(--ok); }
.gpio-func-wg0 { background: rgba(240,160,80,.15); color: var(--warn); }
.gpio-func-wg1 { background: rgba(248,81,73,.15);  color: var(--err); }
