:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #e4e8ef;
  --text: #121826;
  --muted: #6b7280;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --nav: #0f172a;
  --nav-text: #cbd5e1;
  --green: #059669;
  --red: #dc2626;
  --amber: #b45309;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; }

/* ---------------------------------------------------------------- layout */
.app { min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 238px;
  background: linear-gradient(180deg, #111c33 0%, var(--nav) 60%);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  z-index: 40;
  transition: transform .22s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  color: #fff;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 17px;
  color: #fff;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  box-shadow: 0 6px 16px rgba(59, 130, 246, .35);
}

.brand-text { font-size: 15px; font-weight: 700; letter-spacing: .2px; }

.nav { flex: 1; overflow-y: auto; padding-right: 2px; }

.nav-group { margin-bottom: 16px; }

.nav-title {
  font-size: 10px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: #64748b;
  padding: 0 10px 6px;
  font-weight: 700;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--nav-text);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(37, 99, 235, .3); }
.nav-link .icon { flex: 0 0 auto; opacity: .9; }

.sidebar-foot {
  font-size: 10.5px;
  color: #64748b;
  padding: 14px 10px 2px;
  border-top: 1px solid rgba(255, 255, 255, .06);
}

.main { margin-left: 238px; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 19px; font-weight: 800; letter-spacing: -.2px; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.menu-btn {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 38px;
  height: 38px;
  font-size: 17px;
  cursor: pointer;
  color: var(--text);
}

.user-chip { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: 12px; color: var(--text); font-weight: 600; text-decoration: none; }
.user-name span { color: var(--muted); font-weight: 500; margin-left: 3px; }
.user-name:hover { text-decoration: none; color: var(--brand); }

.content { padding: 24px; max-width: 1240px; width: 100%; }
.content.wide { max-width: 1500px; }

.backdrop { display: none; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 14px; font-weight: 700; }
.card-actions { display: flex; gap: 6px; align-items: center; }
.card-body { padding: 16px 18px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 23px; font-weight: 800; margin-top: 4px; letter-spacing: -.3px; }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }

/* ---------------------------------------------------------------- tables */
.table-wrap { width: 100%; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: #f8fafc;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid #eef1f6;
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #f9fbff; }
table.data .num, .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .right, .right { text-align: right; }
.empty-cell { text-align: center; color: #9aa4b2; padding: 28px 12px !important; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}
.badge.grey { background: #f1f3f7; color: #5b6472; }
.badge.blue { background: #e8f0ff; color: #1d4ed8; }
.badge.green { background: #e7f7ef; color: #047857; }
.badge.red { background: #fdecec; color: #b91c1c; }
.badge.amber { background: #fdf3e3; color: #b45309; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #f4f6fa; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; }
.btn.danger { background: #fff; border-color: #f3c4c4; color: var(--red); }
.btn.danger:hover { background: #fdf2f2; }
.btn.sm { padding: 7px 12px; font-size: 12px; }
.btn.xs { padding: 4px 9px; font-size: 11.5px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn.link { border: none; background: none; padding: 0; color: var(--brand); font-weight: 600; }
.btn.link:hover { text-decoration: underline; background: none; }

form.inline { display: inline-block; margin: 0; }
.actions-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.card-head .actions-row { margin-top: 0; }

/* ---------------------------------------------------------------- alerts */
.alert {
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert.ok { background: #ecfdf3; border-color: #bbf7d0; color: #047857; }
.alert.err { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

/* ---------------------------------------------------------------- forms */
.form-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.form-card.narrow { max-width: 520px; }
.form-title { font-size: 13px; font-weight: 800; margin: 4px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid + .form-grid { margin-top: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: #374151; }
.field > span { display: block; }
.field small { font-weight: 400; color: var(--muted); font-size: 11px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #d5dbe5;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 400;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.field textarea { resize: vertical; min-height: 72px; }
.field input[type="number"] { text-align: right; }

.searchbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.searchbar input, .searchbar select {
  padding: 9px 12px;
  border: 1px solid #d5dbe5;
  border-radius: 9px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  outline: none;
}
.searchbar input { min-width: 240px; flex: 1; max-width: 360px; }
.searchbar input:focus, .searchbar select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }

.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { min-width: 180px; flex: 0 1 240px; }

.mini-input {
  width: 120px;
  padding: 5px 8px;
  border: 1px solid #d5dbe5;
  border-radius: 7px;
  font-size: 12px;
  font-family: inherit;
}

/* ---------------------------------------------------------------- docs */
.doc-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.doc-head-left { display: flex; align-items: center; gap: 12px; }
.doc-no-big { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.meta-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 26px; }
.meta-item span { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.meta-item strong { font-size: 13.5px; }

.totals { font-size: 13px; }
.totals > div { display: flex; justify-content: space-between; gap: 30px; padding: 6px 0; }
.totals .grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 17px; font-weight: 800; }
.detail-totals {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  width: 320px;
  max-width: 100%;
  margin: 0 0 18px auto;
  box-shadow: var(--shadow);
}

.doc-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.doc-lines { margin-top: 22px; }
.doc-lines-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.doc-lines-head h3 { font-size: 13px; font-weight: 800; }

table.line-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 680px; }
table.line-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: #f8fafc;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
table.line-table td { padding: 6px 8px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
table.line-table select {
  width: 100%;
  min-width: 190px;
  padding: 8px 9px;
  border: 1px solid #d5dbe5;
  border-radius: 7px;
  font-family: inherit;
  font-size: 12.5px;
  background: #fff;
}
table.line-table input {
  width: 92px;
  padding: 8px 9px;
  border: 1px solid #d5dbe5;
  border-radius: 7px;
  font-family: inherit;
  font-size: 12.5px;
  text-align: right;
}
table.line-table input:focus, table.line-table select:focus { border-color: var(--brand); outline: none; }
.spec-cell { color: var(--muted); font-size: 12px; max-width: 120px; }
.row-del {
  border: none;
  background: none;
  color: #c0392b;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.row-del:hover { background: #fdf2f2; }
tr.over-stock { background: #fff6f6; }
tr.over-stock .amount-cell { color: var(--red); font-weight: 700; }

.doc-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap; margin-top: 18px; }
.doc-foot .totals { width: 320px; max-width: 100%; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.doc-foot .actions-row { margin-top: 0; }

/* ---------------------------------------------------------------- misc */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pre-wrap { white-space: pre-wrap; margin: 0; }
.plus { color: var(--green); font-weight: 600; }
.minus { color: var(--red); font-weight: 600; }

/* ---------------------------------------------------------------- login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 15% 10%, #1e3a8a 0%, transparent 60%),
    radial-gradient(700px 500px at 90% 90%, #4c1d95 0%, transparent 60%),
    #0b1220;
}
.login-wrap {
  width: 100%;
  max-width: 390px;
  padding: 24px;
}
.login-brand { display: flex; align-items: center; gap: 12px; color: #fff; margin-bottom: 22px; }
.login-brand strong { display: block; font-size: 18px; }
.login-brand small { display: block; font-size: 11px; color: #94a3b8; margin-top: 2px; }
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .muted { margin: 0 0 20px; font-size: 12px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { margin-top: 8px; padding: 12px; font-size: 14px; }
.login-wrap .alert { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .backdrop.show { opacity: 1; pointer-events: auto; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 16px; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .meta-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .topbar-actions .btn { padding: 7px 10px; font-size: 12px; }
  .user-name { display: none; }
  .doc-foot { flex-direction: column; align-items: stretch; }
  .doc-foot .totals { width: 100%; }
  .detail-totals { width: 100%; margin-left: 0; }
}
