:root {
  --navy: #132d4f;
  --navy-soft: #1c3b63;
  --blue: #246bba;
  --blue-dark: #1d5a9d;
  --blue-soft: #eaf3fd;
  --ink: #172033;
  --muted: #65748a;
  --line: #dce4ee;
  --line-soft: #e9eef4;
  --bg: #f3f6fa;
  --white: #ffffff;
  --green: #18865b;
  --green-soft: #e9f7f1;
  --red: #c23b3b;
  --red-soft: #fff0f0;
  --orange: #d99020;
  --shadow: 0 8px 28px rgba(19, 45, 79, .07);
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

aside {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 26px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  color: #fff;
  background: var(--navy);
}

.brand {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  column-gap: 12px;
  padding: 0 6px;
}

.brand span,
.logo {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: #fff;
  color: var(--navy);
  font-size: 17px;
  font-weight: 800;
}

.brand b { font-size: 15px; font-weight: 700; letter-spacing: .04em; }
.brand small { grid-column: 2; color: #a9bbd0; font-size: 13px; }

aside nav { display: grid; gap: 4px; }

.nav-group {
  margin: 14px 12px 4px;
  color: #7f96b1;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
}

aside nav a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 13px;
  border-radius: 10px;
  color: #d0dbea;
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}

aside nav a:hover { background: var(--navy-soft); color: #fff; }
aside nav a.active { background: var(--blue); color: #fff; }

aside form { margin-top: auto; }

main {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 34px 36px 48px;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

h1 { margin: 0 0 5px; font-size: 30px; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; }
h2 { margin: 18px 0 14px; font-size: 19px; line-height: 1.35; font-weight: 700; }
h3 { font-weight: 700; }
p { margin: 0; color: var(--muted); }

button,
.button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 11px 18px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, transform .05s ease;
}

button:hover,
.button:hover { background: var(--blue-dark); }
button:active,
.button:active { transform: translateY(1px); }

.secondary { background: var(--navy); }
.secondary:hover { background: var(--navy-soft); }
.ghost { width: 100%; background: transparent; border: 1px solid #46617f; color: #d8e2ee; }
.ghost:hover { background: var(--navy-soft); }
.primary { min-height: 48px; padding: 13px 18px; }

.cards,
.stats-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.cards article,
.stats-cards article,
.panel,
.form-card,
.result-card,
.empty-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: var(--shadow);
}

.cards article,
.stats-cards article { padding: 20px; }
.cards small,
.stats-cards small { display: block; color: var(--muted); font-size: 14px; }
.cards strong,
.stats-cards strong { display: block; margin-top: 8px; font-size: 27px; line-height: 1.25; font-weight: 700; }

.panel { padding: 8px 20px 20px; overflow: auto; }
.panel h2 { padding: 0 2px; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 15px 11px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }
td b { font-weight: 650; }
td small { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.empty { padding: 42px 18px; text-align: center; color: var(--muted); }
.stock { color: var(--green); font-weight: 750; }
.stock.zero { color: var(--red); }

.kaspi-orders-panel { margin-bottom: 22px; }
.kaspi-orders-title { display:flex; align-items:center; justify-content:space-between; gap:16px; margin:0; }
.kaspi-orders-title h2 { margin-bottom:2px; }
.order-metrics { display:flex; flex-wrap:wrap; gap:10px; margin:2px 0 14px; }
.order-metrics span { padding:8px 11px; border-radius:9px; background:#eef5fc; color:#39546f; font-size:13px; }
.order-metrics b { margin-left:5px; color:var(--ink); }
.order-product + .order-product { margin-top:9px; padding-top:9px; border-top:1px solid var(--line-soft); }
.order-state { display:inline-block; padding:6px 9px; border-radius:999px; background:#eef2f7; font-size:12px; font-weight:700; white-space:nowrap; }
.state-reserved { background:#fff4d6; color:#875c00; }
.state-sold, .state-returned { background:var(--green-soft); color:var(--green); }
.state-cancelled { background:#eef2f7; color:#536174; }
.state-unlinked { background:var(--red-soft); color:var(--red); }
.state-return_pending { background:#fff0df; color:#934c00; }
.text-error { color:var(--red); }
.order-actions form { margin:0; }
.compact { min-height:36px; padding:8px 11px; font-size:13px; }

.form-card { width: 100%; max-width: 720px; padding: 26px; }
.form-card > h2:first-child { margin-top: 0; }
.form-card form { display: grid; gap: 18px; }

label { display: grid; gap: 7px; color: #344057; font-size: 15px; font-weight: 650; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid #cbd6e3;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
textarea { min-height: 100px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #8c98a8; }
input:focus, select:focus, textarea:focus { outline: 3px solid #d9eaff; border-color: var(--blue); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.search { display: flex; gap: 10px; margin-bottom: 18px; }
.search input { flex: 1; }
.lookup, .product-summary { padding: 15px; border: 1px solid #c9def4; border-radius: 11px; background: #eef5fc; color: var(--muted); }
.lookup b, .lookup span { display: block; }
.lookup b { margin-bottom: 4px; color: var(--ink); }

.alert { margin-bottom: 16px; padding: 13px 15px; border-radius: 10px; font-weight: 550; }
.error { background: var(--red-soft); color: var(--red); }
.success { background: var(--green-soft); color: var(--green); }
.status { display: inline-block; padding: 5px 10px; border-radius: 999px; background: var(--blue-soft); color: #244d79; font-size: 13px; font-weight: 700; }

body.login {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 20px;
  background: linear-gradient(145deg, #102844, #1d4b7d);
}

.login-card {
  width: min(430px, calc(100vw - 32px));
  padding: 34px;
  display: grid;
  gap: 18px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(6, 16, 31, .4);
}

.login-card h1 { margin: 0; }
.login-card .logo { background: var(--navy); color: #fff; }

@media (max-width: 1100px) {
  body { grid-template-columns: 228px minmax(0, 1fr); }
  main { padding: 28px 24px 42px; }
}
