@import url("https://fonts.googleapis.com/css2?family=Lilita+One&family=Nunito:wght@600;700;800&display=swap");

:root {
  --sun: #f7c948;
  --fire: #ff6b35;
  --sea: #2ec4b6;
  --ink: #011627;
  --pink: #ff3366;
  --cream: #fff6e9;
  --grape: #7b2cbf;
  --muted: #4a5560;
  --line: #ead9c4;
  --paper: #fff6e9;
  --accent: #ff6b35;
  --accent-ink: #fff;
  --accent-soft: rgba(255, 107, 53, 0.14);
  --white: #fffdf8;
  --shadow: 6px 6px 0 #011627;
  --tap: 44px;
  --bar-h: 56px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { overflow-x: hidden; max-width: 100%; }
html { scroll-padding-top: 0; }
body {
  font-family: Nunito, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: 700;
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  align-items: stretch;
}
#login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 107, 53, 0.16), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(255, 107, 53, 0.08), transparent 42%),
    var(--paper);
}
#login[hidden], #app[hidden] { display: none !important; }
.card {
  background: var(--white);
  padding: 32px 28px;
  width: min(380px, 92vw);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 8px 8px 0 var(--fire);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 6px;
  background: linear-gradient(90deg, var(--fire), var(--sun), var(--pink), var(--sea));
}
.card img {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  object-fit: cover;
}
.card h1 { font-family: "Lilita One", sans-serif; font-size: 22px; font-weight: 400; margin: 12px 0 20px; }
label, .field { display: block; font-size: 12px; margin: 12px 0 6px; color: var(--muted); }
.field { margin: 0 0 14px; }
.field .lbl, .lbl-plain {
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--muted);
}
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  max-width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
input.invalid, textarea.invalid, select.invalid { border-color: #a33; }
.field-err { display: block; color: #a33; font-size: 12px; margin-top: 5px; }
.hint { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin: 2px 0 6px; }
button { font: inherit; cursor: pointer; }
.card button, .primary {
  margin-top: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  padding: 10px 16px;
  min-height: var(--tap);
  border-radius: 8px;
  font-weight: 600;
}
.card button:hover, .primary:hover { filter: brightness(0.96); }
.err { color: #a33; font-size: 13px; margin-top: 10px; min-height: 1em; }

.admin-top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--bar-h);
  padding: 8px 14px;
  background: var(--ink);
  color: #fff;
  border-bottom: 4px solid var(--fire);
  position: sticky;
  top: 0;
  z-index: 32;
  flex: 0 0 auto;
}
.admin-top img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid var(--sun);
  object-fit: cover;
}
.admin-top strong {
  font-family: "Lilita One", sans-serif;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--sun);
}
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: var(--tap);
  height: var(--tap);
  background: var(--fire);
  border: 3px solid #fff;
  border-radius: 12px;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  background: #fff;
  border-radius: 99px;
}
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(1, 22, 39, 0.45);
  z-index: 18;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 100dvh;
}
.admin-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  align-items: start;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}
aside {
  border-right: 4px solid var(--ink);
  background: var(--white);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  position: sticky;
  top: var(--bar-h);
  height: calc(100dvh - var(--bar-h));
  overflow-y: auto;
  align-self: start;
}
.aside-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.aside-brand img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--accent);
  object-fit: cover;
}
.aside-brand strong { font-family: "Lilita One", sans-serif; font-size: 15px; font-weight: 400; line-height: 1.3; }
.aside-role { display: block; font-size: 11px; color: var(--muted); font-weight: 500; margin-top: 2px; }
aside nav { display: flex; flex-direction: column; gap: 4px; }
aside nav button, #logout {
  text-align: left;
  background: none;
  border: 0;
  padding: 10px 12px;
  min-height: var(--tap);
  color: var(--muted);
  border-radius: 8px;
}
aside nav button.active, aside nav button:hover {
  background: var(--accent-soft);
  color: var(--ink);
}
aside nav button.active { color: var(--fire); font-weight: 800; }
aside nav button[hidden] { display: none !important; }
#logout { margin-top: auto; }
#logout:hover { color: var(--accent); }

main {
  padding: 16px 22px 28px;
  min-width: 0;
  align-self: start;
  width: 100%;
}
#view > :first-child { margin-top: 0; }
h2 { font-family: "Lilita One", sans-serif; font-size: 24px; font-weight: 400; margin-bottom: 8px; }
h3 { font-size: 15px; font-weight: 600; margin: 22px 0 10px; }
.sub { color: var(--muted); margin-bottom: 22px; font-size: 14px; line-height: 1.45; }

.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; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  min-width: 0;
  box-shadow: 0 1px 0 rgba(28, 28, 28, 0.03);
  position: relative;
  overflow: hidden;
}
.stat:nth-child(1)::before { background: var(--fire); }
.stat:nth-child(2)::before { background: var(--sea); }
.stat:nth-child(3)::before { background: var(--pink); }
.stat:nth-child(4)::before { background: var(--sun); }
.stat::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
}
.stat b { display: block; font-size: 22px; font-weight: 600; }
.stat span { font-size: 12px; color: var(--muted); }

.panel {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 18px 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 0 rgba(28, 28, 28, 0.03);
}
.panel h3 { margin-top: 0; }
.panel .sub { margin-bottom: 12px; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  margin-bottom: 20px;
}
table { width: 100%; min-width: 560px; border-collapse: collapse; background: #fff; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); text-align: left; padding: 12px 12px; vertical-align: top; }
th {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f7f4ef;
  font-weight: 600;
}
td b { font-weight: 600; }
td small { color: var(--muted); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions button, .ghost {
  background: none;
  border: 1px solid var(--line);
  padding: 8px 12px;
  min-height: 36px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}
.row-actions button:hover, .ghost:hover { border-color: var(--accent); color: var(--accent); }

form.stack {
  max-width: 640px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 20px 18px 18px;
  margin-bottom: 20px;
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(28, 28, 28, 0.06);
  position: relative;
  overflow: hidden;
}
form.stack::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: var(--accent);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; margin: 12px 0; color: var(--ink); font-size: 14px; }
.check input { width: auto; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.form-actions .primary { margin-top: 0; }
.form-actions .ok, .form-actions .err { margin: 0; }

.deal-list { display: flex; flex-direction: column; margin: 4px 0 12px; }
.deal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.deal-name { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--ink); font-size: 14px; }
.deal-name input { width: auto; flex: 0 0 auto; }
.deal-off {
  display: flex;
  align-items: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  flex: 0 0 auto;
}
.deal-off input {
  width: 64px;
  border: 0;
  border-radius: 0;
  text-align: center;
  padding: 8px 6px;
  background: transparent;
}
.deal-off input:focus { outline: none; }
.deal-off span {
  padding: 0 10px;
  font-size: 12px;
  color: var(--muted);
  border-left: 1px solid var(--line);
  white-space: nowrap;
}
.deal:not(:has(input[type="checkbox"]:checked)) .deal-off { opacity: 0.38; }

.branch-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 10px;
}
.branch-card p { color: var(--muted); font-size: 14px; margin: 4px 0; }
.branch-card small { color: var(--muted); }

.msg { background: #fff; border: 1px solid var(--line); padding: 16px; margin-bottom: 12px; border-radius: 14px; min-width: 0; }
.msg b { overflow-wrap: anywhere; }
.thread { font-size: 13px; color: var(--muted); white-space: pre-wrap; margin: 8px 0; overflow-wrap: anywhere; }
.qr img { width: min(240px, 100%); background: #fff; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.qr-url { font-size: 13px; color: var(--muted); margin: 10px 0; overflow-wrap: anywhere; }
.ok { color: #2a6; font-size: 13px; margin-top: 8px; }
.ok.err, p.err { color: #a33; }
.logo-preview {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin: 8px 0;
}
code { font-size: 13px; background: #fff; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); }

.bar-list { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 4px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr) auto;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}
.bar-label { overflow-wrap: anywhere; }
.bar-track { height: 8px; background: #f0ece6; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.bar-val { font-variant-numeric: tabular-nums; color: var(--muted); }

.tag-box {
  border: 1px solid var(--line);
  background: #fff;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  align-items: center;
  border-radius: 8px;
}
.tag-box:focus-within { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
.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;
  outline: none !important;
  font-size: 15px !important;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--ink);
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.2;
  border-radius: 99px;
}
.chip button {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 0;
  font-size: 14px;
  line-height: 1;
  width: 16px;
  height: 16px;
}
.chip button:hover { color: var(--accent); }
.chip.muted { color: var(--muted); border-style: dashed; background: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

body.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.modal-overlay[hidden] { display: none !important; }
.modal-shade {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(28, 28, 28, 0.36) 0%, rgba(28, 28, 28, 0.56) 72%),
    rgba(28, 28, 28, 0.52);
  backdrop-filter: blur(6px) saturate(0.72);
  -webkit-backdrop-filter: blur(6px) saturate(0.72);
}
.modal {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(92vh, 880px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border: 1px solid rgba(230, 226, 219, 0.95);
  border-radius: 20px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.65) inset,
    0 24px 64px rgba(28, 28, 28, 0.28),
    0 8px 20px rgba(255, 107, 53, 0.08);
  animation: modal-in 0.18s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 16px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
  border-bottom: 1px solid var(--line);
}
.modal-head::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 4px;
  background: var(--accent);
}
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 600; color: var(--ink); }
.modal-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 10px;
}
.modal-close:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.modal-body {
  padding: 16px 20px 22px;
  background: var(--paper);
}
.modal-body form.stack {
  max-width: none;
  background: #fff;
  border: 1px solid var(--line);
  padding: 18px 16px 14px;
  margin: 0;
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(28, 28, 28, 0.06);
  overflow: visible;
}
.modal-body form.stack::before { display: none; }
.modal-body .form-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, #fff 70%, rgba(255, 255, 255, 0));
  padding-top: 14px;
  margin-top: 4px;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 90;
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  font-size: 14px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 0.2s;
  max-width: min(360px, calc(100% - 32px));
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: #7a2e2e; }

@media (max-width: 1199px) {
  .admin-shell { grid-template-columns: 200px minmax(0, 1fr); }
  main { padding: 14px 18px 24px; }
}

@media (max-width: 768px) {
  :root { --bar-h: 52px; }
  .admin-shell { grid-template-columns: minmax(0, 1fr); }
  .admin-top { min-height: var(--bar-h); padding: 6px 12px; }
  .nav-toggle { display: inline-flex; }
  .scrim.show { display: block; }
  aside {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    height: 100dvh;
    z-index: 30;
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    overflow-y: auto;
  }
  #app.nav-open aside { transform: none; }
  .stats { grid-template-columns: 1fr 1fr; }
  main { padding: 12px 14px 28px; }
  .grid2 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; }
  .view-head { flex-direction: column; }
  .view-head .primary { width: 100%; }
  .branch-card { flex-direction: column; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 12px; }
  .stat b { font-size: 20px; }
  .card { padding: 24px 18px; }
  main { padding: 12px 12px 24px; }
  .modal-overlay {
    padding: 20px 0 0;
    align-items: end;
    place-items: end center;
  }
  .modal {
    width: 100%;
    max-height: calc(100dvh - 20px);
    min-height: calc(100dvh - 20px);
    border: 0;
    border-radius: 16px 16px 0 0;
  }
  .modal-body { padding: 14px 14px 20px; }
  .modal-body form.stack { padding: 14px 12px 12px; }
  .deal { flex-wrap: wrap; }
  table, thead, tbody, th, td, tr { display: block; width: 100%; }
  table { min-width: 0; }
  thead { display: none; }
  tr {
    border-bottom: 1px solid var(--line);
    padding: 12px 12px 10px;
  }
  tr:last-child { border-bottom: 0; }
  th, td { border: 0; padding: 4px 0; }
  .row-actions { margin-top: 8px; }
}

@media (max-width: 375px) {
  :root { --bar-h: 50px; }
  .admin-top { padding: 6px 10px; }
  .admin-top strong { font-size: 15px; }
  main { padding: 10px 12px 24px; }
}
