:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-muted: #f6f8fb;
    --border: #e3e7ee;
    --border-strong: #d4d9e2;
    --text: #1f2a3c;
    --text-muted: #5f6b7d;
    --text-faint: #8a94a5;
    --primary: #3b5bdb;
    --primary-hover: #3049b8;
    --primary-soft: #eef1fd;
    --success-bg: #e8f6ee;
    --success-text: #2b7a4b;
    --neutral-bg: #eef0f4;
    --neutral-text: #5f6b7d;
    --warning-bg: #fdf3e2;
    --warning-text: #9a6212;
    --danger-bg: #fdecec;
    --danger-text: #b42318;
    --radius: 10px;
    --radius-sm: 7px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 224px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 24px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand { padding: 0 10px 20px; }
.brand-name {
    display: flex; align-items: center; gap: 8px;
    font-size: 20px; font-weight: 800; color: var(--text); letter-spacing: -0.02em;
}
.brand-name:hover { text-decoration: none; }
.brand-mark {
    width: 16px; height: 16px; border-radius: 3px;
    background:
        linear-gradient(var(--text) 0 0) 0 0 / 5px 5px,
        linear-gradient(var(--text) 0 0) 6.5px 0 / 5px 5px,
        linear-gradient(var(--text) 0 0) 13px 0 / 5px 5px,
        linear-gradient(var(--text) 0 0) 0 6.5px / 5px 5px,
        linear-gradient(var(--text) 0 0) 6.5px 6.5px / 5px 5px,
        linear-gradient(var(--text) 0 0) 13px 6.5px / 5px 5px,
        linear-gradient(var(--text) 0 0) 0 13px / 5px 5px,
        linear-gradient(var(--text) 0 0) 6.5px 13px / 5px 5px,
        linear-gradient(var(--text) 0 0) 13px 13px / 5px 5px;
    background-repeat: no-repeat;
}
.brand-sub {
    margin-top: 4px; font-size: 9px; letter-spacing: 0.2em;
    text-transform: uppercase; color: var(--text-faint);
}

.nav-section {
    margin: 0;
    font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase;
    color: var(--text-faint); font-weight: 500; padding: 16px 12px 5px; }

.nav-link {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 12px; margin: 1px 0; }
.nav-link:hover { background: var(--surface-muted); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link.disabled { color: var(--text-faint); cursor: default; }
.nav-link.disabled:hover { background: none; }
.nav-soon {
    font-size: 10px; padding: 1px 6px; border-radius: 99px;
    background: var(--neutral-bg); color: var(--text-faint);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 28px 32px 20px; flex: 1; max-width: 1500px; width: 100%; }
.footer { padding: 12px 32px 24px; font-size: 10px; color: var(--text-faint); }

/* ---------- Page header ---------- */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.eyebrow {
    font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
    color: var(--text-faint); margin-bottom: 6px;
}
.page-title { margin: 0; font-size: 27px; font-weight: 650; letter-spacing: -0.02em; }
.page-subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 14px; border-radius: 6px;
    font: inherit; font-weight: 600; font-size: 12px;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-muted); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 11px; }
.btn-icon { width: 36px; padding: 0; }
.btn[disabled], .btn.is-disabled { opacity: 0.55; cursor: not-allowed; }
.btn.is-disabled:hover { background: var(--surface); }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px; margin-bottom: 20px;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-title { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.card-title + .card-header-actions { margin-left: auto; }

/* ---------- Forms ---------- */
.form-grid {
    display: grid; gap: 14px 16px;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.form-grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row-single { margin-bottom: 18px; max-width: calc(20% - 19px); min-width: 220px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.input, .select, .textarea {
    width: 100%; height: 38px; padding: 0 10px;
    font: inherit; font-size: 13px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: 5px; outline: none;
}
.textarea { padding: 8px 10px; resize: vertical; min-height: 38px; line-height: 1.4; }
.select {
    appearance: none; -webkit-appearance: none; padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%231f2a3c' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 91, 219, 0.15);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input[readonly], .select[disabled] { background: var(--surface-muted); color: var(--text-muted); }
.is-invalid { border-color: var(--danger-text) !important; }
.field-error { color: var(--danger-text); font-size: 11px; }

.form-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.hint { font-size: 11px; }
.input-file { height: auto; padding: 7px 10px; }
.input-unit { position: relative; }
.input-unit .input { padding-right: 84px; }
.unit { color: var(--text-faint); font-size: 11px; }
.input-unit-label {
    position: absolute; right: 28px; top: 50%; transform: translateY(-50%);
    font-size: 11px; color: var(--text-faint); pointer-events: none; white-space: nowrap;
}

.checkbox-group {
    margin: 0; padding: 12px 18px 14px; min-width: 0;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.checkbox-group legend { padding: 0 6px; font-size: 12px; font-weight: 500; color: var(--text-muted); }
.checkbox { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 13px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }

/* ---------- Detail pages ---------- */
.disclosure summary { cursor: pointer; list-style: revert; }
.disclosure-body { margin-top: 14px; }
.item-image {
    display: block; max-width: 280px; max-height: 280px; object-fit: contain;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-muted);
}
.image-form { margin-top: 18px; max-width: 420px; }
.summary-line { margin: 0 0 16px; font-size: 13px; }

/* ---------- Filters (dashboard) ---------- */
.filters {
    display: grid; gap: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
    align-items: end; margin-bottom: 16px;
}
.help-text { color: var(--text-muted); margin: 0 0 6px; font-size: 13px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; gap: 16px; grid-template-columns: repeat(5, minmax(0, 1fr)); margin: 18px 0 20px; }
.kpi {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px;
}
.kpi-label { font-size: 11px; color: var(--text-muted); }
.kpi-value { margin-top: 12px; font-size: 25px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }

.mini-stats { display: grid; gap: 16px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.mini-stat {
    display: block; padding: 12px 14px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface-muted); color: var(--text);
}
.mini-stat:hover { border-color: var(--primary); text-decoration: none; }
.mini-stat-label { font-size: 11px; color: var(--text-muted); }
.mini-stat-value { font-size: 18px; font-weight: 700; margin-top: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table th {
    background: var(--surface-muted); text-align: left;
    font-size: 10px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
    color: var(--text-muted); padding: 12px 10px; white-space: nowrap;
}
.table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * + * { margin-left: 6px; }
.empty { padding: 28px 10px; text-align: center; color: var(--text-faint); }

/* ---------- BOM lines ---------- */
.lines-table td { border-bottom: none; padding: 8px 10px; }
.lines-table td:first-child { width: 45%; }
.lines-table td:last-child { width: 1%; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; padding: 3px 8px; border-radius: 5px;
    font-size: 10px; font-weight: 500; text-transform: capitalize;
}
.badge-active, .badge-posted { background: var(--success-bg); color: var(--success-text); }
.badge-inactive, .badge-draft, .badge-archived { background: var(--neutral-bg); color: var(--neutral-text); }
.badge-warn { background: var(--warning-bg); color: var(--warning-text); }
.badge-block { background: var(--danger-bg); color: var(--danger-text); }
.badge-open { background: var(--primary-soft); color: var(--primary); }
.badge-partial, .badge-pending_qc { background: var(--warning-bg); color: var(--warning-text); }
.badge-released { background: var(--primary-soft); color: var(--primary); }
.badge-in_progress, .badge-in_production { background: var(--warning-bg); color: var(--warning-text); }
.badge-consumed { background: var(--neutral-bg); color: var(--neutral-text); }
.badge-received, .badge-qc_checked, .badge-completed { background: var(--success-bg); color: var(--success-text); }

/* ---------- Detail view ---------- */
.detail-grid { display: grid; gap: 18px 24px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.detail-label { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.1em; }
.detail-value { margin-top: 4px; font-size: 14px; font-weight: 500; word-break: break-word; }

/* ---------- Alerts ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 13px; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--danger-bg); color: var(--danger-text); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Activity ---------- */
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 7px 0; font-size: 13px; }
.activity time { color: var(--text-muted); }

/* ---------- Search + pagination ---------- */
.search { display: flex; gap: 8px; }
.search .input { height: 34px; width: 240px; font-size: 13px; }
.search .btn { height: 34px; }
.pagination { display: flex; gap: 6px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 30px; height: 30px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 12px; color: var(--text);
}
.pagination .current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .disabled { color: var(--text-faint); }

.muted { color: var(--text-muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Responsive ---------- */
/* ---------- Purchasing documents ---------- */
.document-filters { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; }
.filter-actions { display: flex; gap: 8px; }
.document-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 22px; flex-wrap: wrap; }
.document-number { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.document-party { margin: 12px 0 4px; font-size: 14px; font-weight: 700; }
.document-meta { margin: 6px 0 0; font-size: 12px; }
.document-totals { text-align: right; font-size: 13px; line-height: 1.7; }
.document-notes { margin: 18px 0 0; font-size: 13px; }
.strong { font-weight: 700; }
.table tfoot td { padding: 10px 16px; border-bottom: none; }
.lines-table td .input, .lines-table td .select { min-width: 90px; }
.receipt-picker { max-width: 640px; }
.qc-box { margin-top: 18px; }
.qc-box .field { margin: 8px 0 4px; max-width: 360px; }
.qc-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.qc-form .field { width: 320px; }
.qc-stamp {
    display: inline-flex; align-items: center; gap: 14px; padding: 12px 18px;
    border: 1px solid var(--success-text); border-radius: var(--radius-sm); background: var(--success-bg);
}
.qc-stamp-mark {
    display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
    border-radius: 50%; background: var(--success-text); color: #fff; font-weight: 700;
}

/* ---------- Production ---------- */
.production-form-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.requirements-preview { margin-top: 22px; }
.section-title { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.text-danger { color: var(--danger-text); font-weight: 600; }
.compact-table th, .compact-table td { padding: 10px 8px; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 14px; }
.inline-form .field { width: 260px; }

/* ---------- Inventory ---------- */
.inventory-filters { grid-template-columns: repeat(3, minmax(0, 1fr)) auto auto; }
.movement-filters { grid-template-columns: repeat(5, minmax(0, 1fr)) auto; }
.filter-checkbox { height: 40px; }
.text-success { color: var(--success-text); font-weight: 600; }
.badge-movement-in { background: var(--success-bg); color: var(--success-text); }
.badge-movement-out { background: var(--warning-bg); color: var(--warning-text); }

/* ---------- Payroll ---------- */
.detail-row td { padding-top: 4px; padding-bottom: 8px; border-bottom: none; font-size: 13px; }
.detail-row td:first-child { padding-left: 32px; }

/* ---------- Sales ---------- */
.statement-balance { font-weight: 700; margin-right: 6px; font-size: 13px; }
.input-discount { max-width: 160px; margin-left: auto; text-align: right; }
.gate-pass-page { background: #fff; }
.gate-pass { max-width: 860px; margin: 32px auto; padding: 0 24px; }
.gate-pass-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--text); padding-bottom: 16px; }
.signatures { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; margin-top: 72px; }
.signatures div { border-top: 1px solid var(--text); padding-top: 8px; text-align: center; font-size: 13px; color: var(--text-muted); }

/* ---------- Access & workspace ---------- */
.topbar { display: flex; justify-content: flex-end; align-items: center; gap: 16px; padding: 0 32px; border-bottom: 1px solid var(--border); background: var(--surface); font-size: 12px; height: 64px; }
.topbar-user { font-weight: 600; color: var(--text); }
.link-button { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--primary); cursor: pointer; }
.brand-icon { width: 22px; height: 22px; object-fit: contain; border-radius: 4px; margin-right: 8px; vertical-align: -4px; }
.brand-preview { display: flex; align-items: center; gap: 4px; height: 40px; }
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; }
.role-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; }
.permission-matrix th.center, .permission-matrix td.center { text-align: center; }
.permission-matrix td { padding: 8px 16px; }
.permission-matrix input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
.matrix-group td { background: var(--surface-muted); font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
.report-filters { grid-template-columns: repeat(5, minmax(0, 1fr)) auto; }
.readiness { margin: 0; padding-left: 18px; line-height: 1.8; }
.print-only-title { display: none; }

/* ---------- Notifications ---------- */
.bell { position: relative; margin-right: auto; }
.bell > summary { list-style: none; position: relative; }
.bell > summary::-webkit-details-marker { display: none; }
.bell-count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger-text); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.bell-panel { position: absolute; left: 0; top: 42px; z-index: 50; width: 360px; max-height: 460px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(31, 42, 60, 0.14); }
.bell-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.bell-item { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; }
.bell-item:hover { background: var(--surface-muted); text-decoration: none; }
.bell-item.is-unread { background: var(--primary-soft); }
.bell-title { display: block; font-weight: 600; font-size: 14px; }
.bell-message { display: block; font-size: 13px; color: var(--text-muted); }
.bell-time { display: block; font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.bell-dot { display: inline-block; flex: none; width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; background: var(--primary); }
.bell-dot-stock_out { background: var(--danger-text); }
.bell-dot-low_stock { background: var(--warning-text); }
.bell-dot-production_completed { background: var(--success-text); }
.bell-empty { padding: 16px; margin: 0; font-size: 13px; }
.bell-all { display: block; padding: 10px 16px; text-align: center; font-size: 13px; font-weight: 600; }

@media print {
    .print-only-title { display: block; }

    .sidebar, .footer, .no-print, .alert { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; max-width: none; }
    .card { border: none; padding: 0; }
}

@media (max-width: 1280px) {
    .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .form-grid.cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .mini-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
    .content { padding: 24px 16px; }
    .footer { padding: 16px; }
    .kpis, .filters, .document-filters, .report-filters, .role-options, .inventory-filters, .movement-filters, .production-form-grid, .form-grid.cols-5, .form-grid.cols-3, .form-grid.cols-2, .mini-stats { grid-template-columns: 1fr 1fr; }
    .form-row-single { max-width: none; }
    .card { padding: 20px 16px; }
}
@media (max-width: 560px) {
    .kpis, .filters, .document-filters, .report-filters, .role-options, .inventory-filters, .movement-filters, .production-form-grid, .form-grid.cols-5, .form-grid.cols-3, .form-grid.cols-2, .mini-stats { grid-template-columns: 1fr; }
    .search .input { width: 100%; }
}
