:root {
  --ink: #0e1b23;
  --teal: #296273;
  --teal-dark: #1e4a58;
  --teal-deep: #16323c;
  --sky: #a8d6f7;
  --purple: #442e6f;
  --orange: #ee7e32;
  --green: #49a07d;
  --red: #c4554d;
  --bg: #f4f7f9;
  --card: #ffffff;
  --muted: #6b7a85;
  --line: #e2e9ee;
  --line-strong: #cfdae2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 44, 56, .05), 0 8px 24px rgba(16, 44, 56, .05);
  --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--teal); text-decoration: none; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.green { color: var(--green); }
.red { color: var(--red); }

/* ---------------------------------------------------------------- login */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 20% -10%, #2f6c7d 0%, #16323c 55%, #0d1f26 100%);
}
.login-card {
  width: 360px; background: #fff; border-radius: 20px; padding: 34px 32px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}
.login-logo {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark)); color: #fff;
  font-weight: 800; letter-spacing: .5px; margin-bottom: 18px;
}
.login-logo-horizontal {
  display: block; width: 290px; max-width: 100%; height: auto; margin: 0 auto 16px;
}
.brand-mark-img {
  width: 38px; height: 38px; border-radius: 10px; background: transparent; padding: 0;
  object-fit: contain; flex: 0 0 auto;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.3px; }
.login-card p { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.login-card input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line-strong); border-radius: 10px;
  margin-bottom: 14px; outline: none;
}
.login-card input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(41, 98, 115, .12); }
.login-error { color: var(--red); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* ---------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #1c4654 0%, #16323c 60%, #122931 100%);
  color: #dce9ef; padding: 22px 14px 16px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 0 6px 22px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--sky), #6fb7e6); color: #12303a; font-weight: 800; font-size: 13px;
}
.brand-name { font-weight: 700; font-size: 15px; color: #fff; letter-spacing: .2px; }
.brand-sub { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: #7fa4b2; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #b9d0da; cursor: pointer; border: 0; background: transparent; text-align: left; font-size: 13.5px;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: rgba(168, 214, 247, .14); color: #fff; box-shadow: inset 2px 0 0 var(--sky); }
.nav-item .ico { width: 18px; height: 18px; opacity: .85; }
.nav-item .count {
  margin-left: auto; background: var(--orange); color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 20px;
}
.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; gap: 8px; font-size: 11.5px;
  color: #7fa4b2; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .08);
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(73, 160, 125, .18); }
.sync-dot.warn { background: var(--orange); box-shadow: 0 0 0 3px rgba(238, 126, 50, .18); }

.shell { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px; background: rgba(255, 255, 255, .86); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px;
  padding: 0 24px; position: sticky; top: 0; z-index: 20;
}
.mp-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.mp-tab {
  border: 0; background: transparent; color: var(--muted); padding: 8px 13px; border-radius: 9px;
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 7px;
}
.mp-tab:hover { background: #eef3f6; color: var(--ink); }
.mp-tab.active { background: var(--teal); color: #fff; }
.mp-tab.disabled { opacity: .5; cursor: default; }
.mp-tab .soon { font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; background: #e8eef2; color: var(--muted); padding: 2px 5px; border-radius: 4px; }
.mp-tab.active .soon { background: rgba(255, 255, 255, .18); color: #fff; }
.mp-tab .badge-n {
  background: var(--orange); color: #fff; font-size: 10.5px; border-radius: 20px; padding: 1px 6px; font-weight: 700;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; color: var(--teal); font-size: 16px;
}
.icon-btn:hover { background: #f1f6f8; }
.user-chip { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.link { border: 0; background: none; color: var(--teal); cursor: pointer; font-size: 12px; padding: 0; }

.view { padding: 26px 28px 60px; max-width: 1560px; width: 100%; margin: 0 auto; }

/* ---------------------------------------------------------------- typography */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { margin: 0; font-size: 24px; letter-spacing: -.5px; font-weight: 720; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 0 10px; font-weight: 700; }

/* ---------------------------------------------------------------- cards / KPI */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi { padding: 16px 16px 14px; position: relative; overflow: hidden; }
.kpi-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.kpi-value { font-size: 22px; font-weight: 740; letter-spacing: -.6px; margin-top: 7px; }
.kpi-value small { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.kpi.accent { background: linear-gradient(135deg, #1f4d5c, #296273); color: #fff; border-color: transparent; }
.kpi.accent .kpi-label, .kpi.accent .kpi-sub { color: #a9c9d5; }
.kpi.accent .kpi-value { color: #fff; }
.kpi.warn .kpi-value { color: var(--orange); }

.panel { padding: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.panel-title { font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.panel-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.two-col { display: grid; grid-template-columns: 1.55fr 1fr; gap: 14px; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

/* ---------------------------------------------------------------- chart */
.chart-wrap { width: 100%; height: 230px; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; border-radius: 12px; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; padding: 11px 12px; background: #f8fafb;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: #f7fafb; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .strong { font-weight: 650; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.product-cell { max-width: 380px; }
.product-cell .cell-main { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 7px;
  font-size: 11.5px; font-weight: 650; white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.new { background: #e8f2fb; color: #2b6b9a; }
.badge.accepted { background: #eaf5f1; color: #2f7d61; }
.badge.awaiting_courier { background: #fff3e7; color: #b8641f; }
.badge.in_delivery { background: #eee9f8; color: #5a3f96; }
.badge.ready_for_pickup { background: #e6f6f4; color: #1f7a70; }
.badge.completed { background: #e9f6ee; color: #2e7d4f; }
.badge.cancel_requested, .badge.return_requested { background: #fdf0e6; color: #a96420; }
.badge.cancelled { background: #f7eceb; color: #a24740; }
.badge.returning, .badge.returned { background: #f4eef7; color: #7a4a80; }
.badge.unknown { background: #eef2f4; color: #65757f; }
.badge.flat { background: #f1f5f7; color: #5a6b76; }
.badge.flat::before { display: none; }
.purchase-edit {
  width: 108px; height: 28px; border: 1px solid transparent; border-bottom-color: #b9cbd5;
  border-radius: 6px 6px 2px 2px; background-color: #fbfdfe;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a8b95' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 5px center;
  text-align: right; font-variant-numeric: tabular-nums;
  font-size: 12.5px; color: inherit; padding: 0 22px 0 6px;
}
.purchase-edit:hover { border-color: var(--teal); background-color: #fff; }
.purchase-edit:focus { border-color: var(--teal); background: #fff; outline: none; box-shadow: 0 0 0 3px rgba(41, 98, 115, .1); }
.purchase-edit.edited { background: #e7f5ec; border-color: #bfe3cd; color: #2e7d4f; font-weight: 700; }
td.cost-edited { background: #e7f5ec !important; }

.badge.final, .badge.manual { background: #e9f6ee; color: #2e7d4f; }
.badge.preliminary { background: #eef2f4; color: #65757f; }
.badge.no_cost { background: #fdf0e6; color: #a96420; }
.badge.unconfirmed, .badge.stale { background: #fdf6e3; color: #8a6d1f; }
.badge.excluded { background: #f1f5f7; color: #8b98a1; }

/* ---------------------------------------------------------------- filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters .grow { flex: 1; min-width: 220px; }
.input, .select {
  height: 38px; border: 1px solid var(--line-strong); border-radius: 9px; padding: 0 11px;
  background: #fff; outline: none; font-size: 13px;
}
.input:focus, .select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(41, 98, 115, .1); }
.input::placeholder { color: #9aa8b1; }
.input-sm { height: 32px; font-size: 12.5px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 6px 11px;
  font-size: 12px; cursor: pointer; color: var(--muted); display: inline-flex; gap: 6px; align-items: center;
}
.chip .n { font-weight: 700; color: var(--ink); }
.chip.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.chip.active .n { color: #fff; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: 9px; border: 1px solid var(--line-strong);
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: #f5f8fa; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-accent { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-accent:hover { filter: brightness(.95); }
.btn-danger { background: #fff; border-color: #e7c9c6; color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--teal); }
.btn-sm { height: 31px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- drawer */
.drawer, .modal { position: fixed; inset: 0; z-index: 60; }
.drawer-backdrop, .modal-backdrop { position: absolute; inset: 0; background: rgba(10, 26, 33, .42); backdrop-filter: blur(2px); }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: min(680px, 100%);
  background: var(--bg); box-shadow: -20px 0 50px rgba(10, 26, 33, .18);
  overflow-y: auto; animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: .6; } to { transform: translateX(0); opacity: 1; } }
.modal-panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(780px, calc(100% - 32px)); max-height: calc(100vh - 60px);
  overflow-y: auto; overflow-x: hidden;
  background: var(--bg); border-radius: 18px; box-shadow: 0 30px 80px rgba(10, 26, 33, .3);
}

.drawer-head {
  position: sticky; top: 0; z-index: 5; background: #fff; border-bottom: 1px solid var(--line);
  padding: 18px 22px 14px;
}
.drawer-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.drawer-title { margin: 0; font-size: 19px; letter-spacing: -.3px; }
.drawer-meta { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.drawer-body { padding: 18px 22px 40px; }
.close-x { border: 0; background: #f1f5f7; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.close-x:hover { background: #e6edf1; }

.section { margin-bottom: 18px; }
.section h4 { margin: 0 0 9px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; font-size: 13px; }
.info-grid .k { color: var(--muted); font-size: 11.5px; }
.info-grid .v { font-weight: 600; margin-top: 2px; }

.money-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.money-box { background: #fff; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; }
.money-box .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.money-box .value { font-size: 15px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.money-box.total { background: var(--teal); border-color: var(--teal); color: #fff; }
.money-box.total .label { color: #b6d3dd; }
.money-box.profit { background: #eef8f3; border-color: #d3ebdf; }
.money-box.profit .value { color: #2e7d4f; }

.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ""; position: absolute; left: 4px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.timeline-item { position: relative; padding: 0 0 12px 0; font-size: 12.5px; }
.timeline-item::before { content: ""; position: absolute; left: -18px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--teal); border: 2px solid #fff; }
.timeline-item .t { color: var(--muted); font-size: 11.5px; }

/* ---------------------------------------------------------------- forms */
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 11.5px; font-weight: 650; color: var(--muted); }
.field input, .field select { height: 36px; width: 100%; min-width: 0; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 10px; background: #fff; outline: none; }
.field input:focus, .field select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(41, 98, 115, .1); }
.field .hint { font-size: 10.5px; color: #93a1aa; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------------------------------------------------------------- stores */
.store-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.store-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.store-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.store-name { font-weight: 700; font-size: 15px; letter-spacing: -.2px; }
.store-code { font-size: 11px; color: var(--muted); font-family: var(--mono); margin-top: 2px; }
.store-stats { display: flex; gap: 16px; }
.store-stat .n { font-size: 17px; font-weight: 700; }
.store-stat .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.store-rates { display: flex; flex-wrap: wrap; gap: 6px; }
.rate-chip { background: #f3f7f9; border-radius: 7px; padding: 4px 8px; font-size: 11px; color: #51636e; }
.rate-chip b { color: var(--ink); }
.store-foot { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.dot-alive { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; margin-right: 5px; }
.dot-dead { width: 7px; height: 7px; border-radius: 50%; background: var(--red); display: inline-block; margin-right: 5px; }

/* ---------------------------------------------------------------- misc */
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 28px; margin-bottom: 8px; opacity: .5; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 11px; font-size: 12.5px; margin-bottom: 14px; }
.banner.info { background: #eaf3f8; color: #265a70; }
.banner.warn { background: #fdf3e5; color: #8a5a1c; }
.banner.err { background: #fbeeed; color: #8f3f39; }
.banner b { font-weight: 700; }
.pagination { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: #16323c; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .25); max-width: 90vw;
}
.toast.err { background: #8f3f39; }
.skeleton { background: linear-gradient(90deg, #eef3f5 25%, #f6f9fa 50%, #eef3f5 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.loading { padding: 30px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto; }
  .brand { padding: 0 12px 0 0; }
  .brand-sub, .sidebar-foot { display: none; }
  .nav { flex-direction: row; margin: 0; }
  .nav-item { white-space: nowrap; }
  .view { padding: 18px 14px 60px; }
  .topbar { padding: 0 12px; height: auto; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .three-col { grid-template-columns: 1fr; }
  .form-grid, .info-grid, .money-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 18px; }
  .money-grid { grid-template-columns: 1fr 1fr; }
}
