:root {
  --bg: #120d0b;
  --card: #1f1713;
  --card-2: #2a1d17;
  --text: #fff7ed;
  --muted: #c7aa92;
  --line: #4a3328;
  --accent: #f97316;
  --accent-2: #fb923c;
  --danger: #ef4444;
  --danger-strong: #ff2d2d;
  --ok: #22c55e;
  --warn: #facc15;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #3b1d0d 0, var(--bg) 35%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #1b100a;
  font-weight: 800;
  padding: 12px 16px;
  cursor: pointer;
  min-height: 46px;
  touch-action: manipulation;
}

button:hover { background: var(--accent-2); }
button.secondary { background: #3b2a21; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--danger); color: white; }
button.accent { box-shadow: 0 10px 24px rgb(249 115 22 / 24%); }
button.primary-action {
  min-height: 58px;
  padding: 16px 24px;
  border-radius: 18px;
  font-size: 1.08rem;
  letter-spacing: 0.01em;
  background: linear-gradient(135deg, #fb923c, #f97316 55%, #ea580c);
  box-shadow: 0 16px 34px rgb(249 115 22 / 34%);
}
button.small-action {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0.82;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #140f0c;
  color: var(--text);
  padding: 12px;
  min-height: 46px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 14px 10px;
  text-align: left;
}

th { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; }
tr.slot-row { cursor: pointer; }
tr.slot-row:hover { background: #2a1d17; }
tr.selected { outline: 2px solid var(--accent); background: #2a1d17; }
tr.slot-surplus {
  background: linear-gradient(90deg, rgb(127 29 29 / 72%), rgb(69 10 10 / 58%));
  box-shadow: inset 5px 0 0 var(--danger-strong);
}
tr.slot-surplus:hover { background: linear-gradient(90deg, rgb(153 27 27 / 82%), rgb(69 10 10 / 70%)); }
tr.slot-full {
  background: linear-gradient(90deg, rgb(113 63 18 / 46%), rgb(42 29 17 / 42%));
  box-shadow: inset 5px 0 0 var(--warn);
}

.hidden { display: none !important; }
.login-card { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card .card { max-width: 440px; width: 100%; }
.app { padding: 24px; max-width: 1440px; margin: 0 auto; }
.card {
  background: linear-gradient(180deg, rgb(31 23 19 / 96%), rgb(22 16 13 / 96%));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 18px 50px rgb(0 0 0 / 28%);
}

.topbar, .card-head, .toolbar, .user-box, .actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar, .card-head { justify-content: space-between; }
.topbar { margin-bottom: 20px; }
.toolbar { margin-bottom: 20px; flex-wrap: wrap; }
.toolbar label { min-width: 210px; }
.toolbar .date-control { flex: 1 1 210px; }
.toolbar .capacity-control { flex: 0 1 190px; }
.toolbar .primary-action { margin-left: auto; }
.grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr); gap: 20px; }
.bottom-grid { margin-top: 20px; align-items: start; }
.stack { display: grid; gap: 14px; }
.table-wrap { overflow-x: auto; }
.eyebrow {
  color: var(--accent-2);
  margin: 0 0 6px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

h1, h2 { margin: 0; }
h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); }
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); margin: 6px 0 0; }
.error { color: #fecaca; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 12px;
  background: #332016;
  color: #fed7aa;
  font-weight: 800;
}

.slot-time {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  font-size: 1.02rem;
}
.metric {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 38px;
  border-radius: 14px;
  font-size: 1.08rem;
  font-weight: 950;
}
.metric-booked {
  background: #332016;
  color: #fed7aa;
}
.metric-ok {
  background: rgb(22 101 52 / 42%);
  color: #86efac;
  border: 1px solid rgb(34 197 94 / 35%);
}
.metric-full {
  background: rgb(113 63 18 / 58%);
  color: #fde68a;
  border: 1px solid rgb(250 204 21 / 42%);
}
.metric-surplus {
  background: var(--danger-strong);
  color: #fff;
  border: 1px solid #fecaca;
  box-shadow: 0 0 0 3px rgb(239 68 68 / 18%);
}
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 950;
  white-space: nowrap;
}
.status-ok { background: rgb(22 101 52 / 42%); color: #86efac; }
.status-full { background: rgb(113 63 18 / 60%); color: #fde68a; }
.status-surplus {
  background: var(--danger-strong);
  color: #fff;
  box-shadow: 0 0 22px rgb(255 45 45 / 35%);
}
.booking-list, .compact-list { display: grid; gap: 12px; }
.booking-card, .compact-row {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card-2);
  padding: 14px;
}

.booking-card {
  display: grid;
  gap: 8px;
}

.booking-card header, .compact-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.booking-card strong { font-size: 1.05rem; }
.empty { color: var(--muted); padding: 14px; }

dialog {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
  color: var(--text);
  width: min(780px, calc(100vw - 24px));
  padding: 0;
}

dialog::backdrop { background: rgb(0 0 0 / 68%); }
.modal-form { padding: 22px; display: grid; gap: 16px; }
.form-grid, .inline-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.inline-form { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 16px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); }
.check input { width: auto; }
.warning {
  border: 1px solid #f59e0b;
  border-radius: 16px;
  background: #3b2607;
  color: #fde68a;
  padding: 14px;
  line-height: 1.4;
}
.modal-actions { display: flex; justify-content: space-between; gap: 12px; }
.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  background: #3b2a21;
  color: var(--text);
}
.surplus-dialog {
  width: min(520px, calc(100vw - 26px));
  border: 2px solid var(--danger-strong);
  box-shadow: 0 26px 80px rgb(0 0 0 / 62%), 0 0 48px rgb(255 45 45 / 24%);
}
.surplus-dialog::backdrop {
  background: rgb(0 0 0 / 78%);
  backdrop-filter: blur(3px);
}
.surplus-popup {
  display: grid;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at top, rgb(153 27 27 / 42%), transparent 42%), var(--card);
}
.surplus-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--danger-strong);
  color: #fff;
  font-size: 2rem;
  font-weight: 950;
  box-shadow: 0 0 32px rgb(255 45 45 / 44%);
}
.surplus-summary {
  margin: 0;
  color: #fff;
  font-size: 1.08rem;
  line-height: 1.45;
}
.surplus-note {
  margin: 0;
  border-radius: 14px;
  background: rgb(69 10 10 / 62%);
  color: #fecaca;
  padding: 12px;
  line-height: 1.35;
}
.surplus-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.surplus-actions button {
  min-height: 54px;
}

@media (max-width: 900px) {
  .app { padding: 14px; }
  .grid, .bottom-grid, .form-grid, .inline-form { grid-template-columns: 1fr; }
  .topbar, .card-head { align-items: flex-start; flex-direction: column; }
  .toolbar { display: grid; }
}

@media (max-width: 640px) {
  body {
    background: linear-gradient(180deg, #2b1409 0, var(--bg) 36%);
  }

  .app {
    padding: 10px;
  }

  .card {
    border-radius: 18px;
    padding: 16px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 12px;
  }

  .user-box {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar {
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgb(31 23 19 / 98%);
    backdrop-filter: blur(10px);
  }

  .toolbar label,
  .toolbar .date-control,
  .toolbar .capacity-control {
    min-width: 0;
    width: 100%;
  }

  .toolbar .capacity-control {
    max-width: 180px;
  }

  .toolbar .small-action {
    width: fit-content;
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.78rem;
  }

  .toolbar .primary-action {
    width: 100%;
    margin-left: 0;
    min-height: 64px;
    font-size: 1.18rem;
    border-radius: 20px;
  }

  th, td {
    padding: 12px 7px;
  }

  th {
    font-size: 0.68rem;
  }

  .slot-time {
    font-size: 1.08rem;
  }

  .metric {
    min-width: 42px;
    min-height: 42px;
    font-size: 1.12rem;
  }

  .status-badge {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  tr.slot-surplus {
    box-shadow: inset 7px 0 0 var(--danger-strong), 0 0 22px rgb(255 45 45 / 24%);
  }

  .booking-card header,
  .compact-row,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .actions button {
    width: 100%;
  }

  dialog {
    width: 100vw;
    max-width: 100vw;
    min-height: 100dvh;
    border-radius: 0;
  }

  .modal-form {
    padding: 16px;
  }

  .surplus-dialog {
    width: calc(100vw - 20px);
    border-radius: 22px;
  }

  .surplus-popup {
    padding: 20px 16px;
  }

  .surplus-actions {
    grid-template-columns: 1fr;
  }
}
