:root {
  --night: #070b14;
  --night-2: #0c1220;
  --panel: #101826;
  --ink: #e8e4dc;
  --muted: #8b93a7;
  --line: rgba(201, 162, 39, 0.28);
  --gold: #c9a227;
  --gold-soft: #e4c86a;
  --accent: #c9a227;
  --danger: #d36b6b;
  --ok: #7cbc7a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  font-family: Outfit, "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--night);
  color: var(--ink);
  min-height: 100vh;
}
#login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(ellipse 70% 50% at 80% 10%, rgba(201, 162, 39, 0.1), transparent 50%),
    linear-gradient(180deg, #05080f, #070b14);
}
#login[hidden], #app[hidden] { display: none !important; }
.card {
  background: var(--panel);
  padding: 32px 28px;
  width: min(400px, 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 0 40px rgba(201, 162, 39, 0.08);
}
.card img { width: 48px; height: 48px; }
.card h1 {
  font-size: 22px;
  font-weight: 500;
  margin: 12px 0 20px;
  letter-spacing: 0.04em;
  color: var(--gold);
}
label { display: block; font-size: 12px; margin: 12px 0 6px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
input, textarea, select {
  width: 100%;
  max-width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
  background: #0a1220;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.16);
}
button { font: inherit; cursor: pointer; }
.card button, .primary {
  margin-top: 16px;
  background: var(--gold);
  color: var(--night);
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
}
.card button:hover, .primary:hover { background: var(--gold-soft); }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 1em; }

#app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: start;
  align-content: start;
}
aside {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100vh;
  height: 100dvh;
  align-self: start;
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--night-2);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.aside-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.aside-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.aside-brand img { width: 36px; height: 36px; flex: 0 0 auto; }
.aside-brand strong { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); }
.nav-toggle {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  padding: 0;
  place-items: center;
  flex: 0 0 auto;
}
.nav-toggle span,
.nav-toggle span::before,
.nav-toggle span::after {
  display: block;
  width: 16px;
  height: 1.5px;
  background: currentColor;
  position: relative;
}
.nav-toggle span::before,
.nav-toggle span::after {
  content: "";
  position: absolute;
  left: 0;
}
.nav-toggle span::before { top: -5px; }
.nav-toggle span::after { top: 5px; }
.nav-toggle[aria-expanded="true"] span { background: transparent; }
.nav-toggle[aria-expanded="true"] span::before { top: 0; transform: rotate(45deg); }
.nav-toggle[aria-expanded="true"] span::after { top: 0; transform: rotate(-45deg); }
aside nav { display: flex; flex-direction: column; gap: 4px; }
aside nav button, #logout {
  text-align: left;
  background: none;
  border: 0;
  padding: 9px 10px;
  color: var(--muted);
}
aside nav button.active, aside nav button:hover { background: rgba(201, 162, 39, 0.1); color: var(--gold); }
#logout { margin-top: auto; color: var(--gold); border: 1px solid transparent; }
#logout:hover { border-color: var(--line); }

main, #view {
  padding: 20px 24px 32px;
  min-width: 0;
  min-height: 0;
  align-self: start;
}
h2 { font-size: 22px; font-weight: 500; margin-bottom: 8px; color: var(--ink); }
h3 { font-size: 16px; font-weight: 500; margin: 18px 0 10px; color: var(--gold); }
.sub { color: var(--muted); margin-bottom: 22px; font-size: 14px; line-height: 1.45; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px 14px;
}
.stat b { display: block; font-size: 26px; color: var(--gold); font-weight: 500; letter-spacing: 0.02em; }
.stat span { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 20px;
}
table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  background: var(--panel);
  font-size: 14px;
}
th, td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 10px 8px;
  vertical-align: top;
}
th { color: var(--gold); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 500; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.row-actions button, .ghost {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--ink);
}
.row-actions button:hover, .ghost:hover { border-color: var(--gold); color: var(--gold); }
.ghost { display: inline-block; text-decoration: none; color: var(--ink); }

form.stack {
  max-width: 640px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 16px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.msg {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
  margin-bottom: 12px;
}
.thread { font-size: 13px; color: var(--muted); white-space: pre-wrap; margin: 8px 0; }
.qr img { width: min(240px, 100%); background: #fff; padding: 10px; border: 1px solid var(--line); }
.ok { color: var(--ok); font-size: 13px; margin-top: 8px; }
.hint, .lbl-plain {
  display: block;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0;
  text-transform: none;
  margin-top: 6px;
}
.lbl-plain {
  margin: 14px 0 8px;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.disc-list { display: flex; flex-direction: column; gap: 8px; }
.disc-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a1220;
}
.disc-row input[type="checkbox"] { width: auto; margin: 0; }
.disc-name { font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.disc-off {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.disc-off input[type="number"] {
  width: 72px;
  display: inline-block;
  text-align: right;
}
.disc-off em { font-style: normal; color: var(--gold); }
.source-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}
.source-split > div {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
}
.source-split span {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.source-split b { display: block; font-size: 24px; color: var(--gold); margin: 6px 0 10px; }
.loc-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.loc-card h3 { margin: 0 0 4px; }
.loc-card p { color: var(--ink); font-size: 14px; margin: 0 0 6px; }
.loc-card small { color: var(--muted); }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px 18px;
  margin: 18px 0;
}
.panel h3 { margin-top: 0; }
.panel.import-panel summary {
  cursor: pointer;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
}
form.stack.flush { border: 0; background: transparent; padding: 0; margin: 0; max-width: none; }
.logo-preview {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #0a1220;
  margin-bottom: 10px;
}
.empty { color: var(--muted); font-size: 14px; margin: 12px 0 20px; }
.bar-list { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 22px; }
.row-actions button.danger:hover { border-color: var(--danger); color: var(--danger); }

@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    align-items: start;
    align-content: start;
  }
  aside {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 14px;
    overflow: visible;
  }
  aside.open {
    max-height: 100dvh;
    overflow-y: auto;
  }
  .nav-toggle { display: grid; }
  aside nav, #logout { display: none; }
  aside.open nav { display: flex; }
  aside.open #logout { display: block; margin-top: 8px; }
  .stats { grid-template-columns: 1fr 1fr; }
  main, #view { padding: 14px 14px 32px; }
}

.aside-role {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 10px 8px;
}
aside nav button[hidden] { display: none !important; }
.check input { width: auto; margin-right: 8px; }
input::placeholder, textarea::placeholder { color: #5c6578; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; }
.form-actions .primary { margin-top: 0; }
.ghost.danger:hover { border-color: var(--danger); color: var(--danger); }
.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.view-head .sub { margin-bottom: 0; }
.view-head .primary { margin-top: 0; flex: 0 0 auto; }
body.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
}
.modal-overlay[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 20%, rgba(201, 162, 39, 0.08), transparent 58%),
    rgba(4, 7, 14, 0.5);
  backdrop-filter: blur(5px) saturate(0.8);
  -webkit-backdrop-filter: blur(5px) saturate(0.8);
}
.modal {
  position: relative;
  z-index: 1;
  isolation: isolate;
  transform: translateZ(0);
  width: min(560px, 100%);
  max-height: min(88vh, 840px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(180deg, rgba(201, 162, 39, 0.07), transparent 88px),
    #121b2b;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(201, 162, 39, 0.08),
    0 28px 64px rgba(0, 0, 0, 0.48),
    0 0 72px rgba(201, 162, 39, 0.08);
  animation: modal-in 0.2s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateZ(0) translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateZ(0); }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, #121b2b 70%, rgba(18, 27, 43, 0));
  z-index: 1;
}
.modal-head::after {
  content: "";
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 0;
  height: 1px;
  background: var(--line);
}
.modal-head h3 {
  margin: 0;
  color: var(--gold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 13px;
  font-weight: 500;
}
.modal-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(10, 18, 32, 0.7);
  color: var(--gold);
  font-size: 22px;
  line-height: 1;
  flex: 0 0 auto;
  padding: 0;
}
.modal-close:hover,
.modal-close:focus-visible {
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.12);
  outline: none;
}
.modal-body { padding: 8px 20px 20px; }
.modal-body form.stack {
  max-width: none;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  margin: 0;
  box-shadow: none;
}
.modal-body .form-actions {
  position: sticky;
  bottom: 0;
  margin: 16px -4px 0;
  padding: 14px 4px 2px;
  background: linear-gradient(to top, #121b2b 72%, rgba(18, 27, 43, 0));
}
.tag-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a1220;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  align-items: center;
}
.tag-box:focus-within { border-color: var(--gold); }
.tag-list { display: contents; }
.tag-input {
  flex: 1 1 140px;
  min-width: 120px;
  border: 0 !important;
  background: transparent !important;
  padding: 6px 4px !important;
  width: auto;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(201, 162, 39, 0.12);
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--gold);
  padding: 4px 10px;
  font-size: 12px;
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.chip button {
  border: 0;
  background: none;
  color: inherit;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  width: 16px;
  height: 16px;
}
.chip.muted { color: var(--muted); border-style: dashed; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.branch-card h3 { margin-bottom: 4px; color: var(--gold); font-size: 15px; letter-spacing: 0.06em; text-transform: uppercase; }
.qr-url {
  font-size: 13px;
  color: var(--gold);
  word-break: break-all;
  margin-bottom: 14px;
}
.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 180px) minmax(0, 1fr) 48px;
  gap: 10px;
  align-items: center;
}
.bar-row span { display: block; font-size: 13px; color: var(--ink); overflow-wrap: anywhere; }
.bar { height: 8px; background: rgba(201, 162, 39, 0.14); }
.bar > i { display: block; height: 100%; background: var(--gold); }
.bar-row b { color: var(--gold); font-size: 14px; text-align: right; font-variant-numeric: tabular-nums; }
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--gold);
  color: var(--night);
  padding: 12px 16px;
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  z-index: 90;
  transition: opacity 0.2s;
  max-width: min(360px, calc(100% - 32px));
}
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 700px) {
  .source-split, .stats, .grid2 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr 48px; }
  .bar-row .bar { grid-column: 1 / -1; }
  .loc-card { flex-direction: column; }
  table, thead, tbody, th, td, tr { display: block; width: 100%; }
  table { min-width: 0; }
  thead { display: none; }
  tr {
    border: 1px solid var(--line);
    background: var(--panel);
    margin-bottom: 12px;
    padding: 12px 14px;
  }
  th, td { border: 0; padding: 6px 0; }
}
@media (min-width: 1200px) {
  .modal-overlay { padding: 36px 28px; }
  .modal { width: min(600px, 100%); }
}

@media (max-width: 768px) {
  .modal-overlay { padding: 16px 14px; }
  .modal { width: min(520px, 100%); max-height: min(90vh, 820px); }
  .view-head { flex-direction: column; }
  .view-head .primary { width: 100%; }
  .grid2, .source-split { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .card { padding: 24px 18px; }
  form.stack { padding: 14px; }
  input, textarea, select { font-size: 16px; }
  .view-head { flex-direction: column; }
  .view-head .primary { width: 100%; }
  .modal-overlay { padding: 10px; align-items: center; justify-content: center; }
  .modal {
    width: 100%;
    max-height: calc(100dvh - 20px);
    min-height: 0;
    border-radius: 14px;
  }
  .modal-head,
  .modal-body { padding-left: 16px; padding-right: 16px; }
  .modal-head::after { left: 16px; right: 16px; }
  .disc-row { grid-template-columns: auto 1fr; }
  .disc-off { grid-column: 2; justify-self: start; }
}
