:root {
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --page-bg: #eaf3ff;
  --card: #ffffff;
  --text: #172033;
  --muted: #6b7280;
  --border: #d9e4f2;
  --danger: #b42318;
  --success: #087443;
  --shadow: 0 12px 34px rgba(35, 74, 120, .10);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--page-bg); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--page-bg);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.spacer { flex: 1; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 24px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}
.brand-wrap { display: flex; align-items: center; gap: 12px; }
.logo-mark {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--primary), #7aa8ff);
  font-weight: 800;
  font-size: 23px;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 28%, transparent);
}
h1, h2, h3, p { margin-top: 0; }
.brand-wrap h1 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.brand-wrap p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.app-shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: calc(100vh - 79px); }
.sidebar {
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  background: rgba(255,255,255,.62);
}
.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: #44516a;
  text-align: left;
  padding: 13px 14px;
  border-radius: 13px;
  margin-bottom: 6px;
  font-weight: 700;
}
.nav-item:hover { background: rgba(255,255,255,.75); }
.nav-item.active { background: white; color: var(--primary); box-shadow: 0 5px 18px rgba(35, 74, 120, .08); }

.main-content { min-width: 0; padding: 24px; }
.section { display: none; }
.section.active { display: block; }
.card {
  background: var(--card);
  border: 1px solid rgba(217,228,242,.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 750;
  min-height: 42px;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(29, 59, 98, .09); }
.btn.primary { color: white; background: var(--primary); border-color: var(--primary); }
.btn.secondary { background: #f7faff; }
.btn.danger { color: var(--danger); background: #fff5f4; border-color: #f3cbc7; }
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: white;
  font-size: 27px;
  line-height: 1;
}

.calendar-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.date-nav { display: flex; align-items: center; gap: 14px; }
.date-nav h2 { margin: 0; font-size: 20px; }
.date-nav p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.view-switcher { display: inline-flex; padding: 4px; border-radius: 13px; background: #edf3fb; }
.view-btn { border: 0; background: transparent; border-radius: 10px; padding: 9px 15px; font-weight: 750; color: #65728a; }
.view-btn.active { background: white; color: var(--primary); box-shadow: 0 4px 12px rgba(35, 74, 120, .10); }

.calendar { min-height: 620px; overflow: hidden; }
.day-view { display: grid; grid-template-columns: 76px minmax(0,1fr); }
.week-view { overflow-x: auto; }
.week-grid { display: grid; min-width: 960px; grid-template-columns: 70px repeat(7, minmax(125px,1fr)); }
.time-column, .day-column { position: relative; }
.day-column { border-left: 1px solid var(--border); }
.calendar-day-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: white;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
}
.calendar-day-header span { color: var(--muted); font-size: 12px; font-weight: 650; }
.calendar-day-header.today { color: var(--primary); background: color-mix(in srgb, var(--primary) 5%, white); }
.time-label {
  height: var(--slot-height, 38px);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 0 10px;
  transform: translateY(-7px);
  color: #8290a8;
  font-size: 12px;
}
.time-spacer { height: 64px; border-bottom: 1px solid var(--border); }
.slot {
  height: var(--slot-height, 38px);
  border-bottom: 1px solid #edf2f7;
  position: relative;
  background: white;
}
.slot:hover { background: #f8fbff; }
.slot.break-slot { background: repeating-linear-gradient(-45deg, #f4f7fb, #f4f7fb 7px, #eef3f8 7px, #eef3f8 14px); }
.slot.closed-slot { background: #f5f5f5; }
.slot.drop-target { background: color-mix(in srgb, var(--primary) 12%, white); outline: 2px dashed var(--primary); outline-offset: -3px; }

.appointment-card {
  position: absolute;
  left: 5px;
  right: 5px;
  border: 1px solid rgba(27, 51, 84, .13);
  border-left: 5px solid var(--label-color, var(--primary));
  border-radius: 11px;
  padding: 7px 8px;
  background: var(--appointment-bg, white);
  box-shadow: 0 4px 13px rgba(36, 62, 96, .12);
  overflow: hidden;
  z-index: 5;
  cursor: grab;
  min-height: 28px;
}
.appointment-card:active { cursor: grabbing; }
.appointment-card.cancelled { opacity: .56; text-decoration: line-through; }
.appointment-card.noshow { box-shadow: inset 0 0 0 2px #e5484d; }
.appointment-card .appt-head { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; }
.appointment-card strong { line-height: 1.15; }
.appointment-card .appt-time { white-space: nowrap; color: #56647b; font-size: 11px; }
.appointment-card .appt-services { margin-top: 3px; color: #3d4b62; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appointment-card .appt-footer { display: flex; justify-content: space-between; gap: 6px; margin-top: 5px; font-size: 11px; font-weight: 800; }
.payment-badge { padding: 2px 6px; border-radius: 999px; background: rgba(255,255,255,.76); }
.note-dot { color: var(--primary); }
.empty-calendar { display: grid; place-items: center; min-height: 500px; color: var(--muted); text-align: center; padding: 30px; }

.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); }
.month-weekday { padding: 12px; text-align: center; color: var(--muted); font-size: 12px; font-weight: 800; border-bottom: 1px solid var(--border); }
.month-cell {
  min-height: 122px;
  padding: 9px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: white;
}
.month-cell:nth-child(7n) { border-right: 0; }
.month-cell.other-month { background: #f7f9fc; color: #9ba7ba; }
.month-cell.today { background: color-mix(in srgb, var(--primary) 5%, white); }
.month-date { font-weight: 850; margin-bottom: 6px; }
.month-appt {
  padding: 5px 7px;
  border-radius: 8px;
  background: var(--appointment-bg, white);
  border-left: 4px solid var(--label-color, var(--primary));
  box-shadow: 0 2px 8px rgba(40, 65, 98, .09);
  font-size: 11px;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.month-more { font-size: 11px; color: var(--primary); font-weight: 800; }

.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.section-head h2 { margin-bottom: 5px; }
.section-head p { color: var(--muted); margin-bottom: 0; }
.filter-bar { padding: 14px; margin-bottom: 18px; }
.filter-bar input { width: 100%; }
.grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr)); gap: 14px; }
.list-card { padding: 17px; cursor: pointer; }
.list-card:hover { transform: translateY(-1px); box-shadow: 0 14px 36px rgba(35, 74, 120, .14); }
.list-card h3 { margin-bottom: 5px; }
.list-card p { margin-bottom: 7px; color: var(--muted); }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; background: #eff5fd; color: #50617c; font-size: 12px; font-weight: 800; }
.service-color { width: 13px; height: 13px; border-radius: 50%; display: inline-block; margin-right: 7px; vertical-align: -2px; border: 1px solid rgba(0,0,0,.1); }
.empty-state { padding: 35px; text-align: center; color: var(--muted); }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(300px,1fr)); gap: 16px; }
.settings-card { padding: 20px; }
.settings-card h3 { margin-bottom: 16px; }
.hours-row { display: grid; grid-template-columns: 82px 1fr 1fr 36px; align-items: center; gap: 8px; margin-bottom: 9px; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack-actions { display: grid; gap: 10px; }
.file-btn { display: flex; align-items: center; justify-content: center; }

label { display: grid; gap: 7px; font-weight: 750; color: #37445a; font-size: 13px; margin-bottom: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 11px;
  padding: 11px 12px;
  min-height: 42px;
  outline: none;
}
input[type="color"] { padding: 4px; height: 44px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent); }
textarea { resize: vertical; }

.modal {
  width: min(640px, calc(100vw - 24px));
  border: 0;
  border-radius: 20px;
  padding: 0;
  color: var(--text);
  box-shadow: 0 30px 90px rgba(15, 35, 65, .28);
}
.large-modal { width: min(900px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(16, 31, 52, .48); backdrop-filter: blur(4px); }
.modal form, .modal > div, .modal > .modal-head, .modal > .modal-actions { margin: 0; }
.modal form, #recapDialog { padding: 22px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px !important; }
.modal-head h2 { margin-bottom: 5px; }
.modal-head p { margin-bottom: 0; color: var(--muted); }
.close-btn { border: 0; background: #f0f4f9; width: 38px; height: 38px; border-radius: 12px; font-size: 24px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 14px; }
.inline-field { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.field-block { padding: 14px; border: 1px solid var(--border); border-radius: 14px; margin: 4px 0 16px; background: #f9fbfe; }
.field-title-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.field-title-row h3 { margin-bottom: 10px; }
.service-picker { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; max-height: 290px; overflow: auto; }
.service-option {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: white;
  cursor: pointer;
}
.service-option input { width: auto; min-height: 0; margin-top: 2px; }
.service-option span { display: block; }
.service-option small { color: var(--muted); display: block; margin-top: 2px; }
.modal-actions { display: flex; align-items: center; gap: 9px; margin-top: 20px !important; }
.split-actions { justify-content: space-between; }
.split-actions > div { display: flex; gap: 9px; }

.recap-kpis { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin-bottom: 18px; }
.kpi { border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: #f9fbfe; }
.kpi span { display: block; color: var(--muted); font-size: 12px; font-weight: 750; }
.kpi strong { display: block; margin-top: 5px; font-size: 22px; }
.recap-table-wrap { overflow-x: auto; }
.recap-table { width: 100%; border-collapse: collapse; }
.recap-table th, .recap-table td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.recap-table th { color: var(--muted); font-size: 12px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  padding: 12px 16px;
  border-radius: 12px;
  color: white;
  background: #172033;
  box-shadow: 0 15px 35px rgba(0,0,0,.2);
  transform: translateY(30px);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; }
  .top-actions .secondary { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 79px;
    z-index: 20;
    display: flex;
    overflow-x: auto;
    gap: 5px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(15px);
  }
  .nav-item { white-space: nowrap; width: auto; margin: 0; padding: 10px 12px; }
  .main-content { padding: 14px; }
  .calendar-toolbar { align-items: stretch; flex-direction: column; }
  .view-switcher { align-self: stretch; }
  .view-btn { flex: 1; }
  .recap-kpis { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 620px) {
  .topbar { padding: 12px; }
  .brand-wrap p { display: none; }
  .logo-mark { width: 40px; height: 40px; border-radius: 13px; }
  .top-actions { flex: 1; }
  .top-actions .btn { padding: 9px 10px; font-size: 13px; }
  .top-actions #recapBtn { display: none; }
  .section-head { align-items: stretch; flex-direction: column; }
  .section-head .btn { width: 100%; }
  .form-grid, .service-picker, .two-cols { grid-template-columns: 1fr; }
  .hours-row { grid-template-columns: 70px 1fr 1fr 34px; gap: 5px; }
  .month-cell { min-height: 92px; padding: 5px; }
  .month-appt { padding: 4px; font-size: 9px; }
  .calendar { min-height: 560px; }
  .day-view { grid-template-columns: 60px minmax(0,1fr); }
  .appointment-card { left: 3px; right: 3px; }
  .modal form, #recapDialog { padding: 16px; }
  .split-actions { flex-direction: column-reverse; align-items: stretch; }
  .split-actions > div { width: 100%; }
  .split-actions .btn { flex: 1; }
}

@media print {
  body * { visibility: hidden !important; }
  #recapDialog, #recapDialog * { visibility: visible !important; }
  #recapDialog { position: static; width: 100%; box-shadow: none; }
  #recapDialog .modal-actions, #recapDialog .close-btn { display: none !important; }
}
