:root {
    font-family: 'Segoe UI', Arial, sans-serif;
    color: #20283a;
    background: #f5f7fb;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    --navy: #17243d;
    --muted: #8490a5;
    --line: #e8ecf3;
    --primary: #315ce8;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 2; display: flex; flex-direction: column; width: 250px; padding: 27px 16px 18px; color: #d9e1f1; background: var(--navy); }
.brand, .auth-brand { display: flex; align-items: center; gap: 11px; color: #fff; font: 800 16px 'Segoe UI', Arial, sans-serif; letter-spacing: .04em; }
.brand small, .auth-brand small { display: block; margin-top: 3px; color: #93a2bc; font: 600 9px 'Segoe UI', Arial, sans-serif; letter-spacing: .13em; }
.brand-mark { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 11px; color: white; background: linear-gradient(145deg, #6286ff, #3458dc); font: 800 19px 'Segoe UI', Arial, sans-serif; }
.sidebar nav { display: grid; gap: 5px; margin-top: 41px; }
.sidebar nav a, .nav-disabled { display: block; padding: 11px 13px; border-radius: 8px; color: #b5c0d2; font-size: 13px; }
.sidebar nav a:hover, .sidebar nav a.active { color: #fff; background: #263754; }
.sidebar nav a.active { box-shadow: inset 3px 0 #6a8cff; }
.nav-label { margin: 18px 0 4px 13px; color: #71809a; font-size: 9px; font-weight: 700; letter-spacing: .14em; }
.nav-disabled { color: #8492a9; }
.nav-disabled small { display: block; margin-top: 4px; color: #64728a; font-size: 10px; }
.sidebar-user { display: flex; align-items: center; gap: 9px; margin-top: auto; padding: 13px 5px 0; border-top: 1px solid #33415b; color: #fff; font-size: 11px; }
.sidebar-user small { display: block; margin-top: 3px; color: #94a2b7; font-size: 10px; text-transform: capitalize; }
.avatar { display: grid; width: 31px; height: 31px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: #dbe5ff; background: #3b4e71; font-weight: 700; }
.sidebar-user form { margin-left: auto; }
.icon-button { border: 0; color: #aebbd0; background: transparent; cursor: pointer; font-size: 18px; }
.main-content { width: calc(100% - 250px); min-height: 100vh; margin-left: 250px; padding: 42px clamp(24px, 4vw, 60px); }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-heading h1 { margin: 5px 0 7px; color: #1d2940; font: 800 clamp(25px, 3vw, 32px) 'Segoe UI', Arial, sans-serif; letter-spacing: -.04em; }
.eyebrow { margin: 0; color: #7d8ba2; font-size: 10px; font-weight: 700; letter-spacing: .13em; }
.muted, .page-heading .muted { margin: 0; color: var(--muted); font-size: 13px; }
.date-pill, .result-count { padding: 9px 13px; border: 1px solid var(--line); border-radius: 8px; color: #6c7890; background: #fff; font-size: 11px; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric-card, .panel { border: 1px solid #e9edf4; border-radius: 12px; background: #fff; box-shadow: 0 3px 14px rgb(21 40 72 / 3%); }
.metric-card { min-height: 150px; padding: 18px 19px; }
.metric-top { display: flex; align-items: center; gap: 10px; }
.metric-icon { display: grid; width: 31px; height: 31px; place-items: center; border-radius: 9px; font-size: 12px; font-weight: 700; }
.icon-blue { color: #345ce0; background: #edf1ff; }
.icon-violet { color: #8252dc; background: #f3edff; }
.icon-teal { color: #168c84; background: #e5f7f4; }
.icon-amber { color: #b9851e; background: #fff6df; }
.metric-label { color: #66738a; font-size: 11px; }
.metric-card strong { display: block; margin: 13px 0 4px; color: #26334b; font: 800 28px 'Segoe UI', Arial, sans-serif; }
.metric-caption { color: #a0a9b8; font-size: 10px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: 18px; }
.panel { min-width: 0; padding: 21px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0 0 5px; color: #29364d; font: 700 15px 'Segoe UI', Arial, sans-serif; }
.panel-heading p { margin: 0; color: #98a1b1; font-size: 10px; }
.quick-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.quick-links a { position: relative; display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 0 10px; padding: 12px; border: 1px solid #edf0f5; border-radius: 9px; }
.quick-links a:hover { border-color: #cbd6ff; background: #fafbff; }
.quick-links a > span { display: grid; grid-row: span 2; width: 32px; height: 32px; place-items: center; border-radius: 9px; color: #4566db; background: #eef2ff; font-size: 12px; font-weight: 700; }
.quick-links strong { color: #39465d; font-size: 11px; }
.quick-links small { margin-top: 3px; color: #9ca5b4; font-size: 9px; }
.quick-links b { position: absolute; top: 17px; right: 12px; color: #99a4b6; font-size: 16px; font-weight: 400; }
.readiness { display: grid; gap: 15px; margin: 8px 0 17px; }
.readiness > div { display: flex; align-items: flex-start; gap: 10px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; margin-top: 4px; border-radius: 50%; background: #29b887; box-shadow: 0 0 0 4px #e8f8f1; }
.status-pending { background: #eda83b; box-shadow: 0 0 0 4px #fff5e3; }
.readiness strong, .readiness small { display: block; }
.readiness strong { color: #4a566c; font-size: 11px; font-weight: 600; }
.readiness small { margin-top: 3px; color: #9aa4b3; font-size: 10px; }
.note-box { padding: 11px 12px; border-radius: 7px; color: #7b6b43; background: #fff8e8; font-size: 10px; line-height: 1.6; }
.catalog-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .75fr); align-items: start; gap: 18px; }
.catalog-panel { padding: 19px 0 0; }
.catalog-panel > .panel-heading { padding: 0 19px; }
.search-form { display: flex; gap: 7px; }
.search-form input { width: 150px; }
.table-scroll { overflow-x: auto; border-top: 1px solid #edf0f5; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; text-align: left; }
th { padding: 11px 13px; color: #8390a4; background: #fafbfc; font-size: 9px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
td { padding: 12px 13px; border-top: 1px solid #f0f2f6; color: #566279; font-size: 11px; }
tr:hover td { background: #fcfdff; }
.table-link { color: #3b60d8; font-size: 10px; font-weight: 600; }
.empty-state { padding: 28px; color: #98a1b1; text-align: center; }
.form-panel { padding: 20px; }
.form-stack { display: grid; gap: 13px; }
.form-stack label { display: grid; gap: 6px; color: #59667b; font-size: 10px; font-weight: 600; }
.form-stack input, .form-stack select, .operation-form input, .operation-form select, .search-form input { width: 100%; min-width: 0; padding: 10px 11px; border: 1px solid #e4e9f1; border-radius: 7px; outline: none; color: #334057; background: white; font-size: 11px; }
.form-stack input:focus, .form-stack select:focus, .operation-form input:focus, .operation-form select:focus, .search-form input:focus { border-color: #839bff; box-shadow: 0 0 0 3px #edf0ff; }
.form-stack input[readonly] { color: #7c8798; background: #f6f8fb; }
.button { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; padding: 0 13px; border: 1px solid transparent; border-radius: 7px; cursor: pointer; font-size: 10px; font-weight: 700; }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { background: #274ac7; }
.button-secondary { border-color: #e5e9f0; color: #68758b; background: #fff; }
.button-secondary:hover { background: #f8f9fc; }
.button-center { text-align: center; }
.flash { position: fixed; z-index: 5; top: 18px; right: 22px; max-width: min(440px, calc(100vw - 40px)); padding: 12px 16px; border: 1px solid #cceee1; border-radius: 9px; color: #227b5c; background: #effaf5; box-shadow: 0 8px 25px rgb(20 40 80 / 10%); font-size: 12px; transition: opacity .3s ease, transform .3s ease; }
.flash-error { position: static; max-width: none; margin-bottom: 16px; border-color: #f3d0d0; color: #a54343; background: #fff4f4; box-shadow: none; }
.flash-dismissed { opacity: 0; transform: translateY(-8px); pointer-events: none; }
.auth-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(ellipse at top left, #e8edff 0, transparent 45%), #f5f7fb; }
.auth-card { width: min(100%, 420px); padding: 34px; border: 1px solid #e8ecf3; border-radius: 15px; background: #fff; box-shadow: 0 15px 50px rgb(30 48 83 / 8%); }
.auth-brand { margin-bottom: 30px; color: #25334c; }
.auth-brand small { color: #8390a4; }
.auth-card h1 { margin: 6px 0 8px; color: #1f2b41; font: 800 25px 'Segoe UI', Arial, sans-serif; letter-spacing: -.04em; }
.auth-card .muted { margin-bottom: 22px; line-height: 1.6; }
.auth-card .form-stack { gap: 15px; }
.auth-card .button { margin-top: 4px; min-height: 42px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.operation-panel { margin-bottom: 18px; }
.operation-form { display: grid; gap: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.form-grid label, .operation-row label { display: grid; gap: 6px; color: #59667b; font-size: 10px; font-weight: 600; }
.line-section { display: grid; gap: 11px; }
.line-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.line-heading h3 { margin: 0 0 4px; color: #344159; font-size: 12px; }
.line-heading p { margin: 0; color: #99a3b2; font-size: 10px; }
.dynamic-lines { display: grid; gap: 9px; }
.operation-row { display: grid; grid-template-columns: minmax(180px, 1.5fr) minmax(100px, .6fr) minmax(140px, .9fr) 32px; align-items: end; gap: 10px; padding: 11px; border: 1px solid #edf0f5; border-radius: 9px; }
.purchase-line { grid-template-columns: minmax(180px, 1.35fr) minmax(90px, .5fr) minmax(130px, .75fr) minmax(110px, .6fr) 32px; }
.operation-row input, .operation-row select { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid #e4e9f1; border-radius: 7px; outline: none; color: #334057; background: #fff; font-size: 11px; }
.due-date-row { grid-template-columns: minmax(180px, 1fr) 32px; max-width: 380px; }
.stock-hint { align-self: center; color: #8490a5; font-size: 10px; }
.remove-line { display: grid; width: 31px; height: 35px; place-items: center; border: 1px solid #f0e0e0; border-radius: 7px; color: #a75f5f; background: #fff8f8; cursor: pointer; font-size: 19px; }
.operation-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-top: 15px; border-top: 1px solid #edf0f5; }
.operation-footer p { margin: 0; color: #8b96a8; font-size: 10px; }
.amount-preview { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 24px; padding: 12px 15px; border-radius: 8px; color: #7d889b; background: #f7f8fc; font-size: 11px; }
.amount-preview strong { margin-left: 8px; color: #2d3d5a; font-size: 14px; }
.history-panel { padding-bottom: 0; }
.inventory-note { margin: -10px 0 16px; }
.negative-stock { color: #b14444 !important; font-weight: 700; }
.inline-form { display: inline; }

@media (max-width: 1000px) {
    .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid, .catalog-layout { grid-template-columns: 1fr; }
    .form-panel { order: -1; }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
    .sidebar { position: static; width: 100%; height: auto; padding: 15px; }
    .app-shell { display: block; }
    .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; margin-top: 18px; }
    .sidebar nav a { padding: 9px; font-size: 11px; }
    .nav-label { grid-column: 1 / -1; margin-top: 10px; }
    .nav-disabled { display: none; }
    .sidebar-user { margin-top: 14px; }
    .main-content { width: 100%; margin: 0; padding: 26px 16px; }
    .page-heading { align-items: flex-start; }
    .result-count { display: none; }
    .metrics-grid { gap: 10px; }
    .metric-card { min-height: 130px; padding: 14px; }
    .metric-card strong { font-size: 24px; }
    .quick-links { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .panel { padding: 16px; }
    .catalog-panel { padding: 15px 0 0; }
    .catalog-panel > .panel-heading { align-items: flex-start; padding: 0 14px 14px; }
    .search-form { flex-wrap: wrap; }
    .search-form input { width: 100%; }
    .operation-row, .purchase-line { grid-template-columns: 1fr 1fr; }
    .operation-row > label:first-child { grid-column: 1 / -1; }
    .stock-hint { grid-column: 1; }
    .operation-footer { align-items: flex-start; flex-direction: column; }
}
