:root {
    --bg: #f4f7fb;
    --surface: rgba(255, 255, 255, 0.9);
    --surface-strong: #ffffff;
    --text: #152033;
    --muted: #6c7688;
    --line: rgba(21, 32, 51, 0.08);
    --brand: #0f6fff;
    --brand-2: #19b486;
    --shadow: 0 18px 40px rgba(15, 31, 61, 0.12);
    --sidebar-bg: linear-gradient(180deg, #08182f 0%, #0f213d 100%);
    --topbar-btn-bg: #eef4ff;
    --topbar-btn-border: rgba(15, 111, 255, 0.18);
    --topbar-btn-text: #1c4fb7;
    --table-head: #eef3fb;
    --table-row: rgba(255, 255, 255, 0.82);
}

[data-theme="dark"] {
    --bg: #08111f;
    --surface: rgba(10, 21, 39, 0.86);
    --surface-strong: #0d1b30;
    --text: #edf3ff;
    --muted: #8a99b5;
    --line: rgba(237, 243, 255, 0.08);
    --brand: #5da0ff;
    --brand-2: #20d39b;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
    --sidebar-bg: linear-gradient(180deg, #08182f 0%, #0f213d 100%);
    --topbar-btn-bg: rgba(255,255,255,.04);
    --topbar-btn-border: rgba(255,255,255,.12);
    --topbar-btn-text: #edf3ff;
    --table-head: rgba(255,255,255,.06);
    --table-row: transparent;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Manrope", sans-serif;
    font-size: 14px;
    background:
        radial-gradient(circle at top left, rgba(25, 180, 134, 0.14), transparent 28%),
        radial-gradient(circle at top right, rgba(15, 111, 255, 0.16), transparent 30%),
        var(--bg);
    color: var(--text);
}
a { text-decoration: none; }
html, body { overflow-x: hidden; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.sidebar {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 24px;
    background: var(--sidebar-bg);
    color: #fff;
    position: sticky;
    top: 0;
    min-height: 100vh;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand strong { font-size: 1.32rem; letter-spacing: .02em; }
.brand-subtitle { color: rgba(255,255,255,.72); font-size: .86rem; }
.brand-badge {
    width: 48px; height: 48px; border-radius: 16px;
    display: grid; place-items: center; overflow: hidden; flex: 0 0 auto;
    background: #f4efeb;
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,.14),
        0 10px 22px rgba(0,0,0,.26);
}
.brand-badge-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center 41%;
    transform: scale(1.55);
    filter: contrast(1.08) saturate(.82);
}
.nav-link {
    color: rgba(255,255,255,.9);
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255,255,255,.04);
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.1); }
.content { padding: 20px; min-width: 0; }
.topbar {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    margin-bottom: 20px; padding: 18px 20px; border-radius: 24px;
    background: var(--surface); backdrop-filter: blur(12px); box-shadow: var(--shadow);
}
.topbar-btn {
    background: var(--topbar-btn-bg);
    color: var(--topbar-btn-text);
    border: 1px solid var(--topbar-btn-border);
}
.topbar-btn:hover,
.topbar-btn:focus {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.page-title { margin: 0; font-size: clamp(1.22rem, 1.5vw, 1.72rem); font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted-small { color: var(--muted); font-size: .84rem; }
.sidebar-user { color: #fff; font-weight: 700; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stats-grid.compact { grid-template-columns: repeat(3, 1fr); }
.stat-card, .panel, .auth-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
    box-shadow: var(--shadow); backdrop-filter: blur(12px);
}
.stat-card { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.stat-card strong { font-size: clamp(1.28rem, 1.6vw, 1.82rem); }
.stat-card.accent { background: linear-gradient(135deg, rgba(15,111,255,.15), rgba(25,180,134,.12)); }
.compact-card { padding: 16px; border-radius: 18px; }
.compact-card strong { font-size: 1.8rem; }
.panel { padding: 20px; overflow: hidden; }
.panel.subtle { background: var(--surface-strong); }
.production-form,
.production-form .row,
.panel form,
.panel .row {
    min-width: 0;
}
.form-control,
.form-select,
textarea {
    max-width: 100%;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.panel-head.wrap { flex-wrap: wrap; }
.panel h2, .panel h3 { margin: 0; font-weight: 800; }
.grid-2, .grid-3 { display: grid; gap: 16px; align-items: start; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.production-summary {
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(15, 111, 255, 0.06);
    color: var(--text);
}
.production-components {
    border-top: 1px solid var(--line);
    padding-top: 16px;
}
.component-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.component-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 180px 120px;
    gap: 10px;
    align-items: center;
}
.component-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.component-badge,
.availability-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(15, 111, 255, 0.08);
    color: var(--text);
}
.component-badge small {
    color: var(--muted);
}
.availability-chip.success {
    background: rgba(25, 180, 134, 0.12);
    color: #0b7c5e;
}
.availability-chip.danger {
    background: rgba(255, 95, 109, 0.12);
    color: #b72c41;
}
.chart-shell {
    position: relative;
    width: 100%;
    height: 320px;
    margin-top: 16px;
}
.chart-shell canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}
.list-stack { display: flex; flex-direction: column; gap: 12px; }
.list-row, .notice {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 14px 16px; border-radius: 18px; background: rgba(255,255,255,.04); border: 1px solid var(--line);
}
.inventory-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.inventory-card {
    background: var(--surface-strong);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 18px;
    box-shadow: var(--shadow);
}
.inventory-card-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}
.inventory-card h3 {
    margin: 0;
    font-size: 1.2rem;
}
.inventory-stats {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.inventory-stats span {
    display: block;
    color: var(--muted);
    font-size: .85rem;
}
.inventory-stats strong {
    display: block;
    font-size: 1.05rem;
}
.inventory-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-start;
}
.inventory-adjust-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    flex: 1 1 100%;
}
.inventory-adjust-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    flex: 1 1 100%;
    align-items: stretch;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(15, 111, 255, 0.04);
}
.inventory-adjust-form.writeoff {
    background: rgba(255, 95, 109, 0.04);
}
.inventory-adjust-label {
    display: flex;
    align-items: center;
    font-weight: 700;
    color: var(--text);
}
.inventory-adjust-controls {
    display: grid;
    grid-template-columns: minmax(0, 170px) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
}
.inventory-qty-wrap {
    position: relative;
    min-width: 0;
}
.inventory-qty-wrap .form-control {
    padding-right: 52px;
}
.inventory-unit {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: .83rem;
    pointer-events: none;
}
.inventory-apply-btn {
    width: 100%;
    min-height: 40px;
}
.inventory-editor {
    flex: 1 1 100%;
}
.inventory-editor summary {
    list-style: none;
}
.inventory-editor summary::-webkit-details-marker {
    display: none;
}
.inventory-thumb {
    width: 64px;
    height: 64px;
}
.toggle-panel[hidden] {
    display: none !important;
}
.catalog-tabs {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.catalog-tab {
    display: inline-flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.5);
    color: var(--text);
    font-weight: 700;
}
.catalog-tab.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.production-shortage-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.shortage-item {
    justify-content: flex-start;
    border-radius: 14px;
}
.order-row { align-items: center; }
.order-meta { min-width: 180px; }
.min-w-0 { min-width: 0; }
.product-thumb {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.06);
}
.notice.read { opacity: .68; }
.badge-notify {
    position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; border-radius: 999px;
    display: grid; place-items: center; background: #ff5f6d; color: #fff; font-size: .75rem;
}
.table { --bs-table-bg: transparent; --bs-table-border-color: var(--line); margin-bottom: 0; }
.app-table { color: var(--text); }
.app-table thead th {
    background: var(--table-head);
    color: var(--text);
    border-bottom: 1px solid var(--line);
}
.app-table tbody td {
    background: var(--table-row);
    color: var(--text);
}
.app-table.table-hover tbody tr:hover td {
    background: rgba(15, 111, 255, 0.08);
    color: var(--text);
}
.table-dark,
.table-dark > :not(caption) > * > * {
    background-color: var(--table-row) !important;
    color: var(--text) !important;
    border-color: var(--line) !important;
}
.table-dark thead th {
    background: var(--table-head) !important;
    color: var(--text) !important;
}
.table-dark.table-hover tbody tr:hover td {
    background: rgba(15, 111, 255, 0.08) !important;
    color: var(--text) !important;
}
.btn-outline-light {
    color: var(--topbar-btn-text);
    border-color: var(--topbar-btn-border);
}
.btn-outline-light:hover,
.btn-outline-light:focus {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.quantity-input { width: 90px; }
.note-input { min-width: 140px; }
.status-select { min-width: 130px; }
.auth-shell {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(15,111,255,.28), transparent 25%),
        radial-gradient(circle at bottom right, rgba(25,180,134,.22), transparent 30%),
        #08111f;
}
.auth-card { width: min(100%, 520px); padding: 32px; color: #edf3ff; background: rgba(6, 16, 31, 0.88); }
.auth-card.wide { width: min(100%, 760px); }
.eyebrow { text-transform: uppercase; letter-spacing: .18em; font-size: .78rem; color: #8fc3ff; margin-bottom: 10px; }
.auth-title { font-size: clamp(2rem, 3vw, 3rem); font-weight: 800; margin-bottom: 10px; }
.auth-subtitle { color: #a9b9d3; }
.tags { display: flex; flex-wrap: wrap; gap: 10px; }
.tags span, .permission-item {
    padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,.03);
}
.permissions-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-height: 420px; overflow: auto; }
.permission-item { display: flex; align-items: center; gap: 10px; }
.sidebar-footer { padding-top: 18px; border-top: 1px solid rgba(255,255,255,.08); }
.production-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.production-card-item,
.settings-card {
    padding: 16px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.52);
}
.settings-market-grid {
    align-items: stretch;
}
.production-request-wrap {
    display: flex;
    justify-content: center;
}
.production-request-form {
    width: min(100%, 760px);
}
.production-list-panel {
    max-width: 100%;
}
.table-responsive {
    overflow-x: auto;
}

@media (max-width: 991px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: relative; min-height: auto; }
    .stats-grid, .stats-grid.compact, .grid-2, .grid-3, .inventory-grid, .inventory-adjust-grid, .production-cards-grid { grid-template-columns: 1fr; }
    .component-row { grid-template-columns: 1fr; }
    .inventory-card-head,
    .inventory-adjust-form { grid-template-columns: 1fr; display: grid; }
    .inventory-adjust-controls { grid-template-columns: 1fr; }
    .inventory-stats { justify-content: flex-start; }
}

@media (max-width: 640px) {
    .content { padding: 12px; }
    .topbar, .panel, .stat-card, .auth-card { border-radius: 18px; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .chart-shell { height: 260px; }
}
