/* Admin area – tablet-first, works down to ~375px. */
:root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2530;
    --border: #2b3240;
    --text: #eef1f6;
    --muted: #8d97a8;
    --primary: #ffb000;
    --primary-text: #1a1300;
    --up: #1fd67a;
    --down: #ff4d5e;
    --danger: #e0364a;
    --radius: 12px;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

a { color: var(--primary); }
code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; word-break: break-all; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 16px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.9rem; margin: 8px 0 0; }
.text-up { color: var(--up); }
.text-down { color: var(--down); }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

/* --- header / nav ------------------------------------------------------- */
.admin-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.admin-header__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.admin-header__logo { color: var(--primary); font-weight: 900; letter-spacing: -2px; }
.admin-header__title { font-weight: 700; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.market-pill {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 999px;
    white-space: nowrap;
}
.market-pill--open { background: color-mix(in srgb, var(--up) 20%, transparent); color: var(--up); }
.market-pill--closed { background: var(--surface-2); color: var(--muted); }

.admin-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}
.admin-nav__link {
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    font-weight: 600;
}
.admin-nav__link:hover { background: var(--surface-2); }
.admin-nav__link[data-active="True"] { background: var(--primary); color: var(--primary-text); }
.admin-nav__link--external { color: var(--muted); }
.admin-nav__logout { margin-left: 8px; }

.admin-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    display: grid;
    gap: 16px;
}

/* --- building blocks ---------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    min-width: 0;
}
.card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card__head h1 { margin: 0; }

.alert { padding: 12px 14px; border-radius: 8px; font-weight: 600; }
.alert[hidden] { display: none; }
.alert--success { background: color-mix(in srgb, var(--up) 18%, var(--surface)); color: var(--up); }
.alert--error { background: color-mix(in srgb, var(--down) 18%, var(--surface)); color: #ffc2c8; }
.validation-summary.validation-summary-valid { display: none; }
.validation-summary ul { margin: 0; padding-left: 18px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 8px 18px;
    border: 1px solid transparent;
    border-radius: 8px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    background: var(--surface-2);
}
.btn:disabled { opacity: 0.35; cursor: default; }
.btn--primary { background: var(--primary); color: var(--primary-text); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--border); }
.btn--small { min-height: 36px; padding: 4px 12px; font-size: 0.9rem; }
.btn--large { min-height: 56px; padding: 12px 28px; font-size: 1.1rem; }
.btn--block { width: 100%; }
.btn--icon { min-height: 36px; width: 36px; padding: 0; }
.btn[hidden] { display: none; }

/* --- forms -------------------------------------------------------------- */
.form { display: grid; gap: 14px; }
.form > .btn { justify-self: start; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; }
.form-row > .field { flex: 1 1 180px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field--narrow { flex: 0 1 160px !important; max-width: 100%; }
.field__label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.input {
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.input--code { font-family: Consolas, Menlo, monospace; font-size: 0.9rem; resize: vertical; }
.input--pin { font-size: 1.8rem; letter-spacing: 0.4em; text-align: center; }
.input-validation-error { border-color: var(--down); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.form-actions--sticky { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 40%); }

.setting {
    display: grid;
    grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
    gap: 8px 20px;
    align-items: center;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}
.setting:first-of-type { border-top: 0; }
.setting__help { margin: 0; color: var(--muted); font-size: 0.9rem; }
@media (max-width: 640px) {
    .setting { grid-template-columns: 1fr; }
}

.design-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-top: 12px; }
.design-option { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.design-option:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.design-option input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.design-option__body { display: grid; gap: 4px; min-width: 0; }
.design-option__link { font-size: .85rem; word-break: break-all; }

.drink-cell { display: inline-flex; align-items: center; gap: 10px; }
.drink-thumb { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; flex: none; }
.image-picker { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; min-width: 0; }
.image-picker__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.image-option { position: relative; display: grid; place-items: center; aspect-ratio: 1; border: 2px solid transparent; border-radius: 14px; cursor: pointer; }
.image-option input { position: absolute; opacity: 0; pointer-events: none; }
.image-option img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.image-option__none { font-size: .8rem; color: var(--muted); text-align: center; }
.image-option:has(input:checked) { border-color: var(--primary); }
.image-option:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

.check { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.check input[type="checkbox"] { width: 24px; height: 24px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.market-pill--demo { background: color-mix(in srgb, var(--primary) 22%, transparent); color: var(--primary); }

.login-card { max-width: 380px; width: 100%; margin: 8vh auto 0; }

/* --- tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot th { color: var(--text); font-size: 0.95rem; }
.row--inactive td { opacity: 0.45; }
.row--inactive td:last-child, .row--inactive td:nth-last-child(2) { opacity: 1; }
.row--voided td { text-decoration: line-through; color: var(--muted); }
.row--voided td:last-child { text-decoration: none; }

.link-list { display: grid; gap: 8px; padding-left: 18px; }

.kpis { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface-2); border-radius: var(--radius); padding: 12px 18px; display: grid; min-width: 160px; }
.kpi__value { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi__label { color: var(--muted); font-size: 0.85rem; }

.crash-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.crash-list__item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }

/* --- sales -------------------------------------------------------------- */
.sales { display: grid; gap: 16px; }
.sales__toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }

.qty { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.qty__label { color: var(--muted); font-weight: 600; margin-right: 6px; }
.qty__option {
    width: 56px;
    height: 56px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 1.4rem;
    font-weight: 800;
    cursor: pointer;
}
.qty__option[aria-checked="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.feed-status { color: var(--down); font-weight: 600; }
.feed-status[hidden] { display: none; }

.receipt {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--up) 16%, var(--surface));
    border: 2px solid var(--up);
}
.receipt[hidden] { display: none; }
.receipt__text { font-size: clamp(1.2rem, 3vw, 1.8rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.receipt__note { width: 100%; order: 3; color: var(--primary); font-weight: 700; }
.receipt__note[hidden] { display: none; }
.receipt--warn { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--surface)); }
.receipt--pop { animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(0.97); opacity: 0.4; } }

.sell-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
}
.sell-button {
    position: relative;
    display: grid;
    gap: 6px;
    align-content: center;
    min-height: 120px;
    padding: 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    transition: transform 0.08s;
}
.sell-button:active { transform: scale(0.97); }
.sell-button--busy { opacity: 0.6; }
.sell-button__head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sell-button__img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.sell-button__name { font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; padding-right: 20px; }
.sell-button__price { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--primary); }
.sell-button__trend { position: absolute; top: 10px; right: 12px; font-size: 1.1rem; }
.sell-button__trend--up { color: var(--up); }
.sell-button__trend--down { color: var(--down); }
.sell-button--crashed { border-color: var(--down); box-shadow: 0 0 0 2px var(--down); }
.sell-button.flash-up { animation: btn-flash-up 1.4s ease-out; }
.sell-button.flash-down { animation: btn-flash-down 1.4s ease-out; }
@keyframes btn-flash-up { 0%, 25% { background: color-mix(in srgb, var(--up) 35%, var(--surface-2)); } }
@keyframes btn-flash-down { 0%, 25% { background: color-mix(in srgb, var(--down) 35%, var(--surface-2)); } }

@media (max-width: 480px) {
    .admin-main { padding: 12px; }
    .sell-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .sell-button { min-height: 100px; padding: 10px; }
    .sell-button__price { font-size: 1.35rem; }
    .qty__option { width: 48px; height: 48px; }
}
