/* ===========================================================================
   Sal's Kewl Korner customer panel
   ---------------------------------------------------------------------------
   MOBILE FIRST, and meant literally: every base rule here is the phone layout,
   and the media queries only ever ADD width. The panel is opened on a phone at
   least as often as on a desk -- checking a customer while away from it is the
   normal case, not the exception -- so the narrow layout is the one that has
   to be right, and the wide one is the enhancement.

   What that means in practice, and what to preserve when editing:

   - Nothing has a fixed width. Tables become stacked cards under 720px rather
     than scrolling sideways, because a table you have to pan is a table you
     cannot read on a phone.
   - Tap targets are 44px minimum. That is the size a thumb actually hits.
   - Inputs are 16px. Anything smaller makes iOS Safari zoom the page on focus
     and then leave it zoomed, which feels like the page broke.
   - Colors are tokens, defined light and redefined for dark. Never hard-code
     a hex where a token exists -- it will be wrong in one of the two themes.
   =========================================================================== */

:root {
    --bg:        #f6f7f6;
    --surface:   #ffffff;
    --surface-2: #eef0ee;
    --border:    #d6dad6;
    --text:      #161c17;
    --muted:     #5d665e;
    --accent:    #1d7f2e;
    --accent-fg: #ffffff;
    --danger:    #a3231d;
    --warn:      #8a5a00;
    --gold:      #9a7413;
    --gold-bg:   #fdf4dc;

    --radius: 10px;
    --gap: 14px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .04);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:        #12150f;
        --surface:   #1a1e18;
        --surface-2: #232820;
        --border:    #333a30;
        --text:      #e7ece6;
        --muted:     #9aa79b;
        --accent:    #5fe36a;
        --accent-fg: #0c1209;
        --danger:    #ff8177;
        --warn:      #e0a646;
        --gold:      #e8c265;
        --gold-bg:   #2a2415;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    }
}

:root[data-theme="dark"] {
    --bg:        #12150f;
    --surface:   #1a1e18;
    --surface-2: #232820;
    --border:    #333a30;
    --text:      #e7ece6;
    --muted:     #9aa79b;
    --accent:    #5fe36a;
    --accent-fg: #0c1209;
    --danger:    #ff8177;
    --warn:      #e0a646;
    --gold:      #e8c265;
    --gold-bg:   #2a2415;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    /* The iOS home-bar strip, so the last row of a list is not under it. */
    padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }

a { color: var(--accent); }

/* --- Chrome ------------------------------------------------------------- */

header.bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.bar .brand {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: .01em;
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.bar .brand span.dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--gold);
    flex: none;
}

.bar .who {
    font-size: .8rem;
    color: var(--muted);
    /* Hidden on the narrowest screens: the email is the first thing worth
       losing when the bar has to choose between it and the sign-out button. */
    display: none;
}

main { padding: var(--gap); max-width: 1100px; margin: 0 auto; }

/* --- Cards -------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: var(--gap);
    box-shadow: var(--shadow);
}

.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.card-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.card-head h2, .card-head h3 { margin: 0; margin-right: auto; }

/* --- Stat tiles --------------------------------------------------------- */

.tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: var(--gap);
}

.tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}
.tile .n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.tile .k {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); margin-top: 2px;
}
.tile.gold .n { color: var(--gold); }

/* --- Forms -------------------------------------------------------------- */

label { display: block; font-size: .8rem; color: var(--muted); margin: 10px 0 4px; }

input, select, textarea {
    width: 100%;
    /* 16px, not smaller -- see the header note about iOS zoom. */
    font-size: 16px;
    font-family: inherit;
    padding: 11px 12px;
    min-height: 44px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
textarea { min-height: 80px; resize: vertical; }

input:focus, select:focus, textarea:focus, button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.row { display: flex; flex-direction: column; gap: 0; }

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 11px 16px;
    font-size: .95rem;
    font-family: inherit;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    /* Stops the grey flash on tap in mobile Safari and Chrome. */
    -webkit-tap-highlight-color: transparent;
}

button.primary, .btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-fg);
}
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.small { min-height: 36px; padding: 6px 11px; font-size: .82rem; }
button:disabled { opacity: .5; cursor: not-allowed; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions.end { justify-content: flex-end; }

/* --- Badges ------------------------------------------------------------- */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    white-space: nowrap;
}
.badge.gold   { background: var(--gold-bg); color: var(--gold); border-color: var(--gold); }
.badge.ok     { color: var(--accent); border-color: var(--accent); background: transparent; }
.badge.bad    { color: var(--danger); border-color: var(--danger); background: transparent; }
.badge.warn   { color: var(--warn); border-color: var(--warn); background: transparent; }

/* --- Lists -------------------------------------------------------------- */

.list { list-style: none; margin: 0; padding: 0; }

.list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 2px;
    border-bottom: 1px solid var(--border);
    min-height: 44px;
}
.list li:last-child { border-bottom: none; }

.list .grow { flex: 1; min-width: 0; }
.list .grow .t { font-weight: 600; }
.list .grow .s {
    font-size: .8rem; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.list a.item {
    display: flex; align-items: center; gap: 10px;
    color: inherit; text-decoration: none; flex: 1; min-width: 0;
}

/* --- Key/value ---------------------------------------------------------- */

dl.kv { margin: 0; display: grid; grid-template-columns: 1fr; gap: 0; }
dl.kv div {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 9px 0; border-bottom: 1px solid var(--border);
}
dl.kv div:last-child { border-bottom: none; }
dl.kv dt { color: var(--muted); font-size: .82rem; }
dl.kv dd { margin: 0; text-align: right; font-weight: 600; font-size: .9rem; }

/* --- Utility ------------------------------------------------------------ */

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono  { font-family: var(--mono); font-size: .85rem; word-break: break-all; }
.center { text-align: center; }
.stack > * + * { margin-top: 10px; }
.hide { display: none !important; }

.notice {
    padding: 11px 13px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: .88rem;
    margin-bottom: 12px;
}
.notice.err  { border-color: var(--danger); color: var(--danger); background: transparent; }
.notice.ok   { border-color: var(--accent); color: var(--accent); background: transparent; }
.notice.gold { border-color: var(--gold); background: var(--gold-bg); color: var(--gold); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.searchbar { display: flex; gap: 8px; margin-bottom: var(--gap); }
.searchbar input { flex: 1; }

/* Modal: a sheet from the bottom on a phone, a centered dialog on a desk.
   Bottom-sheet because a centered box on a phone puts the fields under the
   keyboard and the buttons off screen. */
.sheet-back {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(0, 0, 0, .45);
    display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
    background: var(--surface);
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    border: 1px solid var(--border);
}
.sheet h2 { margin-top: 0; }

.spinner { color: var(--muted); padding: 24px 0; text-align: center; }

/* --- Login -------------------------------------------------------------- */

.login-wrap {
    min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.login-card { width: 100%; max-width: 380px; }
.login-card .logo {
    display: flex; align-items: center; gap: 9px;
    font-weight: 700; font-size: 1.15rem; margin-bottom: 4px;
}
.login-card .logo .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--gold); }

.tabs { display: flex; gap: 6px; margin: 14px 0 4px; }
.tabs button {
    flex: 1; min-height: 40px; font-size: .85rem;
    background: transparent; border-color: transparent; color: var(--muted);
    border-bottom: 2px solid var(--border); border-radius: 0;
}
.tabs button[aria-selected="true"] {
    color: var(--text); border-bottom-color: var(--accent); font-weight: 700;
}

/* --- Wider screens ------------------------------------------------------ */

@media (min-width: 560px) {
    .tiles { grid-template-columns: repeat(4, 1fr); }
    .bar .who { display: block; }
    .row { flex-direction: row; gap: 12px; }
    .row > * { flex: 1; }
    .sheet-back { align-items: center; padding: 20px; }
    .sheet { max-width: 520px; border-radius: 14px; }
}

@media (min-width: 900px) {
    main { padding: 20px; }
    h1 { font-size: 1.6rem; }
    .cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); align-items: start; }
    .cols > * { margin-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
