/* UI components — buttons, cards, modals, lists, forms */

/* ---------- Buttons ---------- */

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    background: var(--bg-3);
    color: var(--text-1);
    border: 1px solid var(--line-strong);
    font-family: var(--font-display);
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    line-height: 1.15;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
    cursor: pointer;
}

button:hover, .btn:hover {
    background: var(--line-strong);
    border-color: var(--text-3);
}

button:active, .btn:active {
    transform: scale(0.97);
}

button:disabled, .btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.btn-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: var(--accent-ink);
}

.btn-success {
    background: var(--ok);
    border-color: var(--ok);
    color: #1a2408;
}

.btn-success:hover {
    background: #9dd653;
    border-color: #9dd653;
    color: #1a2408;
}

.btn-danger {
    background: transparent;
    border-color: var(--bad);
    color: var(--bad);
}

.btn-danger:hover {
    background: var(--bad);
    border-color: var(--bad);
    color: #2b0f0c;
}

.btn-warning {
    background: var(--warn);
    border-color: var(--warn);
    color: #271c00;
}

.btn-small {
    padding: 5px 10px;
    font-size: 12px;
}

/* ---------- Cards ----------
   Side panel: flat list sections separated by hairlines (no boxes).
   Modals: boxed sections for grouping. */

.card {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: var(--sp-3) 2px;
    margin-bottom: 0;
}

.card:last-child {
    border-bottom: none;
}

.card .card {
    border-left: 2px solid var(--line);
    border-bottom: none;
    padding-left: var(--sp-3);
    margin-top: var(--sp-2);
}

.modal .card {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: var(--sp-3);
    margin-bottom: var(--sp-3);
}

.modal .card .card {
    background: var(--bg-1);
}

.card-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15.5px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: var(--sp-1);
    color: var(--text-1);
}

.badge {
    display: inline-block;
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 1px 6px;
    border-radius: 4px;
    vertical-align: middle;
}
.badge-rush { background: rgba(248, 113, 113, 0.18); color: #f87171; }
.badge-bulk { background: rgba(96, 165, 250, 0.18); color: #60a5fa; }

.card-sub {
    font-size: 12.5px;
    color: var(--text-2);
    margin-bottom: var(--sp-2);
    line-height: 1.5;
}

/* Assign targeting highlight */
.card-targeting {
    border-left: 3px solid var(--accent);
    padding-left: var(--sp-2);
}

.card-tender {
    border-left: 3px solid #f59e0b;
    padding-left: var(--sp-2);
}

.assign-picks {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-bottom: var(--sp-2);
}

/* ---------- Modal ---------- */

.modal-root {
    position: fixed;
    inset: 0;
    background: rgba(8, 8, 10, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: var(--sp-4);
}

.modal {
    background: var(--bg-1);
    border: 1px solid var(--line-strong);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius-lg);
    max-width: 540px;
    width: 100%;
    /* vh on a mobile browser is the viewport *without* the URL bar, so 82vh
       can be taller than what the player can see and the modal's footer ends
       up under the browser chrome. --app-height is the measured visual
       viewport (ViewportManager), and dvh is the native equivalent. */
    max-height: 82vh;
    max-height: calc(var(--app-height, 100vh) * 0.86);
    overflow-y: auto;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
}

@supports (height: 100dvh) {
    .modal {
        max-height: 86dvh;
    }
}

/* Nothing outside is worth reaching while this is up (a lost session, a
   forced choice), so the modal owns the screen until it is answered. */
.modal-blocking {
    border-top-color: var(--bad);
}

.modal-header {
    padding: var(--sp-4);
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-3);
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.modal-title-icon {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

/* Level-up modal */
.levelup-icon {
    color: var(--accent);
    margin-bottom: var(--sp-2);
}

.levelup-title {
    font-family: var(--font-display);
    font-size: 34px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
}

.levelup-sub {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-2);
    margin-bottom: var(--sp-3);
}

.modal-body {
    padding: var(--sp-4);
    user-select: text;
}

.modal-footer {
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
}

/* ---------- Scrollbar ---------- */

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-0);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-3);
    border: 2px solid var(--bg-0);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--line-strong);
}

/* ---------- Marketplace ---------- */

.market-section {
    margin-bottom: var(--sp-5);
}

.market-section-title {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: var(--sp-1);
}

.market-section-desc {
    font-size: 12px;
    color: var(--text-3);
    margin-bottom: var(--sp-3);
}

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

.market-item {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    border-left: 3px solid transparent;
    border-radius: 0;
    padding: 10px 2px 10px var(--sp-2);
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.market-item:hover {
    border-left-color: var(--accent);
    background: var(--bg-2);
}

.market-item:last-child {
    border-bottom: none;
}

.market-item-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-1);
}

.market-item-id {
    font-family: var(--font-mono);
    font-size: 11px;
}

.market-item-stats {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-1);
}

.stat-badge {
    background: var(--bg-inset);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 2px 7px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-2);
    white-space: nowrap;
}

.market-buy-btn {
    align-self: flex-start;
    margin-top: 2px;
}

/* ---------- Printers panel ---------- */

.printer-row-head {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.printer-row-head .card-title {
    margin-bottom: 0;
    flex: 1;
}

.printer-row-meta {
    font-family: var(--font-mono);
    font-size: 11.5px;
    margin: 6px 0;
}

.printer-row-actions {
    display: flex;
    gap: var(--sp-2);
    margin-top: var(--sp-2);
}

.led-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--led, #fff);
    box-shadow: 0 0 6px 1px var(--led, #fff);
    flex: none;
}

.state-pill {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 2px 8px;
    border: 1px solid currentColor;
    border-radius: var(--radius);
}

.state-ok { color: var(--ok); }
.state-bad { color: var(--bad); }
.state-warn { color: var(--warn); }
.state-muted { color: var(--text-3); }

/* ---------- Printer-assignment dropdown (Staff panel) ---------- */
.assign-select-wrap {
    position: relative;
    margin-bottom: var(--sp-2);
}

.assign-select {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: var(--bg-inset);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text-1);
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.3;
    padding: 8px 30px 8px 10px;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    /* Chevron drawn by hand — keeps the arrow theme-colored without an
       extra image asset. */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%237b7972' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 11px 7px;
}

.assign-select:hover:not(:disabled) {
    border-color: var(--accent-dim);
}

.assign-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(255, 158, 44, 0.25);
}

.assign-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.assign-select option:disabled {
    color: var(--text-3);
    font-style: italic;
}

/* ---------- Catalog option groups ----------
   The product designer's three choices, laid out instead of hidden behind
   <select>. Each list is two to four items long, so the whole set fits and
   the numbers that decide the choice — unit value, the tier's value/time
   trade-off — can be compared without opening anything. */

.catalog-field {
    margin-bottom: var(--sp-3);
}

.catalog-field-label {
    display: block;
    margin-bottom: 6px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-3);
}

.catalog-opts {
    display: grid;
    /* auto-fit so a two-material category gets two wide buttons rather than
       two narrow ones and a hole where the third would be. */
    grid-template-columns: repeat(auto-fit, minmax(94px, 1fr));
    gap: 6px;
}

/* Category names are the longest labels here and read badly at a third of
   the panel's width, so they get two per row whatever the count. */
.catalog-opts-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.catalog-opt {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-height: 44px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-inset);
    color: var(--text-2);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.catalog-opt:hover:not(:disabled) {
    border-color: var(--accent-dim);
    color: var(--text-1);
}

/* The selected one is filled, not merely outlined: at this size an outline
   alone is lost among three others sitting right beside it. */
.catalog-opt[aria-pressed="true"] {
    border-color: var(--accent);
    background: rgba(255, 158, 44, 0.10);
    color: var(--text-1);
}

.catalog-opt:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(255, 158, 44, 0.28);
}

.catalog-opt:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.catalog-opt-name {
    font-family: var(--font-display);
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.15;
}

.catalog-opt-meta {
    font-family: var(--font-mono);
    font-size: 9.5px;
    letter-spacing: 0.03em;
    color: var(--text-3);
    line-height: 1.2;
}

.catalog-opt[aria-pressed="true"] .catalog-opt-meta {
    color: var(--accent);
}

/* Live LED + state pill under the dropdown, showing what the assigned
   printer is doing right now rather than just that one is picked. */
.operator-station {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    margin-bottom: var(--sp-2);
}

.progress-track {
    height: 5px;
    background: var(--bg-inset);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: var(--sp-2);
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
}

.empty-state {
    text-align: center;
    padding: var(--sp-6) var(--sp-4);
    color: var(--text-3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
}

.empty-state .bx-icon {
    color: var(--line-strong);
}

.empty-state p {
    font-size: 13px;
}

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

label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    margin-bottom: var(--sp-1);
}

input[type="range"] {
    width: 100%;
    height: 22px;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    cursor: pointer;
    margin-bottom: var(--sp-2);
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--bg-inset);
    border: 1px solid var(--line);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -6px;
    background: var(--accent);
    border: 1px solid var(--accent-ink);
    border-radius: var(--radius);
}

input[type="range"]::-moz-range-track {
    height: 4px;
    background: var(--bg-inset);
    border: 1px solid var(--line);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--accent);
    border: 1px solid var(--accent-ink);
    border-radius: var(--radius);
}

/* ---------- Storage panel ---------- */

.storage-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
}

.storage-summary-item {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: var(--sp-2) var(--sp-3);
    text-align: center;
}

.storage-summary-value {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--accent);
}

.storage-summary-label {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
    margin-top: 2px;
}

.storage-row {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 8px 2px;
    margin-bottom: 0;
}

.storage-row:last-child {
    border-bottom: none;
}

.storage-row:hover {
    background: var(--bg-2);
}

.storage-color {
    width: 12px;
    height: 12px;
    border-radius: var(--radius);
    background: var(--mat, #888);
    border: 1px solid rgba(0, 0, 0, 0.4);
    flex: none;
}

.storage-name {
    flex: 1;
    font-size: 13px;
    color: var(--text-1);
}

.storage-kg {
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text-2);
}

/* ---------- Save slots ---------- */

.slot-row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    border-left: 3px solid transparent;
    border-radius: 0;
    padding: 10px 2px 10px var(--sp-2);
    margin-bottom: 0;
}

.slot-row:last-child {
    border-bottom: none;
}

.slot-row.slot-active {
    border-left-color: var(--accent);
    background: var(--bg-2);
}

.slot-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.slot-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-1);
}

.slot-active .slot-name {
    color: var(--accent);
}

.slot-when {
    font-family: var(--font-mono);
    font-size: 11px;
}

.slot-actions {
    display: flex;
    gap: var(--sp-2);
}

.slot-delete.confirm {
    background: var(--bad);
    color: #2b0f0c;
    border-color: var(--bad);
    animation: pulse 0.6s ease-in-out infinite;
}

/* ---------- Button rows ---------- */

.btn-row {
    display: flex;
    gap: var(--sp-2);
}

.btn-row-wrap {
    flex-wrap: wrap;
}

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

.text-success { color: var(--ok); }
.text-danger { color: var(--bad); }

/* Two-step order cancel */
.cancel-confirm {
    margin-top: var(--sp-2);
    padding-top: var(--sp-2);
    border-top: 1px solid var(--line);
}

.cancel-confirm .card-sub {
    margin-bottom: var(--sp-1);
}
.text-warning { color: var(--warn); }
.text-muted { color: var(--text-3); }
.text-center { text-align: center; }
.mt-1 { margin-top: var(--sp-2); }
.mt-2 { margin-top: var(--sp-4); }
.mb-1 { margin-bottom: var(--sp-2); }
.mb-2 { margin-bottom: var(--sp-4); }

/* ---------- Settings: mixer rows ----------
   Label, slider, readout and switch on one line, collapsing to two lines when
   the modal is narrow (which on a phone it always is). */

.setting-row {
    display: grid;
    grid-template-columns: minmax(88px, 1fr) minmax(0, 2fr) 44px auto;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-1) 0;
}

.setting-row .setting-label {
    margin: 0;
    font-size: 12.5px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.setting-row .setting-slider {
    margin: 0;
    min-width: 0;
}

.setting-row .setting-slider:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.setting-row .setting-value {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-3);
    text-align: right;
}

.setting-row .setting-switch {
    min-width: 54px;
}

@media (max-width: 560px) {
    .setting-row {
        grid-template-columns: 1fr 44px auto;
    }

    .setting-row .setting-label {
        grid-column: 1 / -1;
    }
}
