:root {
  --navy: #14233a;
  --navy-2: #1d3454;
  --ink: #1c1712;
  --muted: #6e6458;
  --gold: #b8892d;
  --gold-2: #d7b56a;
  --cream: #f6f0e4;
  --paper: #fffdf8;
  --line: #e6dcc8;
  --ok: #2c6a4e;
  --ok-bg: #e7f4ec;
  --err: #9b3226;
  --err-bg: #fbeceb;
  --shadow: 0 18px 40px rgba(20, 35, 58, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Assistant, "Segoe UI", Tahoma, sans-serif;
  background: var(--cream);
  color: var(--ink);
}

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px;
  background: linear-gradient(180deg, var(--navy) 0%, #0f1c2e 100%);
  color: #f4ead6;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 22px 18px 18px;
  border-bottom: 1px solid rgba(215, 181, 106, 0.18);
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--gold), #f0d48a);
  color: var(--navy);
  display: grid; place-items: center;
  font-weight: 800; font-size: 22px;
}
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand span { display: block; font-size: 12px; opacity: 0.7; margin-top: 2px; }
.sidebar nav { padding: 12px 10px; display: grid; gap: 4px; overflow: auto; }
.sidebar nav a {
  color: #eadfcb;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); }
.sidebar nav a.active {
  background: rgba(184, 137, 45, 0.22);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--gold);
}
.sidebar-foot {
  margin-top: auto;
  padding: 16px 18px 20px;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid rgba(215, 181, 106, 0.18);
  font-size: 13px;
}
.sidebar-foot a { color: var(--gold-2); }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 28px 8px;
}
.topbar h1 { margin: 0; font-size: 28px; letter-spacing: -0.03em; }
.nav-toggle { display: none; }
.content { padding: 12px 28px 40px; }

.alert {
  margin: 0 28px 8px;
  padding: 12px 14px;
  border-radius: 10px;
  font-weight: 600;
}
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.err { background: var(--err-bg); color: var(--err); }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 16px; }
.card h2 { margin: 0 0 16px; font-size: 18px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat span { color: var(--muted); font-weight: 600; font-size: 13px; }
.stat strong { display: block; font-size: 28px; margin-top: 6px; color: var(--navy); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 28px;
}
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 700; color: var(--navy); }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid #d9cfbb;
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
}
.field textarea { min-height: 110px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(184, 137, 45, 0.35);
  border-color: var(--gold);
}
.split {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
}
.inline {
  display: flex; gap: 8px; align-items: center;
}
.inline .grow { flex: 1; }

.combo {
  position: relative;
  min-width: 0;
}
.combo.grow { flex: 1; }
.combo > select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}
.combo-input {
  width: 100%;
  border: 1px solid #d9cfbb;
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
}
.combo-input:focus {
  outline: 2px solid rgba(184, 137, 45, 0.35);
  border-color: var(--gold);
}
.combo-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  max-height: 240px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 40;
}
.combo.open .combo-list { display: block; }
.combo-item, .combo-empty {
  padding: 8px 12px;
  cursor: pointer;
}
.combo-item:hover, .combo-item.active { background: #f4ead4; }
.combo-empty { color: var(--muted); cursor: default; }
.combo-add { color: var(--navy); font-weight: 700; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: linear-gradient(180deg, #2a4a73, var(--navy));
  color: #fff; font: inherit; font-weight: 700;
  padding: 11px 18px; border-radius: 12px;
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { filter: brightness(1.08); }
.btn.gold { background: linear-gradient(180deg, #d7b56a, var(--gold)); color: var(--navy); }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn.danger { background: linear-gradient(180deg, #c45a4c, var(--err)); }
.btn.small { padding: 7px 10px; border-radius: 9px; font-size: 14px; }
.plus {
  width: 38px; height: 38px; border-radius: 50%;
  background: #2f7a4e; color: #fff; border: 0; font-size: 22px; cursor: pointer;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
table.data th, table.data td {
  text-align: right;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data th { color: var(--muted); font-size: 13px; }
table.data td.notes {
  white-space: normal;
  max-width: 240px;
  min-width: 120px;
  line-height: 1.35;
}
table.data tbody tr:hover { background: #fbf6ea; }
.badge {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 800;
}
.badge.open { background: #e7f4ec; color: var(--ok); }
.badge.closed { background: #eee; color: #666; }
.remain { font-weight: 800; }
.remain.low { color: var(--err); }
.bar {
  height: 8px; background: #efe6d4; border-radius: 99px; overflow: hidden; min-width: 90px;
}
.bar > i { display: block; height: 100%; background: var(--gold); }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(215,181,106,.25), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(20,35,58,.18), transparent 42%),
    var(--cream);
}
.login-card {
  width: min(420px, 92vw);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { margin: 0 0 6px; }
.login-card p { margin: 0 0 18px; color: var(--muted); }

.modal {
  position: fixed; inset: 0; background: rgba(15, 20, 30, 0.45);
  display: none; place-items: center; z-index: 50; padding: 16px;
}
.modal.open { display: grid; }
.modal .card { width: min(520px, 100%); }

.hint {
  font-size: 13px; color: var(--muted); font-weight: 600;
}
.hint strong { color: var(--navy); }

.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 14px; }
.totals { display: flex; gap: 18px; flex-wrap: wrap; font-weight: 800; color: var(--navy); margin-top: 12px; }

.person-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 8px 0 22px;
}
.person-card {
  --accent: #1f4e79;
  --wash: #e7eef6;
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
  border-top: 7px solid var(--accent);
  transition: transform .12s ease, box-shadow .12s ease;
}
.person-card:hover { transform: translateY(-2px); box-shadow: 0 22px 36px rgba(20,35,58,.16); }
.person-card.selected { outline: 3px solid var(--accent); }
.person-card .who {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}
.avatar {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--wash); color: var(--accent);
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px;
}
.person-card h3 { margin: 0; font-size: 18px; color: var(--navy); }
.person-card .meta { color: var(--muted); font-size: 13px; font-weight: 600; }
.metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.metrics div {
  background: var(--wash);
  border-radius: 12px;
  padding: 8px 10px;
}
.metrics span { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }
.metrics strong { font-size: 16px; color: var(--accent); }

.tone-1 { --accent:#1f4e79; --wash:#e4eef7; }
.tone-2 { --accent:#b45309; --wash:#f8ead8; }
.tone-3 { --accent:#166534; --wash:#e3f2e8; }
.tone-4 { --accent:#9f1239; --wash:#f8e2e8; }
.tone-5 { --accent:#0f766e; --wash:#ddf3f0; }
.tone-6 { --accent:#a16207; --wash:#f6edcf; }
.tone-7 { --accent:#1d4ed8; --wash:#e3eafc; }
.tone-8 { --accent:#9a3412; --wash:#f6e4da; }
.tone-9 { --accent:#115e59; --wash:#dceeed; }
.tone-10 { --accent:#7f1d1d; --wash:#f5e2e2; }

.sum-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.sum-filters .field { min-width: 160px; }
.sum-filters .field label { font-size: 13px; }
.sum-filter-actions { display: flex; gap: 8px; padding-bottom: 2px; }
.icon-btn {
  width: 42px; height: 42px;
  border: 0; border-radius: 10px;
  background: #1f6aa5;
  color: #fff;
  display: grid; place-items: center;
  text-decoration: none;
  cursor: pointer;
}
.icon-btn:hover { filter: brightness(1.08); }

.sum-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.sum-card {
  --fill: #5b2c6f;
  display: flex;
  flex-direction: column;
  min-height: 176px;
  text-decoration: none;
  color: #fff;
  background: var(--fill);
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(20, 20, 30, .22);
  overflow: hidden;
}
.sum-card:hover { transform: translateY(-2px); }
.sum-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px 4px;
}
.sum-party { font-size: 22px; font-weight: 800; line-height: 1.2; }
.sum-product { font-size: 18px; font-weight: 700; opacity: .95; }
.sum-locs {
  flex: 1;
  padding: 8px 16px 12px;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.55;
}
.sum-foot {
  margin-top: auto;
  background: rgba(0, 0, 0, .22);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 12px;
  color: #fff;
  position: relative;
}
.sum-foot .sack {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
}
.sum-foot strong { font-size: 22px; letter-spacing: .02em; }
.sum-card.tone-1 { --fill:#1f4e79; }
.sum-card.tone-2 { --fill:#8b1e3f; }
.sum-card.tone-3 { --fill:#5b2c6f; }
.sum-card.tone-4 { --fill:#9f1239; }
.sum-card.tone-5 { --fill:#0f5f5b; }
.sum-card.tone-6 { --fill:#a15c07; }
.sum-card.tone-7 { --fill:#1d4e89; }
.sum-card.tone-8 { --fill:#9a3412; }
.sum-card.tone-9 { --fill:#115e59; }
.sum-card.tone-10 { --fill:#7f1d1d; }

.import-steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.import-steps span {
  padding: 6px 10px; border-radius: 999px; background: #efe6d4; font-weight: 700; font-size: 13px;
}
.import-steps span.on { background: var(--gold); color: var(--navy); }

@media (max-width: 980px) {
  .person-grid, .sum-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .person-grid, .sum-grid { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .filters, .sum-filters, .actions, .btn, .nav-toggle { display: none !important; }
  .app-shell, .main, .content { display: block; padding: 0; }
  .card { box-shadow: none; border: 0; }
  .person-grid, .sum-grid { grid-template-columns: 1fr 1fr; }
  .person-card, .sum-card { break-inside: avoid; box-shadow: none; }
}

@media (max-width: 980px) {
  .sidebar {
    position: fixed; right: 0; transform: translateX(110%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .nav-toggle {
    display: inline-flex; background: var(--navy); color: #fff;
    border: 0; border-radius: 10px; padding: 8px 12px; cursor: pointer;
  }
  .stats, .form-grid, .filters { grid-template-columns: 1fr 1fr; }
  .nav-backdrop.show {
    position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15;
  }
}
@media (max-width: 640px) {
  .stats, .form-grid, .filters, .split { grid-template-columns: 1fr; }
  .content, .topbar, .alert { padding-right: 16px; padding-left: 16px; margin-right: 0; margin-left: 0; }
}
