:root {
  --ink: #1b2421;
  --muted: #5d6b66;
  --paper: #f3efe6;
  --card: #fffaf3;
  --line: #ddd4c6;
  --teal: #143d38;
  --teal-2: #1f6a5e;
  --clay: #e27b4a;
  --danger: #9c3b2e;
  --ok: #1f6a5e;
  --shadow: 0 18px 40px rgba(27, 36, 33, 0.08);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--paper);
  font: 16px/1.5 "Segoe UI", "Helvetica Neue", sans-serif;
  overflow-x: hidden;
}

body.menu-open { overflow: hidden; }

button, input { font: inherit; }

h1, h2, h3 { margin: 0; letter-spacing: -0.03em; }

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.mark {
  width: 1.6rem;
  height: 1.6rem;
  border: 2px solid currentColor;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px transparent, inset 0 0 0 7px var(--clay);
}

.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  background:
    radial-gradient(circle at top left, rgba(226, 123, 74, 0.18), transparent 26rem),
    var(--paper);
}

.login-card, .panel, dialog {
  width: min(100%, 28rem);
  padding: 1.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 1.2rem 0 0.35rem; }

.lede, .shop-note, .blank p, .hint { color: var(--muted); }

label {
  display: block;
  margin-top: 0.9rem;
  font-size: 0.92rem;
  font-weight: 600;
}

input {
  width: 100%;
  max-width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.8rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  font-size: 16px;
}

input:focus {
  outline: 2px solid rgba(31, 106, 94, 0.35);
  border-color: var(--teal-2);
}

.btn {
  border: 0;
  border-radius: 0.7rem;
  padding: 0.65rem 0.9rem;
  min-height: 2.75rem;
  cursor: pointer;
}

.btn.solid {
  margin-top: 1rem;
  width: 100%;
  color: #fffaf3;
  background: var(--teal);
}

.btn.solid:hover { background: var(--teal-2); }

.btn.ghost {
  color: var(--teal);
  background: transparent;
  border: 1px solid var(--line);
}

.btn.small {
  width: auto;
  margin-top: 0;
  padding: 0.45rem 0.7rem;
}

.btn.danger { color: var(--danger); }

.form-error, .form-ok {
  min-height: 1.2rem;
  margin: 0.7rem 0 0;
  font-size: 0.92rem;
}

.form-error { color: var(--danger); }
.form-ok { color: var(--ok); }

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
}

.side {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding: 1.2rem 0.9rem;
  color: #f3efe6;
  background: var(--teal);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
}

.side .mark { color: #f3efe6; }

.nav { display: grid; gap: 0.35rem; }

.nav-group { display: grid; gap: 0.15rem; }

.nav-label {
  padding: 0.55rem 0.8rem 0.1rem;
  font-weight: 700;
}

.nav button {
  text-align: left;
  color: #f3efe6;
  background: transparent;
  border: 0;
  border-radius: 0.7rem;
  padding: 0.75rem 0.8rem;
  min-height: 2.75rem;
  cursor: pointer;
}

.nav button.active, .nav button:hover { background: rgba(255, 250, 243, 0.12); }

.nav .nav-group button { padding-left: 1.55rem; }

.shop-note {
  margin-top: auto;
  color: rgba(243, 239, 230, 0.78);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.main { min-width: 0; }

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.6rem 0.8rem;
  padding:
    max(0.75rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    0.75rem
    max(1rem, env(safe-area-inset-left));
  background: rgba(243, 239, 230, 0.94);
  border-bottom: 1px solid var(--line);
}

.bar-title {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  gap: 0.45rem;
  min-width: 0;
}

.admin-star {
  margin-left: 0.28rem;
  color: #1f9d4a;
  font-size: 1.088em;
  line-height: 1;
}

.reload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  color: var(--teal);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.reload-btn svg { width: 1.15rem; height: 1.15rem; }

.reload-btn:hover { background: #fff; border-color: var(--teal-2); }

.bar h2 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.bar-user {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-left: auto;
  min-width: 0;
  font-weight: 700;
}

#who {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-user .btn {
  width: auto;
  margin-top: 0;
  font-weight: 700;
  white-space: nowrap;
}

.menu-btn { display: none; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 4;
  border: 0;
  padding: 0;
  background: rgba(27, 36, 33, 0.45);
}

.content { padding: 0.65rem 1.2rem 1.2rem; }

.blank {
  min-height: 16rem;
  display: grid;
  place-items: center;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 1rem;
}

.panel { width: 100%; margin-bottom: 1rem; }

.panel h3 { margin-bottom: 0.2rem; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.user-list { display: grid; gap: 0.8rem; margin-top: 0.8rem; }

.user-card {
  padding: 0.9rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
}

select {
  width: 100%;
  margin-top: 0;
  padding: 0.7rem 0.8rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  font-size: 16px;
}

.mono { font-family: Consolas, "Courier New", monospace; }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  padding: 0.5rem 0.45rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

td input { margin-top: 0; min-width: 8rem; }

.table-actions {
  display: flex;
  gap: 0.35rem;
}

.table-actions .btn { white-space: nowrap; }

.machine-next { margin-top: 1rem; }

.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr));
  gap: 0.6rem;
}

.machine {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0.3rem 0.45rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
}

.machine-photo {
  position: relative;
  width: 4.2rem;
}

.machine-photo > img {
  width: 100%;
  height: auto;
  display: block;
}

.machine.busy .machine-photo > img:not(.machine-warn) { opacity: 0.55; }

.machine-photo > .machine-warn {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 125%;
  height: auto;
  transform: translate(-50%, -50%);
  opacity: 1;
  z-index: 1;
  pointer-events: none;
}

.machine strong {
  color: var(--ink);
  font-size: 0.92rem;
}

.machine span {
  min-width: 3.4rem;
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
  color: #fff;
  background: var(--ok);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}

.machine.busy span { background: var(--danger); }

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 1rem;
}

.choice-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.choice-row input { width: auto; margin-top: 0; }

.screen-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

.screen-actions .btn,
.screen-actions .btn.solid { width: 100%; margin-top: 0.4rem; }

.price-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.7rem 0.8rem;
}

.price-grid label { margin-top: 0; }

.price-save { max-width: 16rem; margin-top: 0.8rem; }

.setup-next {
  margin-top: 1.2rem;
  padding-top: 0.2rem;
  border-top: 1px solid var(--line);
}

.bg-field { margin-top: 0.9rem; }

.zone-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.zone-card {
  padding: 0.9rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
}

.zone-card h3 { margin: 0; }

.zone-card label { margin-top: 0.55rem; }

.zone-card input { max-width: 8rem; }

.zone-card textarea.account-list { min-height: 14rem; margin-top: 0.75rem; }

.zone-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.zone-actions .btn,
.zone-actions .btn.solid { width: 100%; margin-top: 0; }

.loyalty-rates {
  display: flex;
  justify-content: space-evenly;
  align-items: flex-end;
}

.loyalty-rates label {
  margin-top: 0;
  text-align: center;
  flex: 0 0 auto;
}

.rate-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 0.35rem;
  font-weight: 700;
}

.rate-line input { width: 8rem; margin-top: 0; }

.rate-line input.short { width: 4.5rem; }

.account-count { margin: 1rem 0 0.25rem; font-weight: 700; }

textarea.account-list {
  width: 100%;
  min-height: 16rem;
  margin-top: 0.35rem;
  padding: 0.7rem 0.8rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  font: 16px ui-monospace, Consolas, monospace;
  resize: vertical;
}

.period {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 0.35rem;
}

.period label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
}

.period input { width: auto; margin: 0; }

.chart-frame {
  display: grid;
  grid-template-columns: 3.1rem minmax(0, 1fr);
  column-gap: 0.35rem;
  padding: 0.45rem 0.6rem 0.4rem 0.3rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
}

.chart-scale {
  position: relative;
  height: 180px;
  margin-top: 0.7rem;
}

.chart-scale span {
  position: absolute;
  right: 0;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
  transform: translateY(50%);
}

.chart-body { position: relative; min-width: 0; }

.chart-grid {
  position: absolute;
  left: 0;
  right: 0;
  top: 0.7rem;
  height: 180px;
  pointer-events: none;
}

.chart-grid i {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed #d5d0c4;
}

.chart-grid i.top { border-top: 1.5px solid var(--ink); }

.chart {
  display: flex;
  align-items: flex-start;
  gap: 0.2rem;
  height: auto;
  overflow-x: auto;
  padding: 0.7rem 0 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.chart-col {
  flex: 1 0 1.55rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: auto;
  min-width: 1.55rem;
}

.chart-slot {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 180px;
  border-bottom: 1.5px solid var(--ink);
}

.chart-fill {
  width: 68%;
  background: var(--teal);
  border-radius: 0.22rem 0.22rem 0 0;
}

.chart-col span {
  margin-top: 0.22rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.1;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}

.detail-head h3 { margin: 0; }

.page-size { margin: 0; }

.page-size select {
  width: auto;
  min-width: 6.5rem;
  margin: 0;
  padding: 0.4rem 0.65rem;
  font-weight: 700;
}

.pager {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.pager:empty { display: none; }

.pager button {
  min-width: 2.1rem;
  padding: 0.35rem 0.55rem;
  color: var(--teal);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  font-weight: 700;
  cursor: pointer;
}

.pager button[aria-current="page"] {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.pager span {
  min-width: 1.2rem;
  color: var(--muted);
  font-weight: 700;
  line-height: 2rem;
  text-align: center;
}

.user-head {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
}

.role {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.7rem 0; }

.chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  gap: 0.35rem;
  padding: 0.2rem 0.45rem 0.2rem 0.6rem;
  background: var(--paper);
  border-radius: 999px;
  overflow-wrap: anywhere;
}

.chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.add-shop, .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-top: 0.55rem;
}

.add-shop select { flex: 1; width: auto; min-width: 8rem; }

.assign-label {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
}

.row-actions { margin-top: 0.7rem; }

dialog {
  border: 1px solid var(--line);
  width: min(100vw - 1.5rem, 26rem);
  max-height: calc(100dvh - 1.5rem);
  margin: auto;
  overflow: auto;
}

dialog::backdrop { background: rgba(27, 36, 33, 0.35); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.dialog-actions .btn.solid { width: auto; margin-top: 0; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed;
    z-index: 5;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(18rem, 86vw);
    height: auto;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    padding-top: max(1.2rem, env(safe-area-inset-top));
    padding-bottom: max(1.2rem, env(safe-area-inset-bottom));
  }
  .side.open { transform: none; }
  .bar { flex-wrap: nowrap; }
  .bar-user {
    display: flex;
    flex-wrap: nowrap;
    flex: 0 1 auto;
    width: auto;
    margin-left: auto;
  }
  #who {
    max-width: 7rem;
    text-align: right;
  }
  .bar-user .btn {
    width: auto;
    padding: 0.4rem 0.55rem;
  }
  .menu-btn {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0.4rem 0.75rem;
    color: var(--teal);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 0.7rem;
    cursor: pointer;
  }
  .content {
    padding:
      0.55rem
      max(1rem, env(safe-area-inset-right))
      max(1.2rem, env(safe-area-inset-bottom))
      max(1rem, env(safe-area-inset-left));
  }
  .grid { grid-template-columns: 1fr; }
  .price-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .screen-actions { grid-template-columns: 1fr; }
  .zone-row { grid-template-columns: 1fr; }
  .loyalty-rates {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-items: center;
  }
  .loyalty-rates label { min-width: 0; max-width: 100%; }
  .add-shop,
  .row-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .add-shop select { width: 100%; }
  .add-shop .btn,
  .row-actions .btn { width: 100%; }
  .user-head { align-items: flex-start; }
  .blank { min-height: 12rem; padding: 1rem; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn,
  .dialog-actions .btn.solid { width: 100%; }
}
