:root {
    --bg: #0f172a;
    --panel: #111827;
    --panel-light: #1f2937;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #374151;
    --accent: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #38bdf8;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: #0b1220;
    color: var(--text);
}

a { color: #93c5fd; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand a { color: white; font-weight: 700; font-size: 1.2rem; }
.nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.nav a { color: var(--text); }

.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.page-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}
.page-header h1 { margin: 0; }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }
.success-text { color: #86efac; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .65rem .95rem;
    border-radius: 10px;
    border: 1px solid transparent;
    background: var(--accent);
    color: #052e16;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn-secondary {
    background: transparent;
    border-color: var(--line);
    color: var(--text);
}
.btn-danger {
    background: var(--danger);
    color: white;
}

input, select, textarea {
    width: 100%;
    padding: .7rem .8rem;
    margin-top: .35rem;
    margin-bottom: .9rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--panel-light);
    color: var(--text);
}
label { display: block; font-weight: 600; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-span-2 { grid-column: span 2; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.stats-grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.import-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 1rem; }
.stat-card strong { font-size: 2rem; display: block; }
.stat-label { color: var(--muted); display: block; margin-bottom: .4rem; }
.two-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.detail-grid {
    display: grid;
    grid-template-columns: 1.4fr .8fr;
    gap: 1rem;
}

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: .7rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
.table th { color: var(--muted); font-size: .92rem; }
.compact th, .compact td { padding: .55rem; }
.table-scroll { overflow-x: auto; }
.preview-table td, .preview-table th { white-space: nowrap; }

.thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--line);
}
.large-thumb { width: 90px; height: 90px; }
.thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--panel-light);
    color: var(--muted);
}
.detail-image {
    width: 100%;
    max-height: 420px;
    object-fit: contain;
    border-radius: 12px;
    background: white;
}
.detail-list {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: .65rem 1rem;
    margin: 0;
}
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; }
.actions, .actions-inline { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}
.filter-form .actions { margin-top: .5rem; }
.stack-form { display: grid; gap: .5rem; }
.inline-form { margin-top: .6rem; }
.inline-checkbox { display: flex; align-items: center; gap: .6rem; margin: .6rem 0; }
.inline-checkbox input { width: auto; margin: 0; }
.padded-top { padding-top: 1.85rem; }
.subsection { margin-top: 1rem; }
.tree, .root-tree { list-style: none; padding-left: 1rem; }
.tree-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    padding: .75rem 0;
    border-bottom: 1px dashed var(--line);
}
.tree-actions { display: flex; gap: .6rem; align-items: flex-start; }

.stat-link { display: block; color: inherit; }
.stat-link:hover { text-decoration: none; border-color: #4b5563; }
.stat-hint { display: block; margin-top: .5rem; color: var(--muted); font-size: .9rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.empty-block { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.small { font-size: .88rem; }

.category-cascade {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: .8rem;
}
.cascade-level { min-width: 0; }

.tree-node { margin-bottom: .35rem; }
.tree-main {
    display: flex;
    align-items: flex-start;
    gap: .7rem;
    min-width: 0;
}
.tree-toggle {
    width: 32px;
    min-width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel-light);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
}
.tree-toggle-empty {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--muted);
}
.tree-collapsed { display: none; }
.category-edit-form { min-width: 420px; }

.badge {
    display: inline-flex;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 700;
    border: 1px solid transparent;
    text-transform: uppercase;
}
.badge-in, .badge-initial, .badge-import {
    background: rgba(34, 197, 94, .15);
    color: #86efac;
    border-color: rgba(34, 197, 94, .35);
}
.badge-out {
    background: rgba(239, 68, 68, .15);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, .35);
}
.badge-adjustment {
    background: rgba(245, 158, 11, .15);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, .35);
}

.notice-box {
    border: 1px dashed var(--line);
    border-radius: 12px;
    padding: .9rem;
    color: var(--muted);
    background: rgba(255,255,255,0.02);
}
.error-card {
    border-color: rgba(239, 68, 68, .45);
    color: #fecaca;
    background: rgba(127, 29, 29, .35);
}
.error-list {
    margin: .5rem 0 0;
    padding-left: 1.1rem;
}
.mapping-grid { margin-top: 1rem; }
.import-layout { align-items: start; }

@media (max-width: 1024px) {
    .grid-4, .grid-3, .stats-grid, .stats-grid.five, .two-columns, .detail-grid, .import-stats { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .grid-span-2 { grid-column: span 1; }
    .detail-list { grid-template-columns: 1fr; }
    .page-header, .section-head, .empty-block { flex-direction: column; align-items: flex-start; }
    .category-edit-form { min-width: 0; }
    .padded-top { padding-top: 0; }
}

.persistent-banner {
    background: #166534;
    color: white;
    font-weight: 700;
    text-align: center;
    padding: .7rem 1rem;
}
.scanbar-wrap {
    padding: 1rem 1.5rem 0;
}
.scanbar {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    gap: .75rem;
}
.scanbar input { margin: 0; }
.btn-small { padding: .45rem .7rem; }
.narrow { max-width: 560px; }
.login-card { margin-top: 4rem; }
.flash { padding: .9rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.flash-error { background: rgba(239, 68, 68, .15); border: 1px solid rgba(239, 68, 68, .35); color: #fecaca; }
.reset-box {
    margin-top: 1rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-light);
}
.qr-block { display: grid; gap: 1rem; }
.qr-preview {
    width: 180px;
    height: 180px;
    background: white;
    padding: .5rem;
    border-radius: 12px;
    border: 1px solid var(--line);
}
code {
    background: rgba(255,255,255,.08);
    padding: .15rem .35rem;
    border-radius: 6px;
}
@media (max-width: 900px) {
    .scanbar, .topbar, .page-header, .actions-inline, .two-columns, .detail-grid, .stats-grid, .grid-4, .grid-3, .grid-2 {
        display: block;
    }
    .scanbar button, .actions-inline > * { margin-top: .5rem; }
}

.persistent-banner {
    background: #22c55e;
    color: #000;
    font-weight: 700;
    padding: .8rem 1.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, .2);
}

.demo-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    border-color: rgba(34, 197, 94, .45);
}

.demo-card h2 {
    margin-top: 0;
    margin-bottom: .4rem;
}

code {
    background: rgba(255,255,255,.06);
    padding: .15rem .4rem;
    border-radius: 6px;
}

@media (max-width: 1100px) {
    .stats-grid.five,
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .two-columns,
    .detail-grid,
    .demo-card {
        grid-template-columns: 1fr;
        display: grid;
    }
}

@media (max-width: 700px) {
    .topbar,
    .page-header,
    .section-head,
    .empty-block {
        align-items: flex-start;
        flex-direction: column;
    }

    .stats-grid.five,
    .stats-grid,
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .container {
        padding: 1rem;
    }
}
