:root {
  color-scheme: light;
  --bg: #f6f2ee;
  --surface: #ffffff;
  --surface-soft: #f0e9e4;
  --surface-strong: #e8dfd8;
  --text: #1a1517;
  --muted: #8a7872;
  --line: #e3d9d2;
  --primary: #b84f70;
  --primary-strong: #9a3e5d;
  --primary-soft: #faeaef;
  --primary-xsoft: #fdf3f6;
  --sage: #6f927e;
  --gold: #b9812f;
  --blue: #61769f;
  --danger: #bf4545;
  --shadow-sm: 0 1px 3px rgba(25, 17, 21, 0.07), 0 1px 2px rgba(25, 17, 21, 0.04);
  --shadow: 0 4px 16px rgba(25, 17, 21, 0.10), 0 1px 4px rgba(25, 17, 21, 0.05);
  --shadow-lg: 0 20px 48px rgba(25, 17, 21, 0.14), 0 6px 14px rgba(25, 17, 21, 0.08);
  --radius: 10px;
  font-family: Inter, 'Segoe UI', ui-sans-serif, system-ui, -apple-system, sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #161214;
  --surface: #211d1f;
  --surface-soft: #2b262a;
  --surface-strong: #373138;
  --text: #f5f0f2;
  --muted: #bdb0b5;
  --line: #433840;
  --primary: #e891a9;
  --primary-strong: #ffc8d5;
  --primary-soft: #3e2130;
  --primary-xsoft: #2d1822;
  --sage: #9ebea7;
  --gold: #d9b66c;
  --blue: #aab7db;
  --danger: #ff9a9a;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.28);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35), 0 1px 4px rgba(0, 0, 0, 0.20);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.45), 0 6px 14px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

h1, h2 {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ── Auth / Login ─────────────────────────────────────────────── */

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 70% 55% at 10% 100%, rgba(184, 79, 112, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 90% 0%, rgba(111, 146, 126, 0.14) 0%, transparent 55%),
    var(--bg);
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 44px 38px 38px;
  text-align: center;
}

.login-logo {
  display: block;
  object-fit: contain;
  width: min(200px, 68%);
  height: auto;
  margin: 0 auto 8px;
  border-radius: var(--radius);
}

.login-panel h1 {
  font-family: 'Playfair Display', Georgia, serif;
  margin: 10px 0 6px;
  font-size: 1.9rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.login-panel p {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 0.93rem;
}

.login-panel form {
  display: grid;
  gap: 14px;
  text-align: left;
}

/* ── App shell ────────────────────────────────────────────────── */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 0 14px 20px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 6px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.brand-logo {
  display: block;
  object-fit: contain;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 10px;
}

.mobile-logo {
  display: block;
  object-fit: contain;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 8px;
}

.brand strong {
  display: block;
  font-size: 0.93rem;
  font-weight: 600;
  line-height: 1.3;
}

.brand span {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.mobile-bar {
  display: none;
}

.nav {
  display: grid;
  gap: 2px;
}

/* ── Button base ──────────────────────────────────────────────── */

.nav-button,
.icon-button,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.segmented button {
  min-height: 38px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.nav-button {
  justify-content: flex-start;
  padding: 10px 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 500;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.nav-button.active {
  background: var(--primary-xsoft);
  color: var(--primary-strong);
  border-left-color: var(--primary);
}

.nav-button:hover:not(.active) {
  background: var(--surface-soft);
  color: var(--text);
}

.main {
  min-width: 0;
  padding: 28px;
}

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

.view-title h1 {
  margin: 0 0 4px;
  font-size: 2rem;
  line-height: 1.1;
}

.view-title p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary-button {
  padding: 0 18px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff;
  font-weight: 600;
  font-size: 0.88rem;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 8px rgba(184, 79, 112, 0.28);
}

.primary-button:hover {
  background: linear-gradient(135deg, var(--primary-strong), #7e3350);
  box-shadow: 0 4px 14px rgba(184, 79, 112, 0.38);
}

.secondary-button {
  padding: 0 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 500;
  font-size: 0.88rem;
}

.secondary-button:hover {
  background: var(--surface-soft);
  border-color: color-mix(in srgb, var(--muted) 60%, transparent);
}

.ghost-button {
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
}

.ghost-button:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.danger-button {
  padding: 0 16px;
  background: rgba(191, 69, 69, 0.1);
  color: var(--danger);
  font-weight: 500;
  font-size: 0.88rem;
}

.danger-button:hover {
  background: rgba(191, 69, 69, 0.18);
}

.icon-button {
  width: 38px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 1.1rem;
}

.icon-button:hover {
  background: var(--surface-soft);
  border-color: color-mix(in srgb, var(--muted) 60%, transparent);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.session {
  padding: 12px 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.87rem;
}

.session strong {
  display: block;
  font-weight: 600;
}

.session span {
  color: var(--muted);
  font-size: 0.8rem;
}

/* ── Stats ────────────────────────────────────────────────────── */

.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.stat:nth-child(2) { border-top-color: var(--sage); }
.stat:nth-child(3) { border-top-color: var(--blue); }
.stat:nth-child(4) { border-top-color: var(--gold); }

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ── Toolbar ──────────────────────────────────────────────────── */

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

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.period-label {
  min-width: 220px;
  font-weight: 700;
  font-size: 1.05rem;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.segmented button {
  min-height: 30px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.segmented button.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 600;
}

/* ── Calendar ─────────────────────────────────────────────────── */

.calendar-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.calendar-head,
.week-grid {
  display: grid;
  grid-template-columns: 72px repeat(var(--days), minmax(130px, 1fr));
}

.calendar-head {
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.corner-cell,
.day-head {
  min-height: 56px;
  display: grid;
  align-content: center;
  padding: 10px 12px;
}

.day-head {
  border-left: 1px solid var(--line);
}

.day-head strong {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
}

.day-head span {
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 1px;
}

.week-grid {
  max-height: calc(100vh - 315px);
  min-height: 570px;
  overflow: auto;
}

.time-axis {
  display: grid;
  background: var(--surface-soft);
}

.time-label {
  height: 64px;
  padding: 6px 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  text-align: right;
}

.day-column {
  position: relative;
  min-height: calc(var(--hours) * 64px);
  border-left: 1px solid var(--line);
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 63px,
      var(--line) 63px,
      var(--line) 64px
    );
}

.slot-hitbox {
  position: absolute;
  left: 0;
  right: 0;
  height: 32px;
  z-index: 1;
  background: transparent;
}

.appointment {
  position: absolute;
  left: 6px;
  right: 6px;
  z-index: 2;
  border-radius: 8px;
  padding: 8px 10px;
  color: #fff;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
  cursor: grab;
}

.appointment:active {
  cursor: grabbing;
}

.appointment.blocked {
  color: var(--text);
  background: repeating-linear-gradient(135deg, var(--surface-strong), var(--surface-strong) 8px, var(--surface-soft) 8px, var(--surface-soft) 16px) !important;
  border: 1px dashed var(--muted);
  box-shadow: none;
}

.appointment strong,
.month-event strong,
.client-card strong,
.service-card strong {
  display: block;
  line-height: 1.2;
  font-weight: 600;
}

.appointment span,
.month-event span {
  display: block;
  font-size: 0.74rem;
  opacity: 0.9;
  margin-top: 3px;
}

/* ── Month calendar ───────────────────────────────────────────── */

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.month-weekday,
.month-day {
  min-height: 120px;
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px;
}

.month-weekday {
  min-height: 38px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.month-day {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--text);
  text-align: left;
  background: transparent;
}

.day-column.closed {
  background:
    repeating-linear-gradient(135deg, transparent 0, transparent 12px, color-mix(in srgb, var(--surface-strong) 55%, transparent) 12px, color-mix(in srgb, var(--surface-strong) 55%, transparent) 24px),
    repeating-linear-gradient(to bottom, transparent 0, transparent 63px, var(--line) 63px, var(--line) 64px);
}

.month-day.outside {
  background: color-mix(in srgb, var(--surface-soft) 58%, transparent);
  color: var(--muted);
}

.month-date {
  font-weight: 700;
  font-size: 0.86rem;
  align-self: flex-start;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.month-event {
  border-radius: 6px;
  padding: 5px 7px;
  color: #fff;
  font-size: 0.74rem;
  cursor: grab;
}

.month-event.blocked {
  background: var(--surface-strong) !important;
  color: var(--text);
  border: 1px dashed var(--muted);
}

/* ── Clients ──────────────────────────────────────────────────── */

.split-view {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.list-panel,
.detail-panel,
.settings-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.list-panel {
  display: grid;
  gap: 12px;
}

.search-field {
  position: relative;
}

.field,
.search-field input,
.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  min-height: 42px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  resize: vertical;
}

.field:focus,
.search-field input:focus,
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

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

.client-card,
.service-card {
  display: grid;
  gap: 6px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface);
  text-align: left;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.client-card.active,
.client-card:hover,
.service-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(184, 79, 112, 0.1);
}

.client-card span,
.service-card span,
.history-item span {
  color: var(--muted);
  font-size: 0.83rem;
}

.detail-panel {
  min-height: 360px;
}

.detail-header,
.service-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-header h2 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

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

.notes {
  margin: 16px 0;
  padding: 14px 16px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  white-space: pre-wrap;
  font-size: 0.9rem;
}

.history {
  display: grid;
  gap: 8px;
}

.history-item {
  border-left: 3px solid var(--primary);
  padding: 10px 12px;
  background: var(--surface-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
}

/* ── Services ─────────────────────────────────────────────────── */

.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 1px var(--line);
  flex: 0 0 auto;
}

.price-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.86rem;
}

.price-line strong {
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
}

/* ── Settings ─────────────────────────────────────────────────── */

.settings-grid {
  display: grid;
  gap: 16px;
  max-width: 980px;
}

.settings-panel h2 {
  margin: 0 0 16px;
  font-size: 1.2rem;
}

.hours-table {
  display: grid;
  gap: 8px;
}

.hours-row {
  display: grid;
  grid-template-columns: 120px 90px minmax(100px, 140px) minmax(100px, 140px);
  gap: 10px;
  align-items: center;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-line input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* ── Toast ────────────────────────────────────────────────────── */

.toast-wrap {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 10px;
  z-index: 50;
}

.toast {
  min-width: min(360px, calc(100vw - 40px));
  padding: 13px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 500;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

/* ── Modal ────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(22, 14, 18, 0.50);
  backdrop-filter: blur(4px);
}

.modal {
  width: min(680px, 100%);
  max-height: min(820px, calc(100vh - 40px));
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}

.modal-header,
.modal-footer {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 16px 16px 0 0;
}

.modal-footer {
  border-top: 1px solid var(--line);
}

.modal h2 {
  margin: 0;
  font-size: 1.2rem;
}

/* ── Form ─────────────────────────────────────────────────────── */

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

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── Empty / misc ─────────────────────────────────────────────── */

.empty-state {
  min-height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
  font-size: 0.9rem;
}

.drop-target {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ── Responsive ───────────────────────────────────────────────── */

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
  }

  .mobile-bar .nav {
    display: flex;
    overflow-x: auto;
    gap: 6px;
  }

  .mobile-bar .nav-button {
    white-space: nowrap;
    border-left: none;
    border-radius: var(--radius);
  }

  .main {
    padding: 18px;
  }

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

  .split-view {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topline {
    display: grid;
  }

  .actions {
    justify-content: flex-start;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }

  .period-label {
    min-width: 0;
    width: 100%;
  }

  .stat-strip {
    grid-template-columns: 1fr;
  }

  .calendar-shell {
    overflow-x: auto;
  }

  .calendar-head,
  .week-grid {
    min-width: 720px;
  }

  .week-grid {
    max-height: 640px;
  }

  .month-grid {
    min-width: 760px;
  }

  .form-row,
  .hours-row {
    grid-template-columns: 1fr;
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .modal-footer .actions {
    width: 100%;
  }
}
