:root {
    --bg: #0d1117;
    --bg-alt: #121923;
    --panel: rgba(18, 25, 35, 0.9);
    --panel-strong: rgba(20, 28, 39, 0.98);
    --text: #edf3fb;
    --muted: #94a3b8;
    --line: #2a394b;
    --line-strong: #37506b;
    --accent: #6ea0d6;
    --accent-strong: #9bc4ef;
    --good: #7db487;
    --warn: #c4975c;
    --danger: #c97f78;
    --chip: #16202b;
    --shadow: 0 22px 50px rgba(0, 0, 0, 0.32);
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    color: var(--text);
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    background:
        radial-gradient(circle at top right, rgba(110, 160, 214, 0.18), transparent 20%),
        radial-gradient(circle at left center, rgba(70, 94, 126, 0.12), transparent 26%),
        linear-gradient(180deg, #0a0f15 0%, #0d1117 100%);
}

body {
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

input,
select,
button {
    font: inherit;
}

.app-shell,
.login-shell {
    width: min(1920px, calc(100vw - 16px));
    margin: 0 auto;
    padding: 26px 0 40px;
}

.panel {
    background: var(--panel);
    border: 1px solid rgba(55, 80, 107, 0.7);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
}

.topbar h1,
.hero-panel h2,
.section-header h2,
.login-copy h1,
.login-card h2,
.blueprint-card h2 {
    margin: 0;
    letter-spacing: -0.03em;
}

.topbar h1 {
    font-size: clamp(2rem, 3vw, 3rem);
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.lede,
.muted {
    color: var(--muted);
}

.topbar-actions,
.toolbar,
.scanner-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar {
    width: min(100%, 760px);
    justify-content: flex-end;
}

.toolbar input[type="text"] {
    flex: 1 1 260px;
    min-width: 220px;
}

.topbar-pill,
.badge,
.callout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 7px 12px;
    background: var(--chip);
    border: 1px solid rgba(55, 80, 107, 0.8);
    color: var(--muted);
    font-size: 0.84rem;
}

.button,
button {
    border: 1px solid rgba(110, 160, 214, 0.24);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    background: #16202b;
    color: var(--text);
    cursor: pointer;
    transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.button:hover,
button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(74, 57, 34, 0.12);
}

.button-primary {
    background: var(--accent);
    color: #08111b;
    border-color: var(--accent);
}

.button-subtle {
    background: #121923;
}

.button-good {
    background: #152219;
    border-color: rgba(125, 180, 135, 0.3);
    color: var(--good);
}

.button-warn {
    background: #241c12;
    border-color: rgba(196, 151, 92, 0.3);
    color: var(--warn);
}

.button-danger {
    background: #261816;
    border-color: rgba(201, 127, 120, 0.3);
    color: var(--danger);
}

.button-small {
    padding: 8px 10px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    border: 1px solid rgba(55, 80, 107, 0.95);
    border-radius: var(--radius-sm);
    padding: 11px 12px;
    background: rgba(10, 15, 21, 0.95);
    color: var(--text);
}

input:focus,
select:focus {
    outline: 2px solid rgba(47, 93, 98, 0.15);
    border-color: var(--accent);
}

.hero-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 18px;
    margin-bottom: 18px;
}

.hero-panel,
.stat-card,
.login-copy,
.login-card {
    padding: 22px;
}

.hero-panel {
    overflow: hidden;
}

.attempts-table-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
}

.attempts-table-scroll {
    max-height: 395px;
    overflow-y: auto;
    border-top: 1px solid rgba(55, 80, 107, 0.55);
}

.attempts-table-scroll .data-table th,
.attempts-table-scroll .data-table td,
.attempts-table-shell > .data-table th,
.attempts-table-shell > .data-table td {
    border-top: none;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.stat-card {
    min-height: 140px;
}

.stat-label {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
}

.stat-value {
    display: block;
    margin-top: 14px;
    font-size: 2.2rem;
}

.section-stack {
    display: grid;
    gap: 18px;
    padding: 18px;
    margin-bottom: 18px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
}

.compact-form {
    display: grid;
    grid-template-columns: 2fr 1.2fr 1fr auto;
    gap: 12px;
    align-items: end;
}

.field-group {
    min-width: 0;
}

.field-group-wide {
    min-width: 0;
}

.field-group-checkbox {
    display: flex;
    align-items: center;
}

.field-group-action {
    display: flex;
}

.field-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.88rem;
}

.checkbox-line {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.checkbox-line.compact {
    font-size: 0.84rem;
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
    gap: 18px;
    margin-bottom: 18px;
}

.callouts {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.default-account {
    background: rgba(47, 93, 98, 0.12);
    color: var(--accent-strong);
}

.blueprint-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 320px));
    gap: 16px;
    justify-content: start;
}

.viewer-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.account-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.account-summary-card {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid rgba(55, 80, 107, 0.82);
    border-radius: var(--radius-md);
    background: rgba(15, 22, 32, 0.92);
    min-height: 150px;
}

.account-summary-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.account-summary-header strong {
    font-size: 1rem;
    line-height: 1.2;
    word-break: break-word;
}

.account-summary-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(56px, 1fr));
    gap: 10px;
}

.account-summary-stat {
    display: grid;
    gap: 4px;
}

.account-stat-label {
    color: var(--muted);
    font-size: 0.66rem;
    letter-spacing: 0.04em;
    line-height: 1.2;
    text-transform: uppercase;
}

.account-stat-value {
    font-size: 1.2rem;
    line-height: 1;
}

.blueprint-card {
    padding: 12px;
    border: 1px solid rgba(55, 80, 107, 0.82);
    border-radius: var(--radius-md);
    background: var(--panel-strong);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.tile-art {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    border-radius: 14px;
    border: 1px solid rgba(110, 160, 214, 0.18);
    background:
        linear-gradient(rgba(110, 160, 214, 0.11) 1px, transparent 1px),
        linear-gradient(90deg, rgba(110, 160, 214, 0.11) 1px, transparent 1px),
        linear-gradient(180deg, #101823, #0d141e);
    background-size: 18px 18px;
    padding: 16px;
}

.tile-art img {
    width: 56%;
    height: 56%;
    object-fit: contain;
}

.card-header {
    display: grid;
    gap: 10px;
    margin: 12px 0 10px;
}

.sort-row {
    display: grid;
    grid-template-columns: auto 84px;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.compact-label {
    margin-bottom: 0;
}

.sort-order-input {
    text-align: center;
}

.card-header h2 {
    font-size: 1.02rem;
    line-height: 1.25;
}

.card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.badge-good {
    color: var(--good);
    background: #152219;
}

.badge-warn {
    color: var(--warn);
    background: #241c12;
}

.badge-neutral {
    color: var(--accent-strong);
    background: rgba(110, 160, 214, 0.12);
}

.badge-hidden {
    color: #b9a4c0;
    background: #1e1623;
}

.account-matrix {
    display: grid;
    gap: 10px;
    margin: 10px 0 12px;
}

.account-row {
    display: grid;
    grid-template-columns: minmax(92px, 1fr) 76px 74px;
    gap: 10px;
    align-items: center;
}

.account-row-label {
    min-width: 0;
}

.account-row-label strong {
    display: block;
    overflow-wrap: anywhere;
}

.account-row .checkbox-line.compact {
    justify-self: start;
    gap: 6px;
    min-width: 0;
    font-size: 0.76rem;
}

.account-row .checkbox-line.compact span {
    white-space: nowrap;
}

.inventory-count {
    text-align: center;
}

.card-actions {
    display: grid;
    gap: 10px;
}

.transfer-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
        "from to"
        "qty submit";
    gap: 8px;
}

.transfer-form select[name="from_account_id"] {
    grid-area: from;
}

.transfer-form select[name="to_account_id"] {
    grid-area: to;
}

.transfer-form input[name="quantity"] {
    grid-area: qty;
    max-width: 88px;
}

.transfer-form button {
    grid-area: submit;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.save-status {
    margin-top: 6px;
    min-height: 1.2em;
}

.save-error {
    color: var(--danger);
}

.compact-table th,
.compact-table td {
    padding: 8px 8px;
    font-size: 0.83rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 12px 10px;
    border-top: 1px solid rgba(55, 80, 107, 0.55);
    vertical-align: top;
}

.data-table th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.9rem;
}

.token-cell {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.84rem;
    word-break: break-all;
}

.token-visit-list {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--muted);
    line-height: 1.35;
    word-break: break-all;
}

.empty-state {
    padding: 28px;
    border-radius: var(--radius-md);
    background: rgba(16, 24, 35, 0.75);
    border: 1px dashed rgba(55, 80, 107, 0.95);
    color: var(--muted);
    text-align: center;
}

.login-hero {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 20px;
    align-items: start;
}

.login-copy h1 {
    font-size: clamp(2.2rem, 3vw, 3.3rem);
    margin-bottom: 16px;
}

.login-stack {
    display: grid;
    gap: 18px;
}

.form-stack {
    display: grid;
    gap: 12px;
}

.message {
    margin-top: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.94rem;
}

.message-error {
    background: #261816;
    color: var(--danger);
    border: 1px solid rgba(201, 127, 120, 0.22);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: stretch;
    justify-content: center;
    padding: 22px;
    background: rgba(3, 7, 12, 0.62);
    backdrop-filter: blur(10px);
    z-index: 1000;
    overflow: auto;
}

.modal-overlay.open {
    display: flex;
}

.modal-panel {
    width: min(1180px, 100%);
    max-height: calc(100vh - 44px);
    padding: 22px;
    border-radius: var(--radius-lg);
    background: var(--panel-strong);
    border: 1px solid rgba(55, 80, 107, 0.82);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 16px;
    overflow: hidden;
    margin: auto;
}

.scanner-layout {
    display: grid;
    grid-template-columns: 0.9fr 1.1fr;
    gap: 16px;
    min-height: 0;
}

.scanner-side {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
}

.drop-zone {
    min-height: 240px;
    border: 2px dashed rgba(110, 160, 214, 0.34);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    text-align: center;
    color: var(--muted);
    background: linear-gradient(180deg, rgba(110, 160, 214, 0.06), rgba(12, 18, 26, 0.3));
    cursor: pointer;
}

.drop-zone.hover {
    border-color: var(--accent);
    background: linear-gradient(180deg, rgba(110, 160, 214, 0.12), rgba(12, 18, 26, 0.44));
}

.preview-image {
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(55, 80, 107, 0.8);
    background: #0d141e;
}

.row-warn td {
    color: var(--warn);
}

.scan-results-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
}

.scan-results-scroll {
    min-height: 0;
    overflow-y: auto;
    border-top: 1px solid rgba(55, 80, 107, 0.55);
}

.scan-results-scroll .data-table th,
.scan-results-scroll .data-table td,
.scan-results-shell > .data-table th,
.scan-results-shell > .data-table td {
    border-top: none;
}

.scanner-actions {
    margin-top: auto;
    padding-top: 4px;
}

@media (max-width: 1180px) {
    .hero-grid,
    .split-layout,
    .login-hero,
    .scanner-layout {
        grid-template-columns: 1fr;
    }

    .toolbar {
        width: 100%;
        justify-content: flex-start;
    }
}

@media (max-width: 880px) {
    .app-shell,
    .login-shell {
        width: calc(100vw - 12px);
        padding: 16px 0 28px;
    }

    .compact-form {
        grid-template-columns: 1fr;
    }

    .transfer-form {
        grid-template-columns: 1fr;
    }

    .account-row {
        grid-template-columns: 1fr;
    }

    .topbar,
    .section-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-actions,
    .toolbar,
    .scanner-actions {
        width: 100%;
    }

    .topbar-actions > *,
    .toolbar > *,
    .scanner-actions > * {
        width: 100%;
    }

    .toolbar input[type="text"] {
        min-width: 0;
        flex-basis: auto;
    }

    .blueprint-grid {
        grid-template-columns: minmax(0, 1fr);
        justify-content: stretch;
    }

    .blueprint-card {
        max-width: 420px;
        width: 100%;
        margin: 0 auto;
    }

    .account-summary-grid {
        grid-template-columns: 1fr;
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }

    .modal-overlay {
        padding: 10px;
    }

    .modal-panel {
        max-height: calc(100vh - 20px);
        padding: 16px;
    }

    .drop-zone {
        min-height: 180px;
    }

    .preview-image {
        max-height: 220px;
    }
}

@media (max-width: 560px) {
    .panel {
        border-radius: 16px;
    }

    .section-stack,
    .hero-panel,
    .stat-card,
    .login-copy,
    .login-card,
    .modal-panel,
    .scanner-side {
        padding: 14px;
    }

    .topbar h1 {
        font-size: 1.8rem;
    }

    .stat-grid {
        grid-template-columns: 1fr;
    }

    .blueprint-grid {
        gap: 12px;
    }

    .blueprint-card {
        max-width: 100%;
    }

    .account-summary-stats {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 8px;
    }
}
