:root {
  color-scheme: light;
  --bg: #f7faf9;
  --surface: #ffffff;
  --surface-soft: #eef4f3;
  --ink: #0f172a;
  --text: #1f2937;
  --muted: #64748b;
  --line: #d7e0df;
  --line-strong: #aab8b7;
  --primary: #1d4ed8;
  --primary-strong: #1e40af;
  --primary-soft: #dbeafe;
  --selected: #e0f2fe;
  --pending: #fde68a;
  --pending-ink: #7c4a03;
  --confirmed: #bbf7d0;
  --confirmed-ink: #14532d;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --unavailable: #e5e7eb;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.1);
  --radius: 8px;
  --radius-sm: 6px;
  --max: 1220px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

body {
  min-height: 100dvh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(219, 234, 254, 0.7), rgba(247, 250, 249, 0) 300px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  outline-offset: 3px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(29, 78, 216, 0.38);
  outline-offset: 3px;
}

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  transform: translateY(-140%);
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  text-decoration: none;
  transition: transform 180ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid rgba(215, 224, 223, 0.85);
  background: rgba(247, 250, 249, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  color: var(--ink);
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  gap: 6px;
}

.nav-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--muted);
  padding: 0 12px;
  text-decoration: none;
  transition:
    background 180ms ease,
    color 180ms ease;
}

.nav-link:hover,
.nav-link[aria-current="page"] {
  background: var(--surface);
  color: var(--ink);
}

#app {
  width: min(100%, var(--max));
  margin: 0 auto;
  padding: clamp(20px, 4vw, 48px) clamp(16px, 4vw, 40px) 56px;
}

.entry-panel,
.calendar-panel,
.side-panel,
.admin-panel,
.action-panel,
.admin-section {
  min-width: 0;
}

.entry-panel,
.calendar-panel,
.admin-panel,
.action-panel,
.admin-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.entry-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 24px;
  align-items: end;
  padding: clamp(22px, 4vw, 36px);
}

.customer-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 20px;
  align-items: start;
}

.calendar-panel,
.admin-panel {
  padding: clamp(18px, 3vw, 28px);
}

.side-panel {
  display: grid;
  gap: 14px;
}

.action-panel,
.admin-section {
  padding: 18px;
}

.page-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page-title {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.06;
  letter-spacing: 0;
}

.section-title {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
  line-height: 1.2;
}

.lede {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.subtle {
  color: var(--muted);
}

.phone-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
}

.field input,
.field select,
.search {
  min-height: 46px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.field input:hover,
.field select:hover,
.search:hover {
  border-color: var(--line-strong);
}

.field small {
  color: var(--muted);
  font-size: 13px;
}

[aria-invalid="true"] {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12);
}

.phone-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 8px 10px;
  white-space: nowrap;
}

.text-button {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 750;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.legend i {
  width: 12px;
  height: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.legend-open {
  background: #fff;
}

.legend-selected {
  background: var(--selected);
}

.legend-pending {
  background: var(--pending);
}

.legend-confirmed {
  background: var(--confirmed);
}

.legend-unavailable {
  background: var(--unavailable);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
  gap: 10px;
}

.calendar-day {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}

.day-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 10px;
}

.day-header strong {
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.day-header span {
  color: var(--muted);
  font-size: 12px;
}

.day-slots {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.calendar-slot,
.button,
.filter-button {
  min-height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.calendar-slot {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  text-align: left;
}

.calendar-slot strong {
  color: var(--ink);
  font-size: 15px;
}

.calendar-slot span {
  color: var(--muted);
  font-size: 12px;
}

.calendar-slot:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.calendar-slot.is-selected {
  border-color: var(--primary);
  background: var(--selected);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.slot-pending {
  border-color: #f59e0b;
  background: var(--pending);
  color: var(--pending-ink);
}

.slot-pending strong,
.slot-pending span {
  color: var(--pending-ink);
}

.slot-confirmed {
  border-color: #22c55e;
  background: var(--confirmed);
  color: var(--confirmed-ink);
}

.slot-confirmed strong,
.slot-confirmed span {
  color: var(--confirmed-ink);
}

.slot-unavailable {
  background: var(--unavailable);
}

.calendar-slot[disabled] {
  cursor: not-allowed;
  transform: none;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  gap: 8px;
  padding: 10px 16px;
  text-decoration: none;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: var(--primary);
  color: #fff;
}

.button-primary:hover {
  background: var(--primary-strong);
}

.button-secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button-secondary:hover {
  border-color: var(--line-strong);
}

.button-danger {
  border-color: rgba(185, 28, 28, 0.25);
  background: var(--danger-soft);
  color: var(--danger);
}

.button-danger:hover {
  border-color: rgba(185, 28, 28, 0.45);
}

.button[disabled] {
  cursor: not-allowed;
  opacity: 0.46;
  transform: none;
}

.full-width {
  width: 100%;
}

.detail-list {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.detail-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.detail-row span {
  color: var(--muted);
}

.detail-row strong {
  color: var(--ink);
  text-align: right;
}

.notice,
.error-summary {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.notice {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
}

.error-summary {
  border: 1px solid rgba(185, 28, 28, 0.25);
  background: var(--danger-soft);
  color: var(--danger);
}

.booking-list,
.blocked-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.booking-list.compact {
  gap: 8px;
}

.booking-item,
.blocked-item {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px;
}

.booking-item.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}

.booking-item-header,
.blocked-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.booking-title {
  display: grid;
  gap: 2px;
}

.booking-title strong {
  color: var(--ink);
}

.booking-title span {
  color: var(--muted);
  font-size: 13px;
}

.booking-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
}

.status-pending,
.status-cancel_requested {
  background: var(--pending);
  color: var(--pending-ink);
}

.status-confirmed {
  background: var(--confirmed);
  color: var(--confirmed-ink);
}

.status-cancelled {
  background: var(--danger-soft);
  color: var(--danger);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.stat {
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
}

.admin-section {
  margin-top: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.block-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.5fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  font-weight: 750;
}

.filter-button:hover,
.filter-button[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.search {
  width: min(100%, 300px);
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  padding: 22px;
  text-align: center;
}

.compact-empty {
  margin-top: 10px;
  padding: 14px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.toast[hidden] {
  display: none;
}

@media (max-width: 980px) {
  .entry-panel,
  .customer-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .block-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .block-form .button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .nav-link {
    padding: 0 8px;
  }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .page-title {
    font-size: 34px;
  }

  .calendar-grid,
  .side-panel,
  .admin-grid,
  .block-form {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
