:root {
    /* Navy палитр — Header/Sidebar/Hero-д зориулсан цорын ганц дизайны систем.
       Хуучин indigo (#12137A) tokens бүрэн УСТГАГДСАН — доор alias хэлбэрээр
       хуучин --navy/--bg/--surface/--text нэрсийг зөвхөн ЭНЭ палитр руу чиглүүлж,
       тэдгээрийг ашигладаг олон арван хуучин компонент (sidebar, table, form,
       button гэх мэт) кодыг өөрчлөхгүйгээр нэг мөр дизайн систем рүү шилжүүлнэ. */
    --navy-950: #080B24;
    --navy-900: #0D1338;
    --navy-800: #121A4A;
    --navy-700: #1B2560;
    --navy-600: #283374;
    --navy-glass-border: rgba(255, 255, 255, 0.18);
    --navy-hover-overlay: rgba(255, 255, 255, 0.10);
    --navy-active-overlay: rgba(255, 255, 255, 0.16);

    --bg-app: #F5F6FA;
    --bg-card: #FFFFFF;

    --text-on-navy: #FFFFFF;
    --text-on-navy-muted: rgba(255, 255, 255, 0.65);
    --text-primary: #12142B;
    --text-secondary: #6B7086;
    --text-tertiary: #9A9EB5;

    --border-subtle: #E6E8F0;
    --shadow-card: 0 2px 8px rgba(18, 20, 50, 0.06), 0 1px 2px rgba(18, 20, 50, 0.04);
    --shadow-card-hover: 0 12px 32px rgba(18, 20, 50, 0.12);
    --shadow-navy-glow: 0 8px 32px rgba(18, 26, 74, 0.35);

    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --radius-pill: 999px;

    --status-success-bg: #E6F7EF; --status-success-text: #1F9D63; --status-success-dot: #22C55E;
    --status-processing-bg: #E8F0FE; --status-processing-text: #2563D9; --status-processing-dot: #3B82F6;
    --status-pending-bg: #F1F2F6; --status-pending-text: #6B7086; --status-pending-dot: #9CA3AF;
    --status-warning-bg: #FFF6E5; --status-warning-text: #B8860B; --status-warning-dot: #F5A524;
    --status-critical-bg: #FDEAEC; --status-critical-text: #C0293D; --status-critical-dot: #EF4444;

    --font-primary: 'Inter', 'Segoe UI', system-ui, sans-serif;

    /* ---- Хуучин sidebar/table/form системийн нэрс — шинэ палитр руу alias ---- */
    --navy: var(--navy-800);
    --navy-hover: var(--navy-700);
    --navy-active: var(--navy-600);
    --bg: var(--bg-app);
    --surface: var(--bg-card);
    --border: var(--border-subtle);
    --border-strong: #C7CBD3;
    --text: var(--text-primary);
    --text-muted: var(--text-secondary);
    --text-faint: var(--text-tertiary);
    --radius-md-legacy: 8px;
}
* { box-sizing: border-box; }
body {
    font-family: var(--font-primary);
    margin: 0; background: var(--bg-app); color: var(--text-primary); font-size: 14px; line-height: 1.6;
}
.mono { font-family: "Consolas", "Courier New", monospace; }
a { color: inherit; }

.layout, .app-shell { display: flex; min-height: 100vh; }

/* ---------- Glass orb (гоёл чимэглэлийн элемент) ---------- */
.glass-orb {
    position: absolute; border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.35), rgba(255,255,255,0.03) 60%, transparent 70%);
    box-shadow: inset 0 0 20px rgba(255,255,255,0.15), 0 0 30px rgba(120,150,255,0.15);
    pointer-events: none; z-index: 0;
}
.glass-orb--lg { width: 140px; height: 140px; }
.glass-orb--md { width: 80px; height: 80px; }
.glass-orb--sm { width: 40px; height: 40px; }

/* ---------- Sidebar ---------- */
.sidebar, .app-sidebar {
    width: 232px; flex-shrink: 0; color: var(--text-on-navy-muted);
    background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-800) 100%);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
    overflow-y: auto; overflow-x: hidden;
}
.sidebar::-webkit-scrollbar, .app-sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb, .app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
.sidebar-brand {
    padding: 20px 20px 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.1);
    position: relative; z-index: 1;
}
.sidebar-brand .company, .sidebar-brand .brand-name { font-size: 1.05rem; font-weight: 700; color: var(--text-on-navy); letter-spacing: 0.2px; }
.sidebar-brand .subtitle, .sidebar-brand .brand-subtitle {
    font-size: 0.7rem; color: var(--text-on-navy-muted); margin-top: 2px;
    text-transform: uppercase; letter-spacing: 0.05em;
}
.sidebar-nav { padding: 12px 10px; flex: 1; position: relative; z-index: 1; }
.sidebar-nav .nav-heading {
    font-size: 0.7rem; font-weight: 600; color: var(--text-on-navy-muted); text-transform: uppercase; letter-spacing: 0.08em;
    padding: 16px 12px 8px 12px;
}
.nav-section-label {
    display: flex; justify-content: space-between; align-items: center; width: 100%;
    background: none; border: none; cursor: pointer; font: inherit;
    font-size: 0.7rem; font-weight: 600; color: var(--text-on-navy-muted); text-transform: uppercase; letter-spacing: 0.08em;
    padding: 16px 12px 8px 12px; text-align: left;
}
.nav-section-label .chevron { width: 14px; height: 14px; flex-shrink: 0; transition: transform 200ms ease; }
.nav-section-label.collapsed .chevron { transform: rotate(-90deg); }
.nav-group-items { max-height: 500px; overflow: hidden; transition: max-height 250ms ease; }
.nav-group-items.collapsed { max-height: 0; }
.sidebar-nav a, .nav-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 2px;
    border-radius: var(--radius-sm); text-decoration: none; color: var(--text-on-navy-muted); font-size: 0.9rem;
    transition: background 150ms ease, color 150ms ease;
}
.sidebar-nav a:hover, .nav-item:hover { background: var(--navy-hover-overlay); color: var(--text-on-navy); }
.sidebar-nav a.active, .nav-item.active { background: var(--navy-active-overlay); color: var(--text-on-navy); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.nav-label { flex: 1; }
.bell { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
        border-radius: 50%; color: inherit; text-decoration: none; }
.bell:hover { background: rgba(127, 127, 127, 0.12); }
.bell svg { width: 22px; height: 22px; }
.bell-count { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
              background: #C8553D; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.nav-badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: #C8553D; color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.nav-count { font-size: 11.5px; color: var(--text-on-navy-muted); }
.sidebar-nav a:hover .nav-count, .sidebar-nav a.active .nav-count { color: var(--text-on-navy); }
.sidebar-foot { padding: 14px 20px; font-size: 11px; color: var(--text-on-navy-muted); border-top: 1px solid rgba(255,255,255,0.1); position: relative; z-index: 1; }

/* ---------- Topbar (avatar + logout, .main-ийн эхэнд, edge-to-edge bleed) ---------- */
.app-topbar {
    background: var(--navy-800); color: var(--text-on-navy);
    padding: 16px 32px; margin: -28px -36px 24px -36px;
    display: flex; justify-content: flex-end; align-items: center; gap: 16px;
}
.app-topbar .user-info { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.app-topbar a.logout-link, .app-topbar a.login-link { color: var(--text-on-navy-muted); text-decoration: none; font-size: 0.85rem; }
.app-topbar a.logout-link:hover, .app-topbar a.login-link:hover { color: var(--text-on-navy); }
.avatar-circle {
    width: 32px; height: 32px; border-radius: 50%; background: var(--navy-700); color: var(--text-on-navy);
    display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600; flex-shrink: 0;
}

/* ---------- Main content ---------- */
.main, .app-main { flex: 1; min-width: 0; padding: 28px 36px 40px 36px; background: var(--bg-app); }
.page-title { font-size: 19px; font-weight: 700; margin: 0 0 4px 0; }
.page-sub { font-size: 13px; color: var(--text-muted); margin: 0 0 22px 0; }
.page-sub .accent-tag {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px;
}

/* ---------- Toolbar (search + pagination) ---------- */
.toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
    padding: 12px 14px; margin-bottom: 16px; flex-wrap: wrap;
}
form.search { display: flex; align-items: center; gap: 8px; }
form.search input[type=text] {
    padding: 8px 12px; width: 280px; border: 1px solid var(--border-strong); border-radius: 3px;
    font-size: 13.5px; background: var(--bg);
}
form.search input[type=text]:focus { outline: 2px solid var(--navy); outline-offset: -1px; background: var(--surface); }
form.search button {
    padding: 8px 16px; border: 1px solid var(--navy); background: var(--navy); color: white;
    border-radius: 3px; cursor: pointer; font-size: 13.5px; font-weight: 600;
}
form.search button:hover { background: var(--navy-hover); }
a.clear-link { font-size: 12.5px; color: var(--text-muted); text-decoration: underline; }

.pagination { display: flex; align-items: center; gap: 10px; }
.pagination a, .pagination span.disabled {
    padding: 7px 14px; border-radius: 3px; font-size: 13px; font-weight: 600; text-decoration: none;
}
.pagination a { border: 1px solid var(--border-strong); color: var(--navy); background: var(--surface); }
.pagination a:hover { background: var(--navy); color: white; border-color: var(--navy); }
.pagination span.disabled { color: var(--text-faint); border: 1px solid var(--border); }
.pagination .page-count { color: var(--text-muted); font-size: 12.5px; white-space: nowrap; }

/* ---------- Data table ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td {
    padding: 8px 12px; text-align: left; white-space: nowrap;
    max-width: 280px; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--border);
}
table.data th {
    background: var(--navy); color: #FFFFFF; font-size: 11.5px; text-transform: uppercase;
    letter-spacing: 0.04em; font-weight: 600; position: sticky; top: 0; border-bottom: none;
}
table.data tbody tr:nth-child(even) { background: #F4F5F7; }
table.data tbody tr:hover { background: #EAF0F6; }
table.data td.mono { font-size: 12.5px; color: #364055; }

.empty-msg { padding: 40px 20px; color: var(--text-muted); text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; }

/* ---------- Home ---------- */
.home-lead { color: var(--text-muted); margin-bottom: 24px; max-width: 560px; line-height: 1.5; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; max-width: 900px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--stat-accent, var(--navy));
    border-radius: 3px; padding: 16px 18px; text-decoration: none; color: var(--text); display: block;
}
.stat-card:hover { border-color: var(--border-strong); background: #F7F9FB; }
.stat-card .stat-label { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; font-family: "Consolas", "Courier New", monospace; }
.stat-card .stat-value .unit { font-size: 12px; font-weight: 400; color: var(--text-muted); margin-left: 4px; }

/* ---------- Order form ---------- */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 22px 24px; max-width: 760px; }
.form-row { display: flex; gap: 20px; margin-bottom: 16px; flex-wrap: wrap; }
.field-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 200px; }
.field-group label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field-group.checkbox-group { flex-direction: row; align-items: center; gap: 8px; }
.field-group.checkbox-group label { font-weight: 400; color: var(--text); }
select, input[type=date], input[type=number], input[type=text], input[type=email], input[type=tel],
input[type=password], input[type=url], input[type=search] {
    padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 3px;
    font-size: 13.5px; background: var(--bg); font-family: inherit; color: var(--text);
}
select:focus, input:focus { outline: 2px solid var(--navy); outline-offset: -1px; background: var(--surface); }
.section-heading { font-size: 13.5px; font-weight: 700; margin: 22px 0 10px 0; color: var(--text); }
.order-lines { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.order-line { display: flex; gap: 12px; align-items: flex-end; background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 10px 12px; }
.order-line .field-group { margin-bottom: 0; }
.order-line select { min-width: 260px; }
.order-line input[type=number] { width: 110px; }
.remove-line { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-muted); border-radius: 3px; padding: 8px 10px; cursor: pointer; font-size: 12.5px; }
.remove-line:hover { border-color: #C0554A; color: #C0554A; }
.btn-secondary { border: 1px solid var(--navy); background: var(--surface); color: var(--navy); padding: 8px 16px; border-radius: 3px; cursor: pointer; font-size: 13px; font-weight: 600; }
.btn-secondary:hover { background: #F0F2F6; }
.btn-primary { border: 1px solid var(--navy); background: var(--navy); color: white; padding: 10px 22px; border-radius: 3px; cursor: pointer; font-size: 14px; font-weight: 600; }
.btn-primary:hover { background: var(--navy-hover); }
.form-actions { margin-top: 20px; display: flex; gap: 12px; align-items: center; }
.form-error { background: #FBEAEA; border: 1px solid #E3B4AE; color: #8C2F26; padding: 10px 14px; border-radius: 3px; margin-bottom: 16px; font-size: 13px; }
.role-warning { background: #FBEAEA; border: 1px solid #E3B4AE; color: #8C2F26; padding: 8px 10px; border-radius: 3px; font-size: 13px; }
.position-note { display: block; font-size: 11px; color: var(--text-muted); font-weight: 400; margin-top: 2px; }
.btn-primary:disabled, .btn-primary:disabled:hover { background: #C7CBD3; border-color: #C7CBD3; color: #8A93A3; cursor: not-allowed; }
textarea {
    padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 3px; font-size: 13.5px;
    background: var(--bg); font-family: inherit; color: var(--text); resize: vertical; min-height: 64px;
}
textarea:focus { outline: 2px solid var(--navy); outline-offset: -1px; background: var(--surface); }
input:disabled, select:disabled, textarea:disabled { background: #EEF0F3; color: var(--text-faint); cursor: not-allowed; }

/* ---------- Price request form ---------- */
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.radio-option { display: flex; align-items: center; gap: 6px; font-size: 13.5px; }
.radio-option input { width: auto; }
.or-divider { font-size: 12.5px; color: var(--text-faint); font-weight: 600; padding: 0 4px; align-self: center; }
.price-hint { font-size: 12px; color: var(--navy); margin-top: 4px; min-height: 16px; }
.current-price-box {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 3px; background: #F4F5F7;
    font-family: "Consolas", "Courier New", monospace; font-size: 13.5px; color: var(--text);
}
.final-price-preview {
    background: #EAF4EE; border: 1px solid #B9DCC4; border-radius: 4px; padding: 14px 18px;
    margin-bottom: 16px; max-width: 760px;
}
.final-price-preview-label { font-size: 12px; color: #235A38; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.final-price-preview-value { font-size: 24px; font-weight: 700; color: #235A38; font-family: "Consolas", "Courier New", monospace; }
.final-price-preview-basis { font-size: 12px; color: #235A38; margin-top: 6px; opacity: 0.8; }

/* ---------- Credential reveal card (шинэ нэвтрэх нэр/нууц үг нэг л удаа харуулах) ---------- */
.credential-card {
    background: var(--surface); border: 2px solid #1F9D63; border-radius: 8px;
    padding: 24px 28px; max-width: 480px; box-shadow: var(--shadow-card);
}
.credential-card-header { font-size: 16px; font-weight: 700; color: #1F9D63; margin-bottom: 18px; }
.credential-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.credential-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; min-width: 110px; }
.credential-value { font-size: 16px; font-weight: 700; font-family: "Consolas", "Courier New", monospace; color: var(--text); }
.credential-warning {
    background: #FDEAEC; border: 1px solid #F3B4BB; color: #A32338; border-radius: 4px;
    padding: 12px 14px; font-size: 12.5px; font-weight: 600; margin: 16px 0; line-height: 1.5;
}
.order-total-box {
    display: flex; align-items: center; justify-content: space-between; max-width: 760px;
    background: var(--navy); color: #FFFFFF; border-radius: 4px; padding: 14px 20px; margin: 16px 0;
}
.order-total-label { font-size: 13px; font-weight: 700; letter-spacing: 0.04em; }
.order-total-value { font-size: 22px; font-weight: 700; font-family: "Consolas", "Courier New", monospace; }
table.data tfoot .totals-row td { background: #EEF0F3; font-weight: 700; border-top: 2px solid var(--border-strong); }

/* ---------- Order success / detail ---------- */
.success-banner {
    background: #EAF4EE; border: 1px solid #B9DCC4; color: #235A38; padding: 14px 18px;
    border-radius: 4px; margin-bottom: 20px; font-size: 14px; font-weight: 600;
}
.detail-card { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 20px 24px; max-width: 760px; margin-bottom: 20px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.detail-item .detail-label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
.detail-item .detail-value { font-size: 14px; font-weight: 600; }
/* .status-badge үндсэн бүтэц доор, шинэ навигейшн CSS блокт нэг л удаа тодорхойлогдоно.
   Энэ хуучин код доторх модификатор (.NEW, .PENDING_CEO гэх мэт) л энд хэвээр —
   Захиалга/Үнийн хүсэлтийн бусад хуудсанд (order_detail, price detail) хэвээрээ ашиглагдана. */
.status-badge.NEW { background: #9CA3AF; color: #FFFFFF; }
.status-badge.PARTIALLY_DELIVERED { background: #E8A33D; color: #FFFFFF; }
.status-badge.DELIVERED { background: #4A7C59; color: #FFFFFF; }
.status-badge.CLOSED { background: #1F3D2B; color: #FFFFFF; }
.status-badge.PENDING_CEO { background: #D9A62B; color: #FFFFFF; }
.status-badge.APPROVED_CEO { background: #3A5A8C; color: #FFFFFF; }
.status-badge.REJECTED_CEO { background: #B23A3A; color: #FFFFFF; }
.status-badge.APPLIED { background: #4A7C59; color: #FFFFFF; }
.clickable-row { cursor: pointer; }
.orders-table-wrap .clickable-row:hover { background: #EAF0F6; }
.row-warning { background: var(--status-warning-bg); }
.row-warning:hover { background: var(--status-warning-bg); filter: brightness(0.97); }
.diff-red { color: var(--status-critical-text); font-weight: 600; }
.diff-green { color: var(--status-success-text); font-weight: 600; }
.diff-gray { color: var(--text-muted); }
.loan-pay-inputs { display: flex; gap: 6px; align-items: center; }
.loan-pay-inputs input[type="date"], .loan-pay-inputs input[type="number"] { width: 120px; padding: 4px 6px; }
.loan-save-btn { padding: 4px 10px; font-size: 12.5px; }

/* ---------- Typeahead ---------- */
.typeahead-wrapper { position: relative; }
.typeahead-results {
    display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
    background: var(--surface); border: 1px solid var(--border-strong); border-top: none;
    max-height: 220px; overflow-y: auto; border-radius: 0 0 3px 3px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.typeahead-results.open { display: block; }
.typeahead-item { padding: 8px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); }
.typeahead-item:last-child { border-bottom: none; }
.typeahead-item:hover { background: #EAF0F6; }
.typeahead-item .item-code { font-family: "Consolas", "Courier New", monospace; color: var(--text-muted); font-size: 12px; margin-left: 6px; }
.typeahead-item .item-type { color: var(--text-muted); font-size: 12px; }
.field-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

/* ---------- Order view tabs ---------- */
.order-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 4px 0 20px 0; }
.order-tabs a {
    padding: 9px 16px; font-size: 13.5px; font-weight: 600; text-decoration: none; color: var(--text-muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.order-tabs a:hover { color: var(--navy); }
.order-tabs a.active { color: var(--navy); border-bottom-color: var(--navy); }
@media (max-width: 640px) {
    .order-tabs { overflow-x: auto; scrollbar-width: none; gap: 0; }
    .order-tabs a { white-space: nowrap; flex-shrink: 0; padding: 9px 12px; }
}

/* ---------- Pivot metric sub-tabs ---------- */
.metric-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.metric-tabs a {
    padding: 6px 14px; border-radius: 14px; font-size: 12.5px; font-weight: 600; text-decoration: none;
    background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-muted);
}
.metric-tabs a:hover { border-color: var(--navy); color: var(--navy); }
.metric-tabs a.active { background: var(--navy); border-color: var(--navy); color: #FFFFFF; }

/* ---------- Filter bar ---------- */
.filter-bar {
    display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
    padding: 14px; margin-bottom: 16px;
}
.filter-bar .field-group { min-width: 200px; flex: 0 1 220px; }
.filter-bar .field-group.typeahead-wrapper { flex: 0 1 260px; }

/* ---------- Page header row (title + action button) ---------- */
.page-header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.page-header-row .page-title { margin: 0; }

/* ---------- Column filter row ---------- */
tr.column-filter-row td { background: #F4F5F7; padding: 6px 10px; border-bottom: 2px solid var(--border-strong); }
tr.column-filter-row input {
    width: 100%; padding: 5px 8px; font-size: 12.5px; border: 1px solid var(--border-strong); border-radius: 3px;
    background: var(--surface);
}

/* ---------- Pivot table ---------- */
.pivot-table-wrap { overflow: auto; max-width: 100%; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); max-height: 70vh; }
table.pivot { border-collapse: collapse; font-size: 12.5px; }
table.pivot th, table.pivot td {
    padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}
table.pivot th { background: var(--navy); color: #FFFFFF; font-size: 11px; font-weight: 600; position: sticky; top: 0; z-index: 5; }
table.pivot th.sku-col-header, table.pivot td.sku-col {
    position: sticky; left: 0; z-index: 6; background: var(--navy); color: #FFFFFF; text-align: left; font-weight: 600;
}
table.pivot td.sku-col { background: #F4F5F7; color: var(--text); z-index: 4; }
table.pivot tbody tr:nth-child(even) td:not(.sku-col) { background: #F9FAFB; }
table.pivot td.zero-cell { color: var(--text-faint); }
.pivot-note { font-size: 12.5px; color: var(--text-muted); margin-top: 10px; }

/* ---------- Landing navbar (харанхуй, мэргэжлийн албан ёсны хэдар) ---------- */
.landing-navbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 20px;
    padding: 14px 40px;
    background: rgba(6, 16, 50, 0.72);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border-bottom: 1px solid rgba(255,255,255,0.10);
}
.landing-navbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 0.03em; color: #FFFFFF; font-size: 1rem; white-space: nowrap; }
.landing-logo-mark { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.landing-navbar-links { display: flex; gap: 28px; flex-wrap: wrap; }
.landing-navbar-links a { color: rgba(255,255,255,0.75); text-decoration: none; font-size: 0.88rem; font-weight: 600; }
.landing-navbar-links a:hover { color: #FFFFFF; }
.landing-navbar-cta { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.landing-navbar-cta span { font-size: 0.85rem; color: rgba(255,255,255,0.75); font-weight: 600; }
.navbar-pill {
    background: #FFFFFF; color: #082287; padding: 9px 20px; border-radius: var(--radius-pill);
    text-decoration: none; font-size: 0.85rem; font-weight: 700;
    transition: background 150ms ease;
}
.navbar-pill:hover { background: #E7E9F2; }

/* ---------- Homepage hero (цагаан, мэргэжлийн албан ёсны загвар) ---------- */
.hero-section {
    background: var(--bg-app);
    color: var(--text-primary);
    padding: 132px 48px 72px 48px; min-height: 100vh;
    position: relative;
}
.hero-section h1 {
    font-family: var(--font-primary);
    color: var(--navy-800);
    font-size: 3.4rem; font-weight: 800; line-height: 1.15; margin: 0 0 20px 0; letter-spacing: -0.01em;
    text-align: center;
}
.hero-section p.subtitle {
    font-size: 1.1rem; color: var(--text-secondary); max-width: 620px;
    margin: 0 auto 36px auto; text-align: center; line-height: 1.6;
}
.hero-cta-row {
    display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
    margin-bottom: 56px;
}
.hero-btn-primary {
    background: var(--navy-800); color: #FFFFFF; padding: 14px 30px; border-radius: var(--radius-sm);
    text-decoration: none; font-weight: 700; font-size: 0.95rem;
    box-shadow: var(--shadow-card);
    transition: background 150ms ease;
}
.hero-btn-primary:hover { background: var(--navy-700); }
.hero-btn-secondary {
    background: transparent; color: var(--navy-800); border: 1.5px solid var(--border-strong);
    padding: 13px 30px; border-radius: var(--radius-sm); text-decoration: none; font-weight: 700; font-size: 0.95rem;
    transition: border-color 150ms ease, background 150ms ease;
}
.hero-btn-secondary:hover { border-color: var(--navy-800); background: var(--navy-hover-overlay); }

.today-tasks { max-width: 1180px; margin: 0 auto 36px auto; }
.today-tasks h2 { font-size: 18px; margin: 0 0 12px 0; color: var(--navy-800); }
.task-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.task-card { display: flex; gap: 12px; align-items: flex-start; background: var(--bg-card); border: 1px solid var(--border-subtle);
             border-left: 4px solid var(--navy-800); border-radius: var(--radius-md); padding: 14px 16px; text-decoration: none;
             color: var(--text-primary); box-shadow: var(--shadow-card); min-height: 64px; }
.task-card.urgent { border-left-color: #C8553D; }
.task-card .task-icon { font-size: 22px; line-height: 1; }
.task-card .task-title { display: block; font-weight: 700; font-size: 15px; }
.task-card .task-detail { display: block; font-size: 13px; color: var(--text-secondary); margin-top: 3px; }
.bell-light { color: #FFFFFF; }
.dept-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 22px; max-width: 1180px; margin: 0 auto;
}
.hero-glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 24px; color: var(--text-primary); text-decoration: none;
    box-shadow: var(--shadow-card);
    position: relative;
    transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
    display: flex; flex-direction: column; gap: 10px; cursor: pointer;
}
.hero-glass-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-card-hover); border-color: var(--border-strong); }
.hero-glass-card .card-icon { width: 38px; height: 38px; color: var(--navy-800); margin-bottom: 4px; }
.hero-glass-card .card-icon svg { width: 100%; height: 100%; }
.hero-glass-card .dept-title { font-size: 17px; font-weight: 700; }
.hero-glass-card .dept-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.45; }
.hero-glass-card.coming-soon { opacity: 0.55; cursor: default; }
.hero-glass-card.coming-soon:hover { transform: none; box-shadow: 0 4px 14px rgba(0,0,0,0.25); border-color: rgba(255,255,255,0.14); }
.hero-glass-card.coming-soon .card-icon { color: var(--text-tertiary); }

@media (max-width: 720px) {
    .landing-navbar { padding: 12px 16px; }
    .landing-navbar-links { display: none; }
    .landing-navbar-brand span { display: none; }
    .landing-navbar-cta span { display: none; }
    .hero-section h1 { font-size: 2.2rem; }
}

/* ---------- Department sub-page (сидбар shell дотор, .main-ийн агуулга) ---------- */
.dept-back-link {
    display: inline-block; margin: 0 0 20px 0; font-size: 13.5px; color: var(--navy-800);
    text-decoration: none; font-weight: 600;
}
.dept-back-link:hover { text-decoration: underline; }
.dept-page-header { margin: 0 0 28px 0; display: flex; align-items: flex-start; gap: 16px; }
.dept-page-header .dept-icon { width: 52px; height: 52px; border-radius: 10px; background: var(--bg-app); border: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dept-page-header .dept-icon svg { width: 26px; height: 26px; stroke: var(--navy-800); }
.dept-page-header h1 { font-size: 22px; color: var(--navy-800); margin: 0 0 4px 0; }
.dept-page-header p { color: var(--text-secondary); font-size: 13.5px; margin: 0; }

.func-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
}
.func-card {
    background: var(--bg-card); border-radius: var(--radius-md); padding: 20px; text-decoration: none;
    color: var(--text-primary); box-shadow: var(--shadow-card); border: 1px solid var(--border-subtle);
    transition: transform 200ms ease, box-shadow 200ms ease, border-color 200ms ease;
    display: flex; align-items: center; gap: 14px;
}
.func-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-card-hover); border-color: var(--navy-600); }
.func-card .func-icon { font-size: 26px; flex-shrink: 0; }
.func-card .func-title { font-size: 14.5px; font-weight: 600; }
.func-card.placeholder { background: var(--bg-app); color: var(--text-secondary); border: 1px dashed var(--border-subtle); cursor: default; opacity: 0.75; }
.func-card.placeholder:hover { transform: none; box-shadow: var(--shadow-card); border-color: var(--border-subtle); }
.external-tag { font-size: 10.5px; color: var(--text-secondary); font-weight: 500; margin-left: 6px; }
.badge-soon {
    display: inline-block; background: var(--text-secondary); color: #FFFFFF; font-size: 10.5px; font-weight: 700;
    padding: 2px 9px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.03em; margin-left: 8px;
    vertical-align: middle;
}

/* ---------- Status badge (Orders STATUS баганад ашиглана) ---------- */
.status-badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px;
    border-radius: var(--radius-pill); font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.status-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status-badge.status-success { background: var(--status-success-bg); color: var(--status-success-text); }
.status-badge.status-processing { background: var(--status-processing-bg); color: var(--status-processing-text); }
.status-badge.status-pending { background: var(--status-pending-bg); color: var(--status-pending-text); }
.status-badge.status-warning { background: var(--status-warning-bg); color: var(--status-warning-text); }
.status-badge.status-critical { background: var(--status-critical-bg); color: var(--status-critical-text); }

/* ---------- Attention pulse (KPI/alert-д зориулсан бэлтгэл, одоохондоо ашиглагдахгүй) ---------- */
@keyframes subtle-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(178, 58, 72, 0.25); }
    50% { box-shadow: 0 0 0 6px rgba(178, 58, 72, 0); }
}
.attention-badge { animation: subtle-pulse 2.5s ease-in-out infinite; }

/* ---------- KPI / Chart (хэлтсийн dashboard-д ашиглана) ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 8px; }
.kpi-card { background: var(--bg-card); border-radius: var(--radius-md); padding: 20px 24px; box-shadow: var(--shadow-card); border-left: 3px solid var(--navy-800); }
.kpi-card .kpi-label { font-size: 0.85rem; color: var(--text-secondary); }
.kpi-card .kpi-value { font-size: 2rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.kpi-card .kpi-trend-up { color: var(--status-success-text); }
.kpi-card .kpi-trend-down { color: var(--status-critical-text); }
.kpi-card .kpi-sparkline { height: 32px; margin-top: 8px; }
.chart-container { background: var(--bg-card); border-radius: var(--radius-md); padding: 24px; box-shadow: var(--shadow-card); }

@media (max-width: 720px) {
    .hero-section { padding: 96px 20px 32px 20px; min-height: auto; }
    .dept-grid, .func-grid { grid-template-columns: 1fr; }
}

/* =====================================================================
   Утас эхэнд (2026-10-05): base.html-ийн hamburger цэс, карт хүснэгт,
   нэг баганат маягт. Таслах цэгүүд: ≤900px (sidebar → гулсдаг цэс),
   ≤640px (хүснэгт → карт). Хүрэх талбай ≥44px.
   ===================================================================== */
.menu-toggle, .topbar-brand, .sidebar-backdrop { display: none; }
.menu-toggle {
    width: 44px; height: 44px; align-items: center; justify-content: center; flex: none;
    background: transparent; border: 0; color: var(--text-on-navy); cursor: pointer; border-radius: var(--radius-sm);
}
.menu-toggle svg { width: 24px; height: 24px; }
.topbar-brand { color: var(--text-on-navy); text-decoration: none; font-weight: 700; font-size: 15px; margin-right: auto; }
.snapshot-note { margin-top: -16px; }

/* Мастер хүснэгт, CF матриц, pivot: карт биш — эхний багана наалттай хэвтээ гүйлгэлт */
table.no-cards td:first-child, table.no-cards th:first-child { position: sticky; left: 0; z-index: 1; }
table.no-cards td:first-child { background: inherit; background-color: var(--surface); }
table.no-cards tbody tr:nth-child(even) td:first-child { background-color: #F4F5F7; }
table.no-cards th:first-child { z-index: 2; }

@media (max-width: 900px) {
    .sidebar, .app-sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; height: 100vh; height: 100dvh; z-index: 1000;
        width: 84vw; max-width: 300px; transform: translateX(-100%); transition: transform 200ms ease;
        padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
    }
    body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-navy-glow); }
    body.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 11, 36, 0.45); z-index: 999; }
    body.nav-open { overflow: hidden; }
    .sidebar-nav a, .nav-section-label { min-height: 44px; }

    .main, .app-main { padding: 0 16px 32px 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
    .app-topbar {
        position: sticky; top: 0; z-index: 50; margin: 0 -16px 16px -16px; padding: 6px 12px;
        padding-top: max(6px, env(safe-area-inset-top)); justify-content: space-between; gap: 8px;
    }
    .menu-toggle { display: inline-flex; }
    .topbar-brand { display: block; }
    .app-topbar .user-name { display: none; }
    .app-topbar a.logout-link, .app-topbar a.login-link { padding: 10px 4px; }
}

@media (max-width: 640px) {
    body { font-size: 15px; }
    .page-title { font-size: 18px; }
    .page-header-row { flex-wrap: wrap; }
    /* iOS 16px-ээс жижиг input дээр автоматаар томруулдаг — 16px */
    input, select, textarea, button { font-size: 16px !important; }
    select, input[type=date], input[type=number], input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], textarea { width: 100%; min-height: 44px; }
    .btn-primary, .btn-secondary, form.search button { min-height: 44px; }
    .form-card { padding: 16px; }
    .form-row { flex-direction: column; gap: 12px; }
    .field-group { min-width: 0; }
    .form-actions { flex-direction: column-reverse; align-items: stretch; }
    .form-actions .btn-primary, .form-actions .btn-secondary, .form-actions a { width: 100%; text-align: center; }
    .order-line { flex-wrap: wrap; }
    .order-line .sku-typeahead { flex: 1 1 100%; }
    .order-line .field-group { min-width: 0; }
    .order-line .remove-line { min-height: 44px; }
    .order-line select { min-width: 0; }
    .order-line input[type=number] { width: 100%; }
    .toolbar { padding: 10px; }
    form.search { width: 100%; }
    form.search input[type=text] { width: auto; flex: 1; min-width: 0; }
    .filter-bar .field-group, .filter-bar .field-group.typeahead-wrapper { flex: 1 1 100%; }
    tr.column-filter-row { display: none; }
    .stat-grid, .kpi-grid, .func-grid { grid-template-columns: 1fr; }

    /* ---- Хүснэгт → карт (no-cards, pivot, cf-week-table-аас бусад) ---- */
    .table-wrap:has(table.data:not(.no-cards):not(.cf-week-table)) { border: 0; background: transparent; overflow: visible; }
    table.data:not(.no-cards):not(.cf-week-table) thead { display: none; }
    table.data:not(.no-cards):not(.cf-week-table),
    table.data:not(.no-cards):not(.cf-week-table) tbody,
    table.data:not(.no-cards):not(.cf-week-table) tfoot,
    table.data:not(.no-cards):not(.cf-week-table) tr { display: block; width: 100%; }
    table.data:not(.no-cards):not(.cf-week-table) tr {
        background: var(--surface) !important; border: 1px solid var(--border); border-radius: var(--radius-md);
        margin-bottom: 10px; padding: 4px 14px; box-shadow: var(--shadow-card);
    }
    table.data:not(.no-cards):not(.cf-week-table) td {
        display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
        white-space: normal; max-width: none; overflow: visible; text-align: right;
        padding: 6px 0; border-bottom: 1px dashed var(--border); min-height: 32px; font-size: 14px;
    }
    table.data:not(.no-cards):not(.cf-week-table) td:last-child { border-bottom: 0; }
    table.data:not(.no-cards):not(.cf-week-table) td::before {
        content: attr(data-label); flex: 0 0 40%; text-align: left; font-weight: 600; color: var(--text-muted);
        font-size: 12.5px; font-family: var(--font-primary); text-transform: none; letter-spacing: 0;
    }
    table.data:not(.no-cards):not(.cf-week-table) td:not([data-label])::before,
    table.data:not(.no-cards):not(.cf-week-table) td[colspan]::before { content: none; }
    table.data:not(.no-cards):not(.cf-week-table) td[colspan] { display: block; text-align: center; }
    table.data:not(.no-cards):not(.cf-week-table) td > * { max-width: 60%; }
    /* Нүдэн доторх маягт (оролт + товч) карт дотроо багтаж, доошоо орно */
    table.data:not(.no-cards):not(.cf-week-table) td > form {
        flex: 1 1 60%; min-width: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end;
    }
    table.data:not(.no-cards):not(.cf-week-table) td > form input[type=text],
    table.data:not(.no-cards):not(.cf-week-table) td > form input[type=email] { flex: 1 1 100%; width: 100%; }
    table.data:not(.no-cards):not(.cf-week-table) td > form > * { max-width: 100%; }

    .pivot-table-wrap { max-height: none; }
    table.pivot th.sku-col-header, table.pivot td.sku-col { position: sticky; left: 0; z-index: 1; }
}

/* ---------- Камерын баркод уншигч (static/js/barcode.js) ---------- */
.scan-overlay { position: fixed; inset: 0; background: #000; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.scan-overlay video { width: 100%; height: 100%; object-fit: cover; }
.scan-overlay .scan-frame { position: absolute; width: min(78vw, 360px); height: min(40vw, 180px); border: 3px solid #fff;
    border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45); }
.scan-overlay .scan-hint { position: absolute; top: calc(50% + min(20vw, 90px) + 18px); color: #fff; font-size: 15px; text-align: center; padding: 0 16px; }
.scan-overlay .scan-close { position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%); min-height: 48px; padding: 0 28px;
    border-radius: 24px; border: 0; background: #fff; color: #111; font-size: 16px; font-weight: 600; }
.scan-btn { min-width: 44px; min-height: 44px; border-radius: 10px; border: 1px solid #D5D9E0; background: #fff; font-size: 18px; cursor: pointer; }
.scan-row { display: flex; gap: 8px; align-items: flex-start; }
.scan-row .typeahead-wrapper { flex: 1; min-width: 0; }
