:root {
  --over: #d82027;
  --over-dark: #a90f18;
  --ink: #17191d;
  --muted: #6d727d;
  --line: #e7e9ed;
  --panel: #ffffff;
  --canvas: #f5f6f8;
  --soft-red: #fff0f1;
  --soft-green: #eaf8f0;
  --soft-yellow: #fff6dc;
  --soft-blue: #eaf2ff;
  --green: #157347;
  --blue: #2657b8;
  --yellow: #946200;
  --shadow: 0 15px 42px rgba(26, 30, 39, 0.08);
  --radius: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  color: #fff;
  background: linear-gradient(180deg, #111317 0%, #1f2228 100%);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 24px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: var(--over); box-shadow: 0 10px 25px rgba(216, 32, 39, .35); font-family: Manrope, sans-serif; font-size: 25px; font-weight: 800; }
.brand-text { display: grid; line-height: 1.08; }
.brand-text strong { font-family: Manrope, sans-serif; font-size: 18px; letter-spacing: -.02em; }
.brand-text small { margin-top: 4px; color: #aeb3bd; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }

.nav-label { margin: 8px 10px; color: #7f8590; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.nav-list { display: grid; gap: 5px; }
.nav-button { position: relative; width: 100%; display: flex; align-items: center; gap: 11px; padding: 11px 12px; border: 0; border-radius: 11px; color: #c7cbd2; background: transparent; text-align: left; transition: background .15s ease, color .15s ease; }
.nav-button:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-button.active { background: rgba(216,32,39,.18); color: #fff; }
.nav-button.active::before { content: ""; position: absolute; left: 0; width: 3px; height: 24px; border-radius: 999px; background: var(--over); }
.nav-icon { width: 21px; display: inline-grid; place-items: center; font-size: 17px; }
.nav-badge { margin-left: auto; min-width: 23px; padding: 2px 7px; border-radius: 99px; color: white; background: var(--over); font-size: 11px; text-align: center; }
.sidebar-spacer { flex: 1; }
.sidebar-note { margin: 18px 5px 14px; padding: 13px; border: 1px solid rgba(255,255,255,.09); border-radius: 13px; color: #b6bbc4; background: rgba(255,255,255,.04); font-size: 12px; }
.profile-chip { display: flex; align-items: center; gap: 10px; padding: 10px 8px 0; border-top: 1px solid rgba(255,255,255,.08); }
.avatar { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: #fff; background: #4e535c; font-weight: 700; }
.profile-meta { min-width: 0; display: grid; }
.profile-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.profile-meta span { color: #999faa; font-size: 12px; }

.main { min-width: 0; }
.topbar { position: sticky; top: 0; display: flex; align-items: center; gap: 16px; height: 76px; padding: 0 30px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); backdrop-filter: blur(14px); z-index: 15; }
.topbar-title { min-width: 0; }
.topbar-title h1 { margin: 0; font-family: Manrope, sans-serif; font-size: 22px; letter-spacing: -.035em; }
.topbar-title p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }
.mobile-menu { display: none; }

.content { padding: 28px 30px 56px; }
.content-grid { display: grid; gap: 20px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.page-head h2 { margin: 0; font-family: Manrope, sans-serif; font-size: 27px; letter-spacing: -.04em; }
.page-head p { max-width: 720px; margin: 6px 0 0; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 9px; }

.btn { min-height: 41px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 14px; border: 1px solid transparent; border-radius: 11px; font-weight: 650; transition: transform .12s ease, box-shadow .12s ease, background .12s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--over); box-shadow: 0 8px 20px rgba(216,32,39,.2); }
.btn-primary:hover { background: var(--over-dark); }
.btn-secondary { border-color: var(--line); color: var(--ink); background: #fff; }
.btn-ghost { color: var(--muted); background: transparent; }
.btn-success { color: var(--green); background: var(--soft-green); }
.btn-warning { color: var(--yellow); background: var(--soft-yellow); }
.btn-danger { color: var(--over-dark); background: var(--soft-red); }
.btn-sm { min-height: 34px; padding: 6px 10px; border-radius: 9px; font-size: 13px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: 0 1px 2px rgba(17,19,23,.02); }
.card-pad { padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-header h3 { margin: 0; font-family: Manrope, sans-serif; font-size: 16px; letter-spacing: -.02em; }
.card-header p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.kpi { position: relative; overflow: hidden; padding: 19px; }
.kpi::after { content: ""; position: absolute; right: -18px; bottom: -31px; width: 95px; height: 95px; border-radius: 50%; background: var(--kpi-soft, var(--soft-red)); }
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi-value { margin-top: 8px; font-family: Manrope, sans-serif; font-size: 28px; font-weight: 800; letter-spacing: -.045em; }
.kpi-foot { margin-top: 7px; color: var(--muted); font-size: 12px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr); gap: 18px; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.filters { display: grid; grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(140px, .35fr)); gap: 10px; margin-bottom: 16px; }
.field { display: grid; gap: 6px; }
.field label { color: #444952; font-size: 12px; font-weight: 700; }
.input, .select, .textarea { width: 100%; min-height: 42px; border: 1px solid #dfe2e7; border-radius: 10px; color: var(--ink); background: #fff; outline: none; transition: border .15s ease, box-shadow .15s ease; }
.input, .select { padding: 9px 11px; }
.textarea { min-height: 94px; padding: 10px 11px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: rgba(216,32,39,.55); box-shadow: 0 0 0 3px rgba(216,32,39,.09); }
.input::placeholder, .textarea::placeholder { color: #a2a7af; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
.table { width: 100%; border-collapse: collapse; min-width: 780px; background: #fff; }
.table th { padding: 12px 14px; border-bottom: 1px solid var(--line); color: #767c86; background: #fafbfc; font-size: 11px; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
.table td { padding: 13px 14px; border-bottom: 1px solid #edf0f2; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fffafa; }
.table-main { font-weight: 700; }
.table-sub { margin-top: 2px; color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; }

.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-layout { color: var(--blue); background: var(--soft-blue); }
.status-material { color: #7251a8; background: #f1ebfb; }
.status-first { color: var(--yellow); background: var(--soft-yellow); }
.status-production { color: #8b3c89; background: #faebf8; }
.status-shipping { color: #277071; background: #e8f7f7; }
.status-done, .status-paid, .status-valid { color: var(--green); background: var(--soft-green); }
.status-contested { color: var(--over-dark); background: var(--soft-red); }

.kanban { display: grid; grid-template-columns: repeat(5, minmax(245px, 1fr)); gap: 13px; overflow-x: auto; padding-bottom: 10px; }
.kanban-column { min-height: 510px; padding: 12px; border: 1px solid var(--line); border-radius: 15px; background: #f0f2f5; }
.kanban-head { display: flex; align-items: center; justify-content: space-between; padding: 3px 3px 12px; }
.kanban-head strong { font-family: Manrope, sans-serif; font-size: 14px; }
.count { min-width: 24px; height: 24px; display: grid; place-items: center; border-radius: 99px; color: #676d76; background: #fff; font-size: 12px; }
.kanban-stack { display: grid; gap: 10px; }
.order-card { padding: 13px; border: 1px solid #e2e5e9; border-radius: 12px; background: #fff; box-shadow: 0 4px 12px rgba(28,31,38,.05); cursor: pointer; }
.order-card:hover { border-color: #d2d5da; transform: translateY(-1px); }
.order-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.order-code { color: var(--over); font-size: 12px; font-weight: 800; }
.order-title { margin-top: 8px; font-weight: 750; line-height: 1.25; }
.order-client { margin-top: 3px; color: var(--muted); font-size: 12px; }
.order-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #edf0f2; color: #737983; font-size: 11px; }

.timeline { display: grid; gap: 0; }
.timeline-item { position: relative; display: grid; grid-template-columns: 22px 1fr auto; gap: 11px; padding-bottom: 18px; }
.timeline-item:not(:last-child)::before { content: ""; position: absolute; left: 7px; top: 17px; bottom: 0; width: 1px; background: #dfe2e6; }
.timeline-dot { width: 15px; height: 15px; margin-top: 3px; border: 4px solid #ffdfe1; border-radius: 50%; background: var(--over); z-index: 1; }
.timeline-title { font-weight: 700; }
.timeline-desc { color: var(--muted); font-size: 12px; }
.timeline-date { color: #969ba4; font-size: 11px; white-space: nowrap; }

.bar-chart { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 80px; align-items: center; gap: 10px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; color: #50555e; font-size: 12px; white-space: nowrap; }
.bar-track { height: 9px; overflow: hidden; border-radius: 99px; background: #edf0f3; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--over), #f45a5f); }
.bar-value { font-size: 12px; font-weight: 700; text-align: right; }

.scenario-tabs { display: grid; grid-template-columns: repeat(5, minmax(95px, 1fr)); gap: 8px; margin-bottom: 16px; }
.scenario-tab { padding: 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: #fff; font-weight: 700; }
.scenario-tab.active { border-color: var(--over); color: var(--over); background: var(--soft-red); }
.calc-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(310px, .8fr); gap: 18px; }
.calc-result { padding: 22px; color: #fff; background: linear-gradient(145deg, #1d2026, #2c3038); }
.result-label { color: #c4c8cf; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.result-value { margin: 5px 0 12px; font-family: Manrope, sans-serif; font-size: 38px; font-weight: 800; letter-spacing: -.05em; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-cell { padding: 12px; border: 1px solid rgba(255,255,255,.08); border-radius: 11px; background: rgba(255,255,255,.05); }
.result-cell span { display: block; color: #aeb3bb; font-size: 11px; }
.result-cell strong { display: block; margin-top: 4px; font-size: 15px; }

.permission-table { display: grid; gap: 8px; }
.permission-row { display: grid; grid-template-columns: minmax(180px, 1fr) repeat(6, 80px); align-items: center; min-height: 44px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; }
.permission-row.head { border: 0; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.toggle { width: 40px; height: 23px; position: relative; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span { position: absolute; inset: 0; border-radius: 99px; background: #d9dde2; transition: .18s; }
.toggle span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 17px; height: 17px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .18s; }
.toggle input:checked + span { background: var(--over); }
.toggle input:checked + span::after { transform: translateX(17px); }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.compare-pane { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #f3f4f6; }
.compare-title { padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fff; font-size: 12px; font-weight: 750; }
.compare-image { aspect-ratio: 4 / 3; display: grid; place-items: center; color: #8b9099; background: repeating-linear-gradient(45deg, #f4f5f7, #f4f5f7 10px, #eceef1 10px, #eceef1 20px); text-align: center; }

.message-list { max-height: 360px; display: grid; gap: 10px; overflow-y: auto; padding-right: 5px; }
.message { max-width: 78%; padding: 10px 12px; border-radius: 13px 13px 13px 4px; background: #f0f2f5; }
.message.own { margin-left: auto; border-radius: 13px 13px 4px 13px; color: #fff; background: #2b2e34; }
.message-meta { margin-top: 4px; color: inherit; opacity: .65; font-size: 10px; }

.empty { display: grid; place-items: center; min-height: 240px; padding: 32px; color: var(--muted); text-align: center; }
.empty strong { display: block; margin-bottom: 5px; color: var(--ink); font-size: 16px; }
.notice { padding: 12px 14px; border: 1px solid #f0d6a0; border-radius: 11px; color: #775517; background: #fff9e9; font-size: 13px; }
.demo-banner { display: flex; align-items: center; gap: 9px; padding: 9px 13px; border: 1px solid #edd5d7; border-radius: 10px; color: #8d1820; background: #fff6f6; font-size: 12px; }

.modal-backdrop { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(12,14,17,.62); backdrop-filter: blur(4px); z-index: 50; }
.modal { width: min(760px, 100%); max-height: calc(100vh - 40px); overflow: auto; border-radius: 20px; background: #fff; box-shadow: var(--shadow); }
.modal-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 19px 21px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); z-index: 1; }
.modal-head h3 { margin: 0; font-family: Manrope, sans-serif; font-size: 19px; }
.modal-body { padding: 21px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 16px 21px 21px; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(460px, .95fr); background: #fff; }
.login-visual { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 48px; color: #fff; background: radial-gradient(circle at 75% 15%, #e24a50 0, transparent 26%), linear-gradient(145deg, #a70f17, #d82027 55%, #ef4d53); }
.login-visual::before, .login-visual::after { content: ""; position: absolute; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; }
.login-visual::before { width: 420px; height: 420px; right: -120px; bottom: -130px; }
.login-visual::after { width: 270px; height: 270px; right: -45px; bottom: -60px; }
.login-brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.login-copy { max-width: 610px; position: relative; z-index: 1; }
.login-copy h1 { margin: 0; font-family: Manrope, sans-serif; font-size: clamp(38px, 5vw, 66px); line-height: .98; letter-spacing: -.055em; }
.login-copy p { max-width: 530px; margin: 20px 0 0; color: rgba(255,255,255,.84); font-size: 17px; }
.login-features { display: flex; flex-wrap: wrap; gap: 9px; position: relative; z-index: 1; }
.login-feature { padding: 8px 11px; border: 1px solid rgba(255,255,255,.25); border-radius: 99px; background: rgba(255,255,255,.1); font-size: 12px; }
.login-panel { display: grid; place-items: center; padding: 36px; }
.login-card { width: min(430px, 100%); }
.login-card h2 { margin: 0; font-family: Manrope, sans-serif; font-size: 29px; letter-spacing: -.04em; }
.login-card > p { margin: 7px 0 24px; color: var(--muted); }
.login-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 4px; border-radius: 12px; background: #f0f2f4; }
.login-tab { min-height: 39px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-weight: 700; }
.login-tab.active { color: var(--ink); background: #fff; box-shadow: 0 2px 8px rgba(24,27,32,.08); }
.login-form { display: grid; gap: 14px; margin-top: 19px; }
.login-submit { width: 100%; margin-top: 3px; }
.login-help { margin-top: 18px; color: var(--muted); font-size: 12px; text-align: center; }

.toast-region { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 9px; z-index: 100; }
.toast { min-width: 280px; max-width: 390px; padding: 12px 14px; border: 1px solid var(--line); border-left: 4px solid var(--over); border-radius: 11px; background: #fff; box-shadow: var(--shadow); animation: toast-in .2s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calc-layout, .two-col { grid-template-columns: 1fr; }
  .permission-row { grid-template-columns: minmax(150px, 1fr) repeat(6, 65px); }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; transform: translateX(-102%); width: 270px; transition: transform .2s ease; box-shadow: 20px 0 40px rgba(0,0,0,.18); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: grid; }
  .topbar { height: 68px; padding: 0 18px; }
  .topbar-title p { display: none; }
  .content { padding: 22px 18px 48px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .three-col { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-visual { min-height: 330px; padding: 30px; }
  .login-panel { padding: 34px 20px; }
  .permission-table { overflow-x: auto; }
  .permission-row { min-width: 700px; }
}

@media (max-width: 580px) {
  .page-head { display: grid; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .kpi-grid, .filters, .form-grid, .compare { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .scenario-tabs { grid-template-columns: repeat(2, 1fr); }
  .scenario-tab:last-child { grid-column: 1 / -1; }
  .topbar-actions .demo-banner { display: none; }
  .login-copy h1 { font-size: 38px; }
  .login-visual { min-height: 300px; }
}

@media print {
  .sidebar, .topbar, .page-actions, .filters, .btn { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
