/* ---------- Theme (from wings.gurbs.net) ---------- */

:root {
  --bg: #161412;
  --surface: #211e1b;
  --surface-2: #2b2723;
  --line: #3a352f;
  --text: #f4efe6;
  --muted: #b5ab9c;
  --accent: #fbc93d; /* yellow used for text */
  --brand: #fbc93d; /* yellow used as a fill */
  --on-brand: #1f1a14;
  --topbar-bg: rgb(22 20 18 / 0.88);
  --bar: #c08a10; /* chart bars, checked for contrast on this surface */
  --danger: #ff6b5b;
  --ok: #6ee7a0;
  --request-bg: color-mix(in srgb, var(--brand) 13%, var(--surface));
  --radius: 14px;
  --display: "Bebas Neue", Impact, "Arial Narrow", sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #faf6ef;
  --surface: #ffffff;
  --surface-2: #f3ede3;
  --line: #e4dccf;
  --text: #1f1a14;
  --muted: #6b6152;
  --accent: #865800;
  --topbar-bg: rgb(250 246 239 / 0.9);
  --bar: #865800;
  --danger: #b91c1c;
  --ok: #166534;
  --request-bg: color-mix(in srgb, var(--brand) 22%, var(--surface));
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3 {
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1;
  margin: 0;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.88rem;
}

.num {
  font-variant-numeric: tabular-nums;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Form controls ---------- */

input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  min-width: 0;
}

select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  min-width: 0;
}

.span-all {
  grid-column: 1 / -1;
  max-width: 20rem;
}

input::placeholder {
  color: var(--muted);
}

input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.92rem;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.65em 1.4em;
  border: 1px solid transparent;
  border-radius: 999px;
  font: 700 1rem/1.2 var(--body);
  color: inherit;
  background: none;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, transform 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
}

.btn-primary:hover:not(:disabled) {
  background: #ffd659;
}

.btn-ghost {
  border-color: var(--line);
  background: var(--surface);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
  color: var(--danger);
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.btn-sm {
  padding: 0.45em 1em;
  font-size: 0.88rem;
}

.btn-lg {
  padding: 0.85em 2em;
  font-size: 1.1rem;
}

/* ---------- Top bar & tabs ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem clamp(1rem, 4vw, 2.5rem);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--display);
  font-size: 1.5rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.topbar-links {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.role-chip {
  padding: 0.2em 0.75em;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.theme-toggle .icon-moon,
:root[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs a {
  flex: none;
  padding: 0.45em 1.15em;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  color: inherit;
}

.tabs a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tabs a[aria-current="page"] {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

/* ---------- Layout ---------- */

.view {
  max-width: 780px;
  margin: 0 auto;
  padding: 1rem clamp(1rem, 4vw, 2rem) 6rem;
}

.view.wide {
  max-width: 1000px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin: 0.75rem 0 1.25rem;
}

.page-head h1 {
  font-size: clamp(2.5rem, 7vw, 3.5rem);
  color: var(--accent);
}

.page-head p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 3vw, 1.5rem);
  margin-bottom: 1.25rem;
}

.card h2 {
  font-size: 1.9rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
}

/* ---------- Login ---------- */

.login {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 140px);
}

.login-card {
  width: min(100%, 380px);
  text-align: center;
  padding: 2.25rem 1.75rem;
}

.login-card img {
  width: 120px;
  height: auto;
  margin: 0 auto 1rem;
}

.login-card h1 {
  font-size: 3rem;
  color: var(--accent);
}

.login-card form {
  display: grid;
  gap: 0.9rem;
  margin-top: 1.25rem;
}

.code-input {
  text-align: center;
  font-size: 1.75rem;
  letter-spacing: 0.4em;
  padding: 0.6rem;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.92rem;
}

.form-ok {
  margin: 0;
  color: var(--ok);
  font-weight: 600;
  font-size: 0.92rem;
}

/* ---------- Add / request forms ---------- */

.add-form {
  display: grid;
  grid-template-columns: 1fr 9rem auto;
  gap: 0.6rem;
}

.request-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

.form-label {
  margin: 0 0 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Item list ---------- */

.list {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem clamp(0.75rem, 3vw, 1.25rem);
  border-top: 1px dashed var(--line);
}

.list > li:first-child {
  border-top: 0;
}

.suggest-btn {
  padding: 0.1em 0.6em;
  border: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 999px;
  background: none;
  color: var(--accent);
  font: 600 0.78rem var(--body);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.suggest-btn:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* Purchased already matches the suggestion */
.suggest-btn.used {
  border-style: solid;
  color: var(--muted);
  border-color: var(--line);
}

.next-in {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}

.suggest-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin: 0 0 0.75rem;
  padding: 0 0.25rem;
}

.suggest-bar p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.group-head {
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.group-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.85rem clamp(0.75rem, 3vw, 1.25rem);
  border: 0;
  background: none;
  color: var(--muted);
  font: 700 0.78rem var(--body);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
}

.group-btn:hover {
  color: var(--text);
}

.group-btn .chev {
  flex: none;
  color: var(--accent);
  transition: transform 0.15s;
}

.group-btn[aria-expanded="true"] .chev {
  transform: rotate(90deg);
}

.group-count {
  color: var(--accent);
}

.group-btn .chip {
  margin-left: auto;
  letter-spacing: 0.06em;
}

.row.requested {
  background: var(--request-bg);
  box-shadow: inset 4px 0 0 var(--brand);
}

.row-name {
  flex: 1;
  min-width: 0;
}

.name-text {
  font-weight: 600;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.name-btn {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.name-btn:hover .name-text {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.row.is-hidden .name-text {
  color: var(--muted);
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.6rem;
  margin-top: 0.1rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.row-price {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chip {
  display: inline-block;
  padding: 0.1em 0.6em;
  border-radius: 999px;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: 0.15em;
  margin-left: 0.4em;
}

/* The eye button: can employees see this item? */
.vis-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
  cursor: pointer;
}

.vis-toggle[aria-pressed="false"] {
  background: transparent;
  color: var(--muted);
  border-style: dashed;
}

.vis-toggle:hover {
  border-color: var(--accent);
}

.vis-toggle .eye-off,
.vis-toggle[aria-pressed="false"] .eye-on {
  display: none;
}

.vis-toggle[aria-pressed="false"] .eye-off {
  display: block;
}

.counter {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.step {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s, transform 0.1s;
}

.step:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.step:active {
  transform: scale(0.92);
}

.step.plus {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

.step.plus:hover {
  background: #ffd659;
  color: var(--on-brand);
}

.count {
  width: 3.75rem;
  padding: 0.45rem 0.25rem;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.count.zero {
  color: var(--muted);
  font-weight: 500;
}

/* Inline edit panel (manager taps an item name) */
.row-edit {
  padding: 0.25rem clamp(0.75rem, 3vw, 1.25rem) 1rem;
  background: var(--surface-2);
}

.row-edit form {
  display: grid;
  grid-template-columns: 1fr 9rem 7rem;
  gap: 0.75rem;
  padding-top: 0.75rem;
}

.edit-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.edit-actions .spacer {
  flex: 1;
}

/* Sticky bar with the trip total and Finish trip */
.trip-bar {
  position: sticky;
  bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.75rem 0.75rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.25);
}

.trip-bar .label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.trip-bar strong {
  display: block;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Dialog ---------- */

.dialog {
  width: min(calc(100% - 2rem), 520px);
  max-height: calc(100vh - 2rem);
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) * 1.25);
  background: var(--surface);
  color: var(--text);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.55);
}

.dialog h2 {
  font-size: 2.2rem;
  color: var(--accent);
}

.dialog p {
  margin: 0.4rem 0 0;
}

.trip-lines {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
}

.trip-lines li {
  border-top: 1px dashed var(--line);
}

.trip-lines li:first-child {
  border-top: 0;
}

.trip-lines label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  font-weight: 500;
  cursor: pointer;
}

.trip-lines input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--brand);
}

.trip-lines .line-name {
  flex: 1;
}

.trip-lines .line-sum {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-align: right;
}

.trip-total {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.trip-total strong {
  font-size: 1.3rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th,
td {
  padding: 0.55rem 0.5rem;
  text-align: left;
  border-top: 1px dashed var(--line);
}

thead th {
  border-top: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

td.n,
th.n {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.pos {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- History ---------- */

.week-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.week-nav .label {
  min-width: 11rem;
  text-align: center;
  font-weight: 600;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.trip {
  border-top: 1px dashed var(--line);
}

.trip:first-of-type {
  border-top: 0;
}

.trip summary {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}

.trip summary::-webkit-details-marker {
  display: none;
}

.trip summary::before {
  content: "+";
  width: 1rem;
  color: var(--accent);
}

.trip[open] summary::before {
  content: "−";
}

.trip summary .when {
  flex: 1;
}

.trip summary .amt {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.trip table {
  margin: 0 0 0.9rem;
}

.log-toggle summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
}

/* ---------- Statistics ---------- */

.seg {
  display: inline-flex;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.seg button {
  padding: 0.35em 0.9em;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 600 0.88rem var(--body);
  cursor: pointer;
}

.seg button[aria-pressed="true"] {
  background: var(--brand);
  color: var(--on-brand);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.tile {
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tile .k {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.tile .v {
  margin-top: 0.25rem;
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tile .s {
  font-size: 0.82rem;
  color: var(--muted);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.card-head h2 {
  margin: 0;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: 600 0.88rem var(--body);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chart {
  position: relative;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart .grid line {
  stroke: var(--line);
  stroke-width: 1;
}

.chart .axis text {
  fill: var(--muted);
  font: 11px var(--body);
  font-variant-numeric: tabular-nums;
}

.chart .bar {
  fill: var(--bar);
}

.chart .hit {
  fill: transparent;
}

.chart .hover-band {
  fill: transparent;
  pointer-events: none;
}

.chart .hover-band.on {
  fill: color-mix(in srgb, var(--text) 7%, transparent);
}

.tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  font-size: 0.85rem;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
}

.tooltip strong {
  display: block;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Settings ---------- */

.settings-form {
  display: grid;
  gap: 1rem;
  max-width: 420px;
}

.settings-form .hint {
  margin: -0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 50;
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.3);
}

/* ---------- Phones ---------- */

@media (max-width: 600px) {
  .brand {
    font-size: 1.25rem;
  }

  .brand img {
    width: 34px;
    height: auto;
  }

  .role-chip {
    display: none;
  }

  .tabs {
    gap: 0.35rem;
    padding-inline: 0.75rem;
  }

  .tabs a {
    padding: 0.45em 0.8em;
    font-size: 0.86rem;
  }

  .add-form {
    grid-template-columns: 1fr 1fr;
  }

  .add-form input[name="name"] {
    grid-column: 1 / -1;
  }

  .row {
    gap: 0.5rem;
  }

  .step {
    width: 2.5rem;
    height: 2.5rem;
  }

  .count {
    width: 3.1rem;
  }

  .vis-toggle {
    width: 2.25rem;
    height: 2.25rem;
  }

  .row-edit form {
    grid-template-columns: 1fr;
  }

  .trip-bar {
    border-radius: var(--radius);
  }
}

@media (max-width: 360px) {
  .brand span {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .step {
    transition: none;
  }
}
