:root {
  --ink: #1c1a18;
  --muted: #6e6860;
  --line: #e4ddd3;
  --paper: #f4f0ea;
  --accent: #6b5a45;
  --white: #fffdf9;
  --tap: 44px;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(28, 26, 24, 0.06);
  --focus: 0 0 0 3px rgba(107, 90, 69, 0.22);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  overflow-x: clip;
  overflow-anchor: none;
}
html { scroll-padding-top: 0; }
body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-width: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}
body.modal-open { overflow: hidden; }
#login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
#login[hidden], #app[hidden], .modal[hidden] { display: none !important; }

.card {
  background: var(--white);
  padding: 36px 28px;
  width: min(400px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card img { width: 56px; height: 56px; }
.card h1 {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 24px;
  font-weight: 400;
  letter-spacing: 0.02em;
  margin: 14px 0 22px;
}

label, .field { display: block; font-size: 12px; margin: 12px 0 6px; color: var(--muted); letter-spacing: 0.02em; }
.field { margin: 0 0 16px; }
.field .lbl, .lbl-plain {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 7px;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.lbl-plain { margin-top: 10px; }
input, textarea, select {
  width: 100%;
  max-width: 100%;
  min-height: var(--tap);
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea { min-height: 0; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}
input.invalid, textarea.invalid, select.invalid { border-color: #a33; box-shadow: 0 0 0 3px rgba(163, 51, 51, 0.12); }
.field-err { display: block; color: #a33; font-size: 12px; margin-top: 5px; }
.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  color: var(--ink);
  font-size: 14px;
}
.check input { width: auto; min-height: 20px; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.form-actions .ok, .form-actions .err { margin: 0; width: 100%; }
.logo-preview {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  margin: 8px 0 4px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-head > div { min-width: 0; flex: 1; }
.page-head .sub { margin-bottom: 0; }
.page-head .primary { margin-top: 0; flex: 0 0 auto; }

.card-list { display: flex; flex-direction: column; gap: 12px; }
.item-card, .branch-card, .panel, .msg {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(28, 26, 24, 0.04);
}
.item-card, .branch-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 16px 18px;
}
.item-card h4, .branch-card b {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
}
.item-card p, .branch-card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin: 6px 0 8px;
}
.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 13px;
  color: var(--muted);
}
.item-price {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.chip, .tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #efe8de;
  color: var(--ink);
  border: 0;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.3;
}
.chip.muted { color: var(--muted); background: #f3eee6; }
.item-card .row-actions { flex: 0 0 auto; }

.tag-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: text;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.tag-box:focus-within {
  border-color: var(--accent);
  box-shadow: var(--focus);
}
.tag-chip { cursor: default; }
.tag-x {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tag-x:hover { background: rgba(28, 26, 24, 0.08); color: var(--ink); }
.tag-type {
  flex: 1 1 120px;
  min-width: 120px;
  min-height: 32px;
  border: 0 !important;
  box-shadow: none !important;
  padding: 6px 4px;
  background: transparent;
  font-size: 16px;
}

.input-suffix {
  position: relative;
  display: block;
}
.input-suffix input {
  padding-right: 40px;
}
.input-suffix .suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.deal-list {
  margin: 4px 0 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
.deal-head, .deal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 12px;
  align-items: center;
}
.deal-head {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  margin: 0;
  background: #f7f3ed;
}
.deal-row {
  padding: 10px 14px;
  margin: 0;
  border-bottom: 1px solid var(--line);
}
.deal-row:last-of-type { border-bottom: 0; }
.deal-row.is-off { opacity: 0.42; }
.deal-name { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 14px; color: var(--ink); }
.deal-name input { width: auto; flex: 0 0 auto; min-height: 20px; }
.deal-discount input { text-align: right; padding-right: 36px; min-height: 40px; }
.deal-discount input:disabled { background: #f7f3ed; color: var(--muted); }

.panel { padding: 20px 20px 18px; margin-bottom: 16px; }
.panel h3 { margin-top: 0; }
.panel .sub { margin-bottom: 14px; }
.panel form.stack {
  max-width: none;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  box-shadow: none;
}
.qr-url { font-size: 13px; color: var(--muted); margin: 10px 0; overflow-wrap: anywhere; }
.bar-list { display: flex; flex-direction: column; gap: 12px; margin: 4px 0 0; }
.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: #efe8de;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill { height: 100%; background: var(--accent); border-radius: inherit; }
.bar-val { font-variant-numeric: tabular-nums; color: var(--muted); }
.dash-table { border: 0; box-shadow: none; margin: 0; }
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 80;
  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;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: #7a2e2e; }
aside nav button[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
.primary {
  margin-top: 16px;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 10px;
  min-height: var(--tap);
  padding: 10px 18px;
  transition: background 0.15s ease, transform 0.15s ease;
}
.primary:hover { background: #2c2824; }
.primary:disabled { opacity: 0.6; cursor: wait; }
button:focus-visible, .ghost:focus-visible, a.ghost:focus-visible, .icon-btn:focus-visible, .primary:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}
.err { color: #a33; font-size: 13px; margin-top: 10px; min-height: 1em; }

#app {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-areas: "nav main";
  grid-template-rows: auto;
  align-items: start;
  align-content: start;
  justify-items: stretch;
  width: 100%;
  min-height: 100dvh;
  flex: 1 1 auto;
}
.nav-backdrop {
  display: none;
  grid-area: nav;
}
aside {
  grid-area: nav;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  max-height: 100dvh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--white);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.aside-head {
  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: 32px; height: 32px; flex: 0 0 auto; }
.aside-brand strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}
.aside-tag {
  display: block;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
}
#nav-toggle {
  display: none;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
}
#nav-toggle span {
  display: block;
  width: 16px;
  height: 1.5px;
  background: var(--ink);
}
aside nav { display: flex; flex-direction: column; gap: 2px; }
aside nav button, #logout {
  text-align: left;
  background: none;
  border: 0;
  border-radius: 10px;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--muted);
  scroll-margin: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
aside nav button.active, aside nav button:hover { background: var(--paper); color: var(--ink); }
#logout { margin-top: auto; border-top: 1px solid var(--line); border-radius: 0; }

main {
  grid-area: main;
  align-self: start;
  width: 100%;
  min-width: 0;
  padding: 18px clamp(16px, 2.4vw, 28px) 32px;
}
h2 {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: clamp(24px, 3vw, 30px);
  font-weight: 400;
  margin-bottom: 8px;
}
h3 {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 18px;
  font-weight: 400;
  margin: 8px 0 12px;
}
.sub { color: var(--muted); margin-bottom: 22px; font-size: 14px; line-height: 1.5; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 18px;
  min-width: 0;
  box-shadow: 0 6px 20px rgba(28, 26, 24, 0.04);
}
.stat b {
  display: block;
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: -0.02em;
}
.stat span { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
table { width: 100%; min-width: 560px; border-collapse: collapse; background: transparent; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); text-align: left; padding: 13px 14px; vertical-align: top; }
th {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f7f3ed;
  font-weight: 600;
}
td b { font-weight: 600; }
td small { color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.row-actions button, .ghost {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 36px;
  padding: 8px 12px;
  color: var(--ink);
  transition: background 0.15s ease;
}
.row-actions button:hover, .ghost:hover { background: #efe8de; }
form.stack {
  max-width: 640px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 18px 22px;
  margin-bottom: 20px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.msg { padding: 18px; margin-bottom: 12px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.msg b { overflow-wrap: anywhere; }
.msg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.msg-meta { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
.msg-status {
  flex: 0 0 auto;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  background: #efe8de;
  padding: 4px 10px;
  color: var(--muted);
}
.thread { margin: 0; display: flex; flex-direction: column; gap: 8px; white-space: normal; color: inherit; }
.bubble {
  background: var(--paper);
  border-radius: 12px;
  padding: 10px 12px;
}
.bubble.out { background: #fff; border: 1px solid var(--line); }
.bubble .who {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.bubble p { font-size: 14px; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.reply-form { margin: 0; padding-top: 4px; border-top: 1px solid var(--line); }
.reply-form .primary { margin-top: 0; }
.reply-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.qr img { width: min(240px, 100%); background: #fff; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.ok { color: #2a6; font-size: 13px; margin-top: 8px; }
.empty {
  background: var(--white);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 18px;
  color: var(--muted);
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 13, 10, 0.52);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(90dvh, 840px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--white);
  border: 1px solid rgba(255, 253, 249, 0.16);
  border-radius: 20px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.45) inset,
    0 28px 70px rgba(10, 8, 6, 0.36),
    0 4px 16px rgba(10, 8, 6, 0.2);
  animation: modal-in 0.2s ease;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  margin: 0;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--white);
}
.modal-head h3 {
  font-size: 22px;
  margin: 0;
  line-height: 1.25;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.icon-btn:hover { background: #efe8de; }
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 22px 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: -20px;
  background: linear-gradient(to top, var(--white) 78%, rgba(255, 253, 249, 0));
  padding-top: 16px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
}
.modal-body .primary { margin-top: 0; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 1200px) {
  .modal { padding: 40px 28px; }
  .modal-panel { width: min(580px, 100%); }
  main { padding: 20px 32px 40px; }
}

@media (max-width: 1199px) {
  html { scroll-padding-top: 52px; }
  #app {
    display: block;
    min-height: 0;
    padding-top: 52px;
  }
  .nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(28, 26, 24, 0.32);
    z-index: 40;
  }
  #app.nav-open .nav-backdrop { display: block; }
  aside {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    height: 52px;
    max-height: 52px;
    overflow: hidden;
    padding: 6px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    align-items: center;
  }
  .aside-head { margin-bottom: 0; width: 100%; }
  #nav-toggle { display: inline-flex; }
  aside nav, #logout { display: none; }
  #app.nav-open aside {
    height: 100dvh;
    max-height: 100dvh;
    width: min(300px, 88vw);
    right: auto;
    overflow: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    box-shadow: 12px 0 40px rgba(28, 26, 24, 0.12);
  }
  #app.nav-open aside nav { display: flex; margin-top: 10px; }
  #app.nav-open #logout { display: block; }
  main { padding: 16px 16px 32px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  form.stack { max-width: none; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; }
  .item-card, .branch-card { flex-direction: column; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .primary { width: 100%; }
}

@media (max-width: 768px) {
  html { scroll-padding-top: 52px; }
  main { padding: 14px 14px 28px; }
  .modal { padding: 16px 12px; }
  .modal-panel {
    width: min(560px, 100%);
    max-height: calc(100dvh - 32px);
  }
}

@media (max-width: 375px) {
  .stats { grid-template-columns: 1fr; gap: 10px; }
  .stat { padding: 16px 14px; }
  .stat b { font-size: 24px; }
  .card { padding: 28px 20px; }
  .grid2 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  input, textarea, select, .tag-type { font-size: 16px; }
  .modal {
    padding: 8px;
    align-items: stretch;
  }
  .modal-panel {
    width: 100%;
    max-height: calc(100dvh - 16px);
    height: calc(100dvh - 16px);
    border-radius: 14px;
  }
  .modal-head { padding: 16px 16px 12px; }
  .modal-body { padding: 14px 16px 16px; }
  .deal-head, .deal-row { grid-template-columns: 1fr; }
  .deal-discount { max-width: 160px; }
}
