/* ==========================================================================
   Serenity — Spa Management App
   Design tokens
   ========================================================================== */
:root {
  /* Palette — warm sage & sand, calm and clinical-clean */
  --sage:        #7C9885;
  --sage-dark:   #5C7A67;
  --sage-light:  #E4EBE4;
  --sand:        #F3EDE4;
  --cream:       #FCFAF7;
  --white:       #FFFFFF;
  --ink:         #2B2B28;
  --ink-soft:    #56534B;
  --stone:       #8A8578;
  --line:        #E6E0D4;
  --line-soft:   #EFEAE0;

  /* Status colors */
  --status-pending:    #C98A3A;
  --status-pending-bg: #FBF0DE;
  --status-confirmed:    #4E7F63;
  --status-confirmed-bg: #E3EEE6;
  --status-completed:    #4C6E8C;
  --status-completed-bg: #E4EBF1;
  --status-cancelled:    #A85C52;
  --status-cancelled-bg: #F4E5E2;

  /* Type */
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Layout */
  --sidebar-w: 240px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-soft: 0 2px 10px rgba(43, 43, 40, 0.05), 0 1px 2px rgba(43,43,40,0.04);
  --shadow-pop: 0 12px 32px rgba(43, 43, 40, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--sand);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--ink); }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

a { color: inherit; }

::selection { background: var(--sage-light); }

/* Focus visibility for accessibility */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--sage-dark);
  outline-offset: 2px;
}

/* ==========================================================================
   App shell
   ========================================================================== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--cream);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform .25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 22px 8px;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 50% 50% 50% 8px;
  background: linear-gradient(135deg, var(--sage), var(--sage-dark));
  display: flex; align-items: center; justify-content: center;
  color: white; flex-shrink: 0;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { font-family: var(--font-display); font-size: 19px; font-weight: 600; line-height: 1.1; }
.brand-sub { font-size: 11px; color: var(--stone); letter-spacing: .04em; text-transform: uppercase; }

.nav-group { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background .15s ease, color .15s ease;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--sage-light); color: var(--sage-dark); }
.nav-item.active { background: var(--sage-dark); color: white; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px 0 8px;
  font-size: 11.5px;
  color: var(--stone);
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}

/* ---------- Main column ---------- */
.main-col {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(252, 250, 247, 0.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar-title { font-size: 22px; }
.topbar-date { font-size: 13px; color: var(--stone); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.menu-toggle {
  display: none;
  background: none; border: none; cursor: pointer;
  padding: 6px; border-radius: 8px; color: var(--ink);
}
.menu-toggle svg { width: 22px; height: 22px; }

.view-root { padding: 24px 28px 60px 28px; flex: 1; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--sage-dark); color: white; }
.btn-primary:hover { background: #4d6a58; }

.btn-secondary { background: var(--white); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--sage-light); }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--sage-light); color: var(--ink); }

.btn-danger { background: var(--white); color: var(--status-cancelled); border-color: var(--status-cancelled-bg); }
.btn-danger:hover { background: var(--status-cancelled-bg); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-icon { padding: 8px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ==========================================================================
   Cards / surfaces
   ========================================================================== */
.card {
  background: var(--white);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}
.card-pad { padding: 20px; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.section-head h2 { font-size: 19px; }
.section-desc { color: var(--stone); font-size: 13px; margin-top: 3px; }

/* ==========================================================================
   Stat cards (dashboard)
   ========================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--sage);
}
.stat-label { font-size: 12px; color: var(--stone); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-family: var(--font-display); font-size: 30px; margin-top: 6px; }
.stat-sub { font-size: 12px; color: var(--stone); margin-top: 4px; }

/* ==========================================================================
   Status badges
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: capitalize;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pending   { background: var(--status-pending-bg); color: var(--status-pending); }
.badge-confirmed { background: var(--status-confirmed-bg); color: var(--status-confirmed); }
.badge-completed { background: var(--status-completed-bg); color: var(--status-completed); }
.badge-cancelled { background: var(--status-cancelled-bg); color: var(--status-cancelled); }

/* ==========================================================================
   Forms
   ========================================================================== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.form-field .hint { font-size: 11.5px; color: var(--stone); }

input[type="text"], input[type="tel"], input[type="date"], input[type="time"],
input[type="number"], input[type="search"], select, textarea {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s ease, background .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--sage);
  background: var(--white);
}
textarea { resize: vertical; min-height: 64px; }

.field-error { border-color: var(--status-cancelled) !important; }
.error-text { color: var(--status-cancelled); font-size: 11.5px; }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; padding: 12px 14px; background: var(--sage-light);
  color: var(--sage-dark); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  position: sticky; top: 0;
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--sage-light); }
.data-table tbody tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cell-strong { font-weight: 600; }
.cell-muted { color: var(--stone); }

.empty-state {
  text-align: center; padding: 48px 20px; color: var(--stone);
}
.empty-state svg { width: 40px; height: 40px; color: var(--sage); margin-bottom: 10px; }
.empty-state h3 { color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.empty-state p { font-size: 13px; margin: 0; }

/* ==========================================================================
   Toolbar / filters
   ========================================================================== */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-box { position: relative; flex: 1; min-width: 180px; max-width: 320px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--stone); }
.search-box input { padding-left: 34px; }
.pill-select { min-width: 140px; }

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(43,43,40,.42);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-pop);
  animation: popIn .18s cubic-bezier(.2,.9,.3,1.2);
}
.modal.modal-sm { max-width: 420px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px 12px 22px; position: sticky; top: 0; background: var(--white);
  border-bottom: 1px solid var(--line-soft); z-index: 1;
}
.modal-head h3 { font-size: 18px; }
.modal-close { background: none; border: none; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--stone); }
.modal-close:hover { background: var(--sage-light); color: var(--ink); }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 14px 22px 20px 22px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line-soft); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ==========================================================================
   Calendar
   ========================================================================== */
.cal-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
}
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-range-label { font-size: 15px; font-weight: 600; min-width: 190px; text-align: center; font-family: var(--font-display); }
.view-toggle { display: flex; background: var(--sage-light); border-radius: 9px; padding: 3px; gap: 2px; }
.view-toggle button {
  border: none; background: transparent; padding: 7px 14px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--sage-dark); cursor: pointer;
}
.view-toggle button.active { background: var(--white); box-shadow: var(--shadow-soft); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; font-size: 12px; color: var(--stone); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }

.cal-grid-wrap {
  background: var(--white);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  overflow: auto;
  max-height: 74vh;
}

/* Day view: time column + staff columns */
.day-grid {
  display: grid;
  min-width: 640px;
  position: relative;
}
.day-grid-head {
  display: grid;
  position: sticky; top: 0; z-index: 5;
  background: var(--cream);
  border-bottom: 1px solid var(--line);
}
.day-grid-head .col-head, .time-col-head {
  padding: 10px 8px; text-align: center; font-size: 12.5px; font-weight: 700; color: var(--ink-soft);
  border-left: 1px solid var(--line-soft);
}
.time-col-head { border-left: none; }

.day-grid-body { display: grid; }
.time-col {
  display: grid;
}
.time-slot-label {
  font-size: 11px; color: var(--stone); padding: 2px 8px; text-align: right;
  border-top: 1px solid var(--line-soft); position: relative; top: -6px;
}
.staff-col { position: relative; border-left: 1px solid var(--line-soft); }
.slot-cell {
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background .1s ease;
}
.slot-cell:hover { background: var(--sage-light); }
.slot-cell.hour-mark { border-top: 1px solid var(--line); }

.now-line {
  position: absolute; left: 0; right: 0; height: 2px; background: var(--status-cancelled);
  z-index: 4; pointer-events: none;
}
.now-line::before {
  content: ""; position: absolute; left: -4px; top: -4px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--status-cancelled);
}

.booking-block {
  position: absolute; left: 4px; right: 4px;
  border-radius: 8px; padding: 6px 8px; overflow: hidden;
  cursor: pointer; border-left: 4px solid; z-index: 3;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  font-size: 12px; line-height: 1.3;
}
.booking-block strong { display: block; font-size: 12.5px; }
.booking-block span { color: var(--ink-soft); font-size: 11px; }
.booking-block.b-pending   { background: var(--status-pending-bg);   border-color: var(--status-pending); }
.booking-block.b-confirmed { background: var(--status-confirmed-bg); border-color: var(--status-confirmed); }
.booking-block.b-completed { background: var(--status-completed-bg); border-color: var(--status-completed); }
.booking-block.b-cancelled { background: var(--status-cancelled-bg); border-color: var(--status-cancelled); opacity: .7; }

/* Week view: 7 day agenda columns */
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(150px, 1fr));
  min-width: 900px;
}
.week-day-col { border-left: 1px solid var(--line-soft); display: flex; flex-direction: column; }
.week-day-col:first-child { border-left: none; }
.week-day-head {
  position: sticky; top: 0; background: var(--cream); z-index: 5;
  padding: 10px 8px; text-align: center; border-bottom: 1px solid var(--line);
}
.week-day-head .wd-name { font-size: 11px; color: var(--stone); text-transform: uppercase; letter-spacing: .04em; }
.week-day-head .wd-num { font-family: var(--font-display); font-size: 18px; }
.week-day-head.is-today .wd-num {
  color: var(--white); background: var(--sage-dark); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px;
}
.week-day-body { padding: 8px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 240px; cursor: pointer; }
.week-booking-chip {
  border-radius: 7px; padding: 6px 8px; font-size: 11.5px; border-left: 3px solid; cursor: pointer;
}
.week-booking-chip strong { display: block; font-size: 12px; }
.week-booking-chip.b-pending   { background: var(--status-pending-bg);   border-color: var(--status-pending); }
.week-booking-chip.b-confirmed { background: var(--status-confirmed-bg); border-color: var(--status-confirmed); }
.week-booking-chip.b-completed { background: var(--status-completed-bg); border-color: var(--status-completed); }
.week-booking-chip.b-cancelled { background: var(--status-cancelled-bg); border-color: var(--status-cancelled); opacity: .7; }
.week-day-empty-hint { font-size: 11px; color: var(--stone); text-align: center; margin-top: 10px; opacity: 0; transition: opacity .15s ease; }
.week-day-body:hover .week-day-empty-hint { opacity: 1; }

/* ==========================================================================
   Misc utility
   ========================================================================== */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.mt-8 { margin-top: 8px; }
.text-muted { color: var(--stone); }
.text-sm { font-size: 12.5px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.status-select-inline {
  border: none; background: transparent; font-weight: 700; font-size: 11.5px;
  border-radius: 999px; padding: 3px 8px; cursor: pointer;
}

/* Toasts */
.toast-stack {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--ink); color: var(--white); padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; box-shadow: var(--shadow-pop); display: flex; align-items: center; gap: 10px;
  animation: popIn .18s ease;
}
.toast svg { width: 16px; height: 16px; color: var(--sage); flex-shrink: 0; }

/* Client history */
.client-card { display: flex; align-items: center; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.client-card:hover { background: var(--sage-light); }
.client-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--sage-light); color: var(--sage-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; font-family: var(--font-display);
}
.client-info { flex: 1; min-width: 0; }
.client-name { font-weight: 600; font-size: 14px; }
.client-meta { font-size: 12px; color: var(--stone); }
.client-visits { font-size: 12px; color: var(--sage-dark); font-weight: 700; white-space: nowrap; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-pop); }
  .sidebar.open { transform: translateX(0); }
  .main-col { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 39;
  }
  .sidebar-backdrop.show { display: block; }
}

@media (max-width: 640px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 14px 16px; }
  .view-root { padding: 16px 16px 50px 16px; }
  .cal-range-label { min-width: 0; font-size: 13px; }
  .topbar-title { font-size: 18px; }
}
