:root {
  --ink: #172235;
  --muted: #64748b;
  --line: #e2e8f0;
  --surface: #ffffff;
  --canvas: #f5f7fb;
  --nav: #101b2e;
  --nav-soft: #1b2940;
  --primary: #315bea;
  --primary-soft: #e9efff;
  --green: #15805f;
  --green-soft: #e5f7f0;
  --amber: #a96608;
  --amber-soft: #fff4d6;
  --red: #bd2c2c;
  --red-soft: #ffebeb;
  --violet: #7652d6;
  --shadow: 0 8px 28px rgba(23, 34, 53, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 245px; position: fixed; inset: 0 auto 0 0; background: var(--nav); color: #fff; padding: 22px 14px; display: flex; flex-direction: column; overflow-y: auto; z-index: 20; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px 25px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--primary); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand small { color: #91a0b7; margin-top: 2px; }
nav { display: grid; gap: 5px; }
.nav-item, .side-action { border: 0; color: #aeb9ca; background: transparent; border-radius: 9px; padding: 11px 12px; text-align: left; }
.nav-item { display: flex; gap: 12px; align-items: center; font-weight: 650; width: 100%; }
.nav-item span { width: 18px; text-align: center; font-size: 17px; }
.nav-item:hover, .nav-item.active { color: #fff; background: var(--nav-soft); }
.sidebar-footer { margin-top: 18px; padding-top: 18px; border-top: 1px solid #273650; display: grid; gap: 3px; }
.side-action:hover { color: #fff; background: var(--nav-soft); }
.file-label input { display: none; }
.danger-text { color: #f6a5a5; }

.main-area { margin-left: 245px; width: calc(100% - 245px); min-width: 0; min-height: 100vh; }
.topbar { min-height: 84px; padding: 17px 28px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 15px; position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 21px; margin: 0; }
.topbar p { color: var(--muted); margin: 3px 0 0; font-size: 13px; }
.user-chip { margin-left: auto; display: flex; align-items: center; gap: 9px; }
.user-chip > span { display: grid; place-items: center; width: 35px; height: 35px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 800; font-size: 12px; }
.user-chip strong, .user-chip small { display: block; }
.user-chip small { color: var(--muted); font-size: 11px; }
.menu-toggle { display: none; border: 0; background: transparent; font-size: 22px; }
.content { padding: 26px 28px 50px; max-width: 1500px; min-width: 0; margin: 0 auto; }

.page-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-actions p { margin: 0; color: var(--muted); }
.action-group, .filters { display: flex; gap: 9px; flex-wrap: wrap; }
.button { border: 1px solid transparent; border-radius: 8px; padding: 9px 14px; font-weight: 700; color: var(--ink); background: var(--surface); }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: #244bd2; }
.button.secondary { border-color: var(--line); }
.button.secondary:hover { background: #f8fafc; }
.button.danger { color: var(--red); border-color: #facaca; background: var(--red-soft); }
.button.small { font-size: 12px; padding: 6px 9px; }
.button:disabled { opacity: .5; cursor: not-allowed; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 20px; }
.kpi-card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 2px 10px rgba(23,34,53,.025); }
.kpi-card { padding: 18px; }
.kpi-card .label { color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi-card .value { font-size: 27px; font-weight: 800; margin: 8px 0 4px; letter-spacing: -.6px; }
.kpi-card .context { font-size: 12px; color: var(--muted); }
.kpi-card .context.good { color: var(--green); }
.kpi-card .context.warn { color: var(--amber); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr); gap: 18px; }
.dashboard-grid > * { min-width: 0; }
.panel { overflow: hidden; margin-bottom: 18px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); gap: 12px; }
.panel-header h2 { margin: 0; font-size: 15px; }
.panel-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 17px 18px; }
.empty-state { padding: 45px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink); margin-bottom: 5px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; text-align: left; padding: 11px 14px; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcff; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.row-title { font-weight: 750; }
.row-subtitle { color: var(--muted); font-size: 11px; margin-top: 3px; }
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.badge.blue { color: var(--primary); background: var(--primary-soft); }
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.amber { color: var(--amber); background: var(--amber-soft); }
.badge.red { color: var(--red); background: var(--red-soft); }
.badge.gray { color: #596579; background: #edf1f5; }
.badge.violet { color: var(--violet); background: #f0ebff; }
.stock-value { font-weight: 800; }
.stock-value.low { color: var(--red); }
.progress { width: 100%; height: 6px; background: #edf1f5; border-radius: 8px; overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.progress > span.warning { background: var(--amber); }

.alert-list { display: grid; gap: 10px; }
.alert-item { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 9px; }
.alert-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--red-soft); color: var(--red); font-weight: 900; }
.alert-item strong, .alert-item small { display: block; }
.alert-item small { color: var(--muted); margin-top: 3px; }

.task-list { display: grid; gap: 10px; }
.task-item { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 13px; align-items: center; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.task-item:last-child { border-bottom: 0; }
.task-priority { width: 8px; height: 42px; border-radius: 8px; background: var(--primary); }
.task-priority.high { background: var(--red); }
.task-priority.medium { background: var(--amber); }
.task-item strong, .task-item small { display: block; }
.task-item small { color: var(--muted); margin-top: 4px; }
.task-meta { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.process-funnel { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.funnel-step { padding: 17px; background: var(--surface); }
.funnel-step span, .funnel-step strong { display: block; }
.funnel-step span { color: var(--muted); font-size: 11px; }
.funnel-step strong { margin-top: 5px; font-size: 22px; }
.recommendation { padding: 14px; border-left: 4px solid var(--primary); background: var(--primary-soft); }
.recommendation strong, .recommendation span { display: block; }
.recommendation span { margin-top: 4px; color: #405175; font-size: 12px; }
.score-value { font-weight: 800; color: var(--primary); }

.metric-bars { display: grid; gap: 14px; }
.metric-row { display: grid; grid-template-columns: 150px 1fr 65px; gap: 10px; align-items: center; font-size: 12px; }
.bar-track { height: 9px; border-radius: 9px; background: #edf1f5; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--primary); }

.filter-input { padding: 9px 11px; min-width: 230px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }

dialog { width: min(700px, calc(100% - 28px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 14px; box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(11, 18, 31, .55); backdrop-filter: blur(2px); }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 19px 22px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.icon-button { border: 0; background: transparent; font-size: 25px; line-height: 1; color: var(--muted); }
.dialog-body { padding: 20px 22px; overflow-y: auto; max-height: calc(100vh - 190px); }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { color: #445269; font-size: 12px; font-weight: 750; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #cfd7e3; border-radius: 8px; padding: 9px 10px; color: var(--ink); background: #fff; }
.field textarea { min-height: 76px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 3px solid rgba(49,91,234,.13); border-color: var(--primary); }
.form-help { color: var(--muted); font-size: 11px; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 800; margin: 5px 0 10px; }
.line-editor { border: 1px solid var(--line); border-radius: 9px; margin-bottom: 10px; padding: 12px; }
.line-grid { display: grid; grid-template-columns: 1fr 110px 42px; gap: 9px; align-items: end; }
.line-grid.order-line { grid-template-columns: 1fr 100px 125px; }
.remove-line { height: 39px; border: 1px solid #facaca; background: var(--red-soft); color: var(--red); border-radius: 8px; font-weight: 900; }
.summary-strip { display: flex; gap: 20px; flex-wrap: wrap; padding: 12px; background: #f7f9fc; border-radius: 9px; margin-top: 14px; }
.summary-strip div { min-width: 105px; }
.summary-strip span, .summary-strip strong { display: block; }
.summary-strip span { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.summary-strip strong { font-size: 14px; }

.sparkline { width: 100%; height: 130px; display: block; }
.sparkline .axis { stroke: var(--line); stroke-width: 1; }
.sparkline .line { fill: none; stroke: var(--primary); stroke-width: 3; }
.sparkline .point { fill: var(--surface); stroke: var(--primary); stroke-width: 2; }
.sparkline text { fill: var(--muted); font-size: 10px; }

#toast-region { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--nav); color: #fff; padding: 12px 15px; border-radius: 9px; box-shadow: var(--shadow); font-size: 13px; animation: toast-in .2s ease-out; }
.toast.error { background: var(--red); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1050px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; width: 100%; }
  .menu-toggle { display: block; }
  .topbar { padding: 14px 16px; }
  .content { padding: 18px 14px 40px; }
  .user-chip div { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .line-grid, .line-grid.order-line { grid-template-columns: 1fr; }
  .metric-row { grid-template-columns: 110px 1fr 55px; }
  .process-funnel { grid-template-columns: repeat(2, 1fr); }
  .task-item { grid-template-columns: 7px minmax(0, 1fr); }
  .task-item > .button { grid-column: 2; justify-self: start; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar p { display: none; }
  .filter-input { min-width: 100%; }
}
