:root {
  --bg: #0b0d12;
  --bg-elev: #11141b;
  --bg-card: #151923;
  --border: #232838;
  --border-strong: #303749;
  --text: #e8ecf3;
  --text-dim: #9aa3b2;
  --muted: #6b7280;
  --primary: #6366f1;
  --primary-600: #4f46e5;
  --danger: #ef4444;
  --ok: #10b981;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.2), 0 8px 24px rgba(0,0,0,.18);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
code { background: rgba(255,255,255,.06); padding: 1px 6px; border-radius: 6px; font-size: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: rgba(11,13,18,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand-link { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 999px;
  background: linear-gradient(180deg, #818cf8, #6366f1);
  box-shadow: 0 0 10px rgba(99,102,241,.6);
}
.brand-name { letter-spacing: .3px; }
.topnav { display: flex; gap: 6px; }
.navlink {
  padding: 8px 12px; border-radius: 10px; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.navlink:hover { background: var(--bg-elev); color: var(--text); }
.navlink.active { background: var(--bg-elev); color: var(--text); }

.container { max-width: 1180px; margin: 28px auto; padding: 0 24px 60px; }

.hero {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  margin-bottom: 22px;
}
.hero h1 { margin: 6px 0 4px; font-size: 26px; letter-spacing: -.2px; }
.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.hero-actions { display: flex; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 9px 14px; border-radius: 10px;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  font-size: 14px; font-weight: 500;
  transition: background .15s, border-color .15s, transform .04s;
}
.btn:hover { background: #1a1f2b; border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, #6f7af8, var(--primary));
  border-color: var(--primary-600);
  color: #fff;
}
.btn-primary:hover { background: linear-gradient(180deg, #818cf8, var(--primary-600)); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-elev); }
.btn-danger-ghost { background: transparent; color: #fca5a5; border-color: rgba(239,68,68,.25); }
.btn-danger-ghost:hover { background: rgba(239,68,68,.08); border-color: rgba(239,68,68,.45); }
.btn-icon { padding: 4px 10px; font-size: 16px; line-height: 1; }

.input {
  width: 100%; padding: 10px 12px;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  outline: none; font-size: 14px; transition: border-color .15s, background .15s;
}
.input:focus { border-color: var(--primary); background: var(--bg-elev); }
textarea.input { resize: vertical; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--text-dim); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row .grow { flex: 1 1 280px; }
.row.align-end { align-items: flex-end; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; }

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.stat {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat-value { font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.stat-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }

.filters {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 16px;
}
.search { flex: 1 1 320px; max-width: 520px; }

.segmented { display: inline-flex; padding: 3px; gap: 3px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-card); }
.seg {
  position: relative; padding: 7px 12px; border-radius: 10px;
  font-size: 13px; color: var(--text-dim); cursor: pointer;
  transition: background .15s, color .15s;
  user-select: none;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg:hover { color: var(--text); }
.seg-active { background: var(--bg-elev); color: var(--text); }

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.card-archived { opacity: .65; }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card-title { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.card-link:hover { text-decoration: underline; }
.card-meta { font-size: 12px; }
.card-desc { font-size: 13px; color: var(--text-dim); margin: 0; }
.card-stats { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12px; padding: 3px 8px;
  background: rgba(99,102,241,.12); border: 1px solid rgba(99,102,241,.25);
  color: #c7d2fe; border-radius: 999px;
}
.chip-entrepot {
  background: rgba(16,185,129,.10); border-color: rgba(16,185,129,.25); color: #a7f3d0;
}
select.input { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
select.input:disabled { opacity: .55; cursor: not-allowed; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); }
.badge-muted { background: rgba(255,255,255,.04); }
.badge-ok { color: #a7f3d0; background: rgba(16,185,129,.12); border-color: rgba(16,185,129,.3); }

.empty {
  text-align: center; padding: 40px 16px;
  background: var(--bg-card); border: 1px dashed var(--border-strong); border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}

.banner {
  margin-top: 22px; padding: 12px 16px; display: flex; gap: 12px;
  align-items: center; justify-content: space-between;
  background: rgba(245,158,11,.07); border: 1px solid rgba(245,158,11,.25);
  color: #fde68a; border-radius: var(--radius);
}

.form-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; margin-top: 14px;
  display: flex; flex-direction: column; gap: 14px;
}

.kits { display: flex; flex-direction: column; gap: 14px; }
.kits-head { display: flex; justify-content: space-between; align-items: center; }
.kit {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; background: var(--bg-elev);
  display: flex; flex-direction: column; gap: 12px;
}
.kit-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.kit-name { max-width: 480px; font-weight: 600; }

.prod-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.prod-table th, .prod-table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.prod-table th { color: var(--text-dim); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.prod-table tr:last-child td { border-bottom: 0; }
.prod-table .input { padding: 7px 10px; }

.kits-readonly { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }

.ifls-area { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.ifls-preview { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.ifls-preview > summary { cursor: pointer; user-select: none; }
.chips-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips-preview .chip { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 6px; }
.error { color: #fca5a5; font-size: 13px; margin: 0; }

.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  background: #0f172a; color: #e2e8f0;
  padding: 10px 14px; border-radius: 10px; border: 1px solid #1e293b;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(2,6,23,.65);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  width: min(560px, 100%); max-height: 90vh; overflow: auto;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.modal-head, .modal-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
}
.modal-head { border-bottom: 1px solid var(--border); }
.modal-foot { border-top: 1px solid var(--border); gap: 10px; }
.modal-foot .btn-primary { margin-left: auto; }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.result-box {
  background: rgba(16,185,129,.08); border: 1px solid rgba(16,185,129,.25);
  border-radius: 10px; padding: 10px 12px; color: #d1fae5;
}
.result-box ul { margin: 6px 0 0 18px; }

@media (max-width: 720px) {
  .hero { flex-direction: column; align-items: flex-start; }
  .topnav .navlink { padding: 6px 10px; }
}
