/* Address-lookup stylesheet. Keep all rules in this one file — simple app,
   one screen at a time, no need to split. Dark mode via prefers-color-scheme. */

:root {
    --bg:          #fafbfc;
    --bg-raised:   #ffffff;
    --bg-sunken:   #f2f4f7;
    --fg:          #0f172a;
    --fg-muted:    #64748b;
    --border:      #e2e8f0;
    --border-strong: #cbd5e1;
    --accent:      #0a58ca;
    --accent-fg:   #ffffff;
    --chip-on-bg:  #dcfce7;
    --chip-on-fg:  #15803d;
    --chip-off-bg: #e2e8f0;
    --chip-off-fg: #475569;
    --err-bg:      #fee2e2;
    --err-fg:      #991b1b;
    --ok-bg:       #dcfce7;
    --ok-fg:       #15803d;
    --shadow:      0 1px 2px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.05);
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg:          #0b1220;
        --bg-raised:   #131b2e;
        --bg-sunken:   #0e1526;
        --fg:          #e2e8f0;
        --fg-muted:    #94a3b8;
        --border:      #1f2a44;
        --border-strong: #334155;
        --accent:      #3b82f6;
        --accent-fg:   #ffffff;
        --chip-on-bg:  #14361f;
        --chip-on-fg:  #86efac;
        --chip-off-bg: #1f2a44;
        --chip-off-fg: #94a3b8;
        --err-bg:      #3f1212;
        --err-fg:      #fca5a5;
        --ok-bg:       #14361f;
        --ok-fg:       #86efac;
        --shadow:      0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.4);
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* Reserve scrollbar space from the first paint so centered content doesn't
   shift right when a result renders and pushes the page into overflow. */
html { scrollbar-gutter: stable; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--fg);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    /* Push the footer to the viewport bottom on short pages. */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
main { flex: 1 0 auto; }

/* --- Layout tokens ------------------------------------------------------ */
/* One content width for the whole app. Nav aligns with it so the viewport
   doesn't look like a wide empty bar above a small column. */
:root { --content-max: 1200px; --reading-max: 760px; }

/* --- Topbar nav --------------------------------------------------------- */
.topbar {
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
    backdrop-filter: saturate(150%) blur(8px);
}
.topbar-inner {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: .75rem 1.5rem;
    max-width: var(--content-max);
    margin: 0 auto;
}
.brand { font-weight: 700; color: var(--fg); text-decoration: none; font-size: 1rem; }
.nav-links { display: flex; gap: 1.25rem; flex: 1; }
.nav-links a {
    color: var(--fg-muted); text-decoration: none; font-weight: 500;
    padding: .25rem .5rem; border-radius: 6px;
}
.nav-links a:hover { color: var(--fg); background: var(--bg-sunken); }
.nav-user { display: flex; align-items: center; gap: .75rem; }
.nav-email { color: var(--fg-muted); font-size: .875rem; }

/* --- Main layout -------------------------------------------------------- */
main { max-width: var(--content-max); margin: 0 auto; padding: 2rem 1.5rem 4rem; }
main > section + aside, main > section + section { margin-top: 2.5rem; }
.narrow { max-width: 480px; margin: 3rem auto; }

h1 { font-size: 1.5rem; margin: 0 0 .5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.125rem; margin: 0 0 .75rem; }
h3 { font-size: .875rem; margin: 1rem 0 .5rem; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-muted); }
.muted { color: var(--fg-muted); }
.nowrap { white-space: nowrap; }

/* --- Forms -------------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: .875rem; }
label { display: block; font-weight: 500; font-size: .875rem; color: var(--fg); }
label input, label select { margin-top: .25rem; }

input[type=text], input[type=email], input[type=password], input[type=date], select {
    width: 100%;
    padding: .55rem .75rem;
    font-size: .9375rem;
    font-family: inherit;
    color: var(--fg);
    background: var(--bg-raised);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    transition: border-color .15s, box-shadow .15s;
    /* Use dark native widgets (calendar popup, etc.) in dark mode. */
    color-scheme: light dark;
}
input:focus, select:focus, button:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
/* Native date input calendar icon — make it blend with the theme instead
   of being a bright native blue. */
input[type=date]::-webkit-calendar-picker-indicator {
    opacity: .55;
    cursor: pointer;
    filter: grayscale(100%);
}
input[type=date]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
input[type=date]::-webkit-datetime-edit-year-field,
input[type=date]::-webkit-datetime-edit-month-field,
input[type=date]::-webkit-datetime-edit-day-field { color: var(--fg); }
input[type=date]:not(:focus):not(.has-value)::-webkit-datetime-edit {
    color: var(--fg-muted);
}

/* --- Buttons ------------------------------------------------------------ */
.btn, .btn-link, button {
    font: inherit;
    cursor: pointer;
    border-radius: 8px;
    padding: .45rem .9rem;
    border: 1px solid var(--border-strong);
    background: var(--bg-raised);
    color: var(--fg);
    transition: background .15s, border-color .15s;
}
.btn:hover, button:hover { background: var(--bg-sunken); }
.btn-primary {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: transparent;
    padding: .55rem 1.1rem;
    font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-link {
    background: transparent; border: 0; color: var(--accent); padding: 0;
    font-weight: 500;
}
.btn-link:hover { text-decoration: underline; background: transparent; }
.btn-link.danger { color: var(--err-fg); }
.btn-link:disabled { color: var(--fg-muted); cursor: not-allowed; text-decoration: none; }
.inline { display: inline; }
.inline-form { display: inline-flex; gap: .4rem; margin-top: .4rem; }
.inline-form input[type=password] { width: auto; }

/* --- Toast notifications ----------------------------------------------- */
.toasts {
    position: fixed;
    top: 4.5rem; right: 1.25rem;
    display: flex; flex-direction: column; gap: .5rem;
    z-index: 100;
    pointer-events: none;
    max-width: calc(100vw - 2.5rem);
}
.toast {
    pointer-events: auto;
    display: flex; align-items: center; gap: .625rem;
    min-width: 260px; max-width: 420px;
    padding: .625rem .875rem;
    border-radius: 10px;
    font-size: .875rem;
    background: var(--bg-raised);
    color: var(--fg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    animation: toast-in .2s cubic-bezier(.2,.7,.2,1) both;
}
.toast::before {
    content: ''; width: 8px; height: 8px; border-radius: 50%;
    background: var(--fg-muted);
    flex-shrink: 0;
}
.toast-success::before, .toast-info::before { background: var(--ok-fg); }
.toast-error::before                        { background: var(--err-fg); }
.toast-close {
    margin-left: auto;
    background: transparent; border: 0; padding: 0 .125rem;
    font-size: 1.125rem; line-height: 1;
    color: var(--fg-muted); cursor: pointer;
}
.toast-close:hover { color: var(--fg); background: transparent; }
.toast-leave { animation: toast-out .2s ease both; }
@keyframes toast-in  { from { transform: translateX(110%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { from { transform: none; opacity: 1; } to { transform: translateX(110%); opacity: 0; } }

/* Flash classes kept as fallback in case something still emits them. */
.flash {
    padding: .625rem .875rem;
    border-radius: 8px;
    margin: 0 0 1rem;
    font-size: .9375rem;
}
.flash-success, .flash-info { background: var(--ok-bg);  color: var(--ok-fg); }
.flash-error                { background: var(--err-bg); color: var(--err-fg); }

/* --- Lookup screen ------------------------------------------------------ */
/* The lookup column sits at a comfortable reading width — a full-viewport
   input/card on a big monitor feels cavernous. Data tables below get the
   full main width. Centered so it doesn't drift left as content grows. */
.lookup { max-width: var(--reading-max); margin: 0 auto; }
.lookup > label { margin-top: 1rem; }

/* Input wrapper that positions the kbd hint + spinner inside the field. */
.q-wrap { position: relative; }
.q-wrap input { padding-right: 3rem; }
.q-kbd {
    position: absolute; top: 50%; right: .75rem;
    transform: translateY(-50%);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .7rem;
    color: var(--fg-muted);
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 .35rem;
    line-height: 1.3;
    opacity: .6;
    pointer-events: none;
    transition: opacity .15s;
}
.q-wrap input:focus ~ .q-kbd { opacity: 0; }
.q-spinner {
    position: absolute; top: 50%; right: .75rem;
    transform: translateY(-50%);
    width: 14px; height: 14px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    opacity: 0;
    transition: opacity .15s;
    animation: spin .8s linear infinite;
}
.q-wrap.is-loading .q-spinner { opacity: 1; }
.q-wrap.is-loading .q-kbd     { opacity: 0; }
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

#suggestions {
    list-style: none; margin: .25rem 0 0; padding: .25rem;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-height: 280px; overflow-y: auto;
}
#suggestions li {
    padding: .5rem .75rem; cursor: pointer; border-radius: 6px;
    color: var(--fg);
}
#suggestions li.active, #suggestions li:hover { background: var(--bg-sunken); }

/* --- Result card -------------------------------------------------------- */
.card {
    margin-top: 1.5rem;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
}
.card header { display: flex; justify-content: space-between; align-items: center; }
.card h2 { margin: 0; }
.card pre {
    font-family: inherit; white-space: pre-wrap;
    margin: .75rem 0 1rem;
    color: var(--fg);
}

/* --- Chips -------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1rem; }
.chip {
    display: inline-flex; align-items: center;
    font-size: .8125rem; padding: .2rem .625rem;
    border-radius: 999px; font-weight: 500;
    white-space: nowrap;
}
.chip-on  { background: var(--chip-on-bg);  color: var(--chip-on-fg);  }
.chip-off { background: var(--chip-off-bg); color: var(--chip-off-fg); }

/* --- Services list ------------------------------------------------------ */
.services { list-style: none; padding: 0; margin: 0; }
.services li {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 1rem;
    align-items: center;
    padding: .625rem 0;
    border-top: 1px solid var(--border);
}
.services li:first-child { border-top: 0; }
.svc-name { font-weight: 600; }
.svc-sat { font-size: .8125rem; font-variant-numeric: tabular-nums; font-weight: 500; }
.svc-sat.yes { color: var(--chip-on-fg); }
.svc-sat.no  { color: var(--fg-muted); }
.svc-meta {
    font-size: .75rem; color: var(--fg-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
/* --- Notes / callouts -------------------------------------------------- */
.note {
    margin: 1rem 0 0;
    padding: .75rem 1rem;
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--bg-sunken));
    font-size: .8125rem;
    color: var(--fg);
    display: flex;
    gap: .625rem;
    align-items: flex-start;
    line-height: 1.45;
}
.note-icon {
    flex-shrink: 0;
    width: 16px; height: 16px;
    color: var(--accent);
    margin-top: 2px;
}
.note strong { font-weight: 600; }

/* --- Recent / history --------------------------------------------------- */
.recent { max-width: var(--reading-max); margin: 0 auto; }
.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-list li {
    padding: .75rem 1rem;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: .5rem;
}
.recent-head { display: flex; align-items: center; gap: .5rem; }
.recent-addr { font-weight: 500; flex: 1; }
.recent-meta {
    display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
    font-size: .8125rem; color: var(--fg-muted); margin-top: .4rem;
}
.recent-meta time { margin-left: auto; }

/* --- Icon buttons (copy etc.) ------------------------------------------ */
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: var(--bg-raised);
    color: var(--fg-muted);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--fg); background: var(--bg-sunken); }
.icon-btn.copied {
    color: var(--chip-on-fg);
    border-color: var(--chip-on-fg);
    background: var(--chip-on-bg);
}
.col-copy { width: 1%; white-space: nowrap; text-align: right; }

/* --- Data tables -------------------------------------------------------- */
.data {
    width: 100%; border-collapse: collapse;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
.data th, .data td { text-align: left; padding: .625rem .875rem; border-top: 1px solid var(--border); }
.data thead th {
    background: var(--bg-sunken); border-top: 0;
    font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--fg-muted); font-weight: 600;
    padding-top: .5rem; padding-bottom: .5rem;
}
.data tbody tr { transition: background .12s; }
.data tbody tr:hover { background: var(--bg-sunken); }
.data td.addr { color: var(--fg); }
.data td.actions { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

/* --- Filter form on history pages -------------------------------------- */
.filter-form {
    display: grid;
    grid-template-columns: 2.5fr 1fr 1fr 1fr 1fr 1fr auto;
    gap: .5rem .75rem;
    align-items: end;
    margin: 1.25rem 0 1rem;
}
.filter-form label {
    font-weight: 500;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--fg-muted);
}
.filter-form input, .filter-form select { margin-top: .2rem; }
.filter-form .f-actions {
    display: flex; gap: .75rem; align-items: center;
    padding-bottom: 2px;
}
.filter-form .f-actions .btn-link { font-size: .8125rem; }
@media (max-width: 900px) {
    .filter-form { grid-template-columns: 1fr 1fr; }
    .filter-form .f-text, .filter-form .f-actions { grid-column: 1 / -1; }
}

.table-actions {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; margin: 0 0 .75rem;
}
.table-actions p { margin: 0; }
.btn-icon {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .4rem .8rem;
    font-size: .875rem;
}
.btn-icon svg { width: 14px; height: 14px; }

/* Bulk / settings / API key layout bits. */
textarea {
    width: 100%;
    padding: .6rem .75rem;
    font-size: .9375rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--fg);
    background: var(--bg-raised);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    resize: vertical;
    min-height: 140px;
}
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.bulk-form { max-width: 760px; }
.row-fail td.error { font-size: .875rem; }

/* API key display block. */
.api-key {
    display: flex; align-items: center; gap: .625rem;
    padding: .625rem .875rem;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: 10px;
    word-break: break-all;
}
.api-key code {
    flex: 1;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .8125rem;
    letter-spacing: .01em;
    color: var(--fg);
    background: transparent;
}

/* Generic section spacing — use instead of inline styles. */
.stack-lg { margin-top: 2.25rem; }
.stack-md { margin-top: 1.25rem; }

/* Settings page grouping. */
.setting-block {
    padding: 1.25rem 1.5rem;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1rem;
}
.setting-block h2 {
    font-size: 1rem;
    margin: 0 0 .75rem;
    font-weight: 600;
}

.code-sample {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .75rem;
    background: var(--bg-sunken);
    padding: .5rem .625rem;
    border-radius: 6px;
    margin: .5rem 0;
    white-space: pre-wrap; word-break: break-all;
    color: var(--fg);
}

/* --- New-user details panel -------------------------------------------- */
details.new-user { margin: 0 0 1.25rem; }
details.new-user > summary {
    display: inline-flex; align-items: center;
    list-style: none; cursor: pointer;
    border-radius: 8px;
    padding: .55rem 1.1rem;
    background: var(--accent); color: var(--accent-fg);
    font-weight: 600; font-size: .9375rem;
    border: 1px solid transparent;
    user-select: none;
}
details.new-user > summary:hover { filter: brightness(1.08); }
details.new-user > summary::-webkit-details-marker,
details.new-user > summary::marker { display: none; content: ''; }
details.new-user[open] > summary { margin-bottom: 1rem; }
.new-user-form {
    background: var(--bg-raised); padding: 1.25rem 1.5rem;
    border: 1px solid var(--border); border-radius: 12px;
    max-width: 480px;
}

.loading { color: var(--fg-muted); }
.error   { color: var(--err-fg); }

/* --- Footer ------------------------------------------------------------- */
.footer {
    margin-top: 3rem;
    border-top: 1px solid var(--border);
    background: var(--bg-raised);
    flex-shrink: 0;
}
.footer-inner {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: .8125rem;
    color: var(--fg-muted);
}
.footer-brand { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.footer-brand strong { color: var(--fg); font-weight: 600; }
.footer-version {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .75rem;
    padding: .15rem .5rem;
    background: var(--bg-sunken);
    border-radius: 999px;
    color: var(--fg-muted);
}
