/* Riso Facial — Design System tokens & base components.
   Canonical source: DESIGN_SYSTEM.md / design-system.html.
   Rule: only the palette below. No blue, no green, no teal. Positive = wine,
   negative = #b00020. Off-palette color is a design bug. */

:root {
  --wine: #781828;
  --wine-deep: #580015;
  --gold: #C8A848;
  --bg: #F8F0F0;
  --surface: #fff;
  --ink: #231919;
  --muted: #897172;
  --faint: #bfaaaa;
  --wine-tint: #F8E3E3;
  --gold-tint: #FBF1D9;
  --row-alt: #FBF7F7;
  --hairline: #f0e6e6;
  --cool-line: rgba(128, 136, 152, .18);
  --positive: #781828;
  --negative: #b00020;
  --gold-text: #7a5b00;
  --radius: 24px;
  --shadow: 0 4px 32px -10px rgba(120, 24, 40, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Manrope', system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--wine); text-decoration: none; }
a:hover { text-decoration: underline; }

.serif { font-family: 'Newsreader', Georgia, serif; }

/* Signature label: uppercase, letter-spaced, muted. */
.label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted { color: var(--muted); }
.tabular { font-variant-numeric: tabular-nums; }

/* --- Card --- */
.card {
  background: var(--surface);
  border: 1px solid var(--cool-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card.p-6 { padding: 24px; }
.card.p-7 { padding: 28px; }
.card--gold { border-top: 4px solid var(--gold); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 9999px;
  border: 1px solid transparent;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-primary { background: var(--wine); color: #fff; }
.btn-primary:hover { background: var(--wine-deep); text-decoration: none; }
.btn-secondary { background: transparent; color: var(--wine); border-color: var(--cool-line); }
.btn-secondary:hover { background: rgba(120, 24, 40, .06); text-decoration: none; }
.btn-danger { background: var(--negative); color: #fff; }
.btn-danger:hover { filter: brightness(.92); text-decoration: none; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Form fields --- */
.form-group { margin-bottom: 18px; }
.form-group > label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.field {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--cool-line);
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
}
.field:focus {
  outline: none;
  border-color: var(--wine);
  box-shadow: 0 0 0 3px var(--wine-tint);
}

/* --- Messages / alerts (semantic, palette-safe) --- */
.alert { padding: 12px 16px; border-radius: 12px; font-size: 13px; margin-bottom: 14px; }
.alert-success { background: var(--wine-tint); color: var(--wine); }
.alert-error { background: #f7dcdf; color: var(--negative); }
.alert-warning { background: var(--gold-tint); color: var(--gold-text); }

.form-errors { color: var(--negative); font-size: 13px; margin-bottom: 14px; }

/* --- Auth screens (login / select clinic): centered card, no shell --- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 400px; padding: 40px 36px; }
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-brand .logo { font-size: 30px; font-weight: 600; color: var(--wine); }
.auth-brand .sub { margin-top: 4px; }

/* --- App shell: fixed header + sidebar + content --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--cool-line);
}
.app-header .brand { font-family: 'Newsreader', serif; font-size: 22px; font-weight: 600; color: var(--wine); }
.header-right { display: flex; align-items: center; gap: 16px; }

.clinic-select {
  padding: 8px 14px;
  border: 1px solid var(--cool-line);
  border-radius: 9999px;
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--wine);
  cursor: pointer;
}
.user-name { font-size: 13px; color: var(--muted); }

.app-shell { display: flex; align-items: flex-start; max-width: 1480px; margin: 0 auto; }
.sidebar { width: 232px; flex: 0 0 232px; padding: 24px 16px; }
.content { flex: 1; min-width: 0; padding: 28px 32px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.nav-link:hover { background: rgba(120, 24, 40, .06); color: var(--wine); text-decoration: none; }
.nav-link.active { background: var(--wine); color: #fff; }
.nav-link .material-symbols-outlined { font-size: 20px; }

.page-title { font-family: 'Newsreader', serif; font-size: 28px; font-weight: 500; margin: 0 0 4px; }
.page-eyebrow { margin-bottom: 20px; }

/* Pills / badges */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.pill-wine { background: var(--wine-tint); color: var(--wine); }
.pill-gold { background: var(--gold-tint); color: var(--gold-text); }

.app-footer {
  max-width: 1480px;
  margin: 0 auto;
  padding: 16px 32px 32px;
  color: var(--faint);
  font-size: 11px;
}

/* --- Header left group + sidebar toggle --- */
.header-left { display: flex; align-items: center; gap: 12px; }
.nav-toggle {
  background: none; border: 1px solid var(--cool-line); border-radius: 10px;
  width: 38px; height: 38px; display: inline-flex; align-items: center;
  justify-content: center; cursor: pointer; color: var(--wine);
}
.nav-toggle:hover { background: rgba(120, 24, 40, .06); }

/* --- Collapsed sidebar (icon rail); collapsed by default --- */
html.nav-collapsed .sidebar { width: 64px; flex-basis: 64px; padding: 24px 8px; }
html.nav-collapsed .nav-label { display: none; }
html.nav-collapsed .nav-link { justify-content: center; padding: 10px; gap: 0; }
html.nav-collapsed .nav-link .pill { display: none; }

/* --- Page head: title + primary actions --- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 10px; flex-wrap: nowrap; overflow-x: auto; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(35, 25, 25, .5);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 60; padding: 40px 20px; overflow: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 20px 60px -20px rgba(120, 24, 40, .35);
  width: 100%; max-width: 520px; padding: 28px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head .page-title { font-size: 22px; margin: 0; }
.modal-close { background: none; border: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-close:hover { color: var(--wine); }

/* --- Toolbar / search --- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.toolbar .field { width: auto; min-width: 260px; }
/* Keep every filter on a single line (scrolls horizontally if narrow). */
.toolbar--inline { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
.toolbar--inline .field { min-width: 0; flex-shrink: 0; }
.toolbar--inline > label, .toolbar--inline > button, .toolbar--inline > .field { flex-shrink: 0; white-space: nowrap; }

/* --- Dense table (.xls) --- */
.xls-wrap { border-radius: 16px; border: 1px solid var(--hairline); overflow: auto; background: var(--surface); }
table.xls { width: 100%; border-collapse: collapse; font-size: 13px; }
.xls th {
  background: var(--wine); color: #fff; font-size: 11px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; text-align: left;
  padding: 11px 14px; position: sticky; top: 0; white-space: nowrap;
}
.xls td { padding: 10px 14px; border-bottom: 1px solid var(--hairline); }
.xls tr:nth-child(even) td { background: var(--row-alt); }
.xls tr:last-child td { border-bottom: none; }
.xls .num { text-align: right; font-variant-numeric: tabular-nums; }
.xls .row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.xls .row-actions a { font-size: 12px; font-weight: 600; }
.xls .row-actions form { display: inline; }
.link-danger { color: var(--negative); background: none; border: none; padding: 0; font: inherit; font-weight: 600; cursor: pointer; }

/* --- Badges (palette-safe: no green/blue) --- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 9999px; font-size: 11px; font-weight: 700; }
.badge-neutral { background: var(--wine-tint); color: var(--wine); }
.badge-gold { background: var(--gold-tint); color: var(--gold-text); }
.badge-muted { background: #efe7e7; color: var(--muted); }
.badge-danger { background: #f7dcdf; color: var(--negative); }

/* --- Empty state --- */
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* --- Pagination --- */
.pagination { display: flex; gap: 8px; align-items: center; margin-top: 18px; font-size: 13px; }
.pagination a { padding: 6px 12px; border: 1px solid var(--cool-line); border-radius: 9999px; }

/* --- Forms --- */
.form-card { max-width: 720px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.field-check { width: auto; margin-right: 8px; }
.check-row { display: flex; align-items: center; margin-bottom: 18px; font-weight: 600; color: var(--muted); }
.help-text { font-size: 11px; color: var(--faint); margin-top: 4px; }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--negative); font-size: 12px; }
.section-title { font-family: 'Newsreader', serif; font-size: 18px; margin: 24px 0 12px; }
.formset-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 12px; align-items: end; padding: 12px 0; border-bottom: 1px dashed var(--hairline); }
.formset-row .form-group { margin-bottom: 0; }

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-basis: auto; display: flex; flex-wrap: wrap; gap: 6px; }
  .nav-link { margin-bottom: 0; }
  .form-row, .formset-row { grid-template-columns: 1fr; }
}

/* --- Form widgets: quantity stepper --- */
.stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--cool-line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  max-width: 180px;
}
.stepper:focus-within {
  border-color: var(--wine);
  box-shadow: 0 0 0 3px var(--wine-tint);
}
.stepper-btn {
  border: 0;
  background: var(--wine-tint);
  color: var(--wine);
  width: 40px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}
.stepper-btn:hover { background: var(--wine); color: #fff; }
.stepper-input.field {
  width: 80px;
  border: 0;
  border-radius: 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: none;
}
.stepper-input.field:focus { box-shadow: none; }
/* Hide the native number spinners so only our buttons remain. */
.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-input { -moz-appearance: textfield; }

/* --- Form widgets: product combobox --- */
.combobox { position: relative; }
.combobox-native { display: none; }
.combobox-list {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  margin-top: 4px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--cool-line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 4px;
}
.combobox-option {
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
}
.combobox-option:hover,
.combobox-option.active { background: var(--wine-tint); color: var(--wine); }
.combobox-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }

/* --- Form widgets: date picker --- */
.datepicker { position: relative; }
.datepicker-display.field { padding-right: 44px; }
.datepicker-icon {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 40px;
  border: 0;
  background: transparent;
  color: var(--wine);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.datepicker-icon .material-symbols-outlined { font-size: 20px; }
.datepicker-pop {
  position: absolute;
  z-index: 40;
  margin-top: 6px;
  width: 288px;
  background: var(--surface);
  border: 1px solid var(--cool-line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.dp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.dp-nav {
  border: 0; background: var(--wine-tint); color: var(--wine);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1;
}
.dp-nav:hover { background: var(--wine); color: #fff; }
.dp-select {
  flex: 1; padding: 6px 8px; border: 1px solid var(--cool-line);
  border-radius: 8px; background: var(--surface); color: var(--ink); font-family: inherit; font-size: 13px;
}
.dp-dow, .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-dow span {
  text-align: center; font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; padding-bottom: 4px;
}
.dp-cell {
  border: 0; background: transparent; color: var(--ink);
  height: 34px; border-radius: 8px; cursor: pointer;
  font-variant-numeric: tabular-nums; font-size: 13px;
}
.dp-cell:hover { background: var(--wine-tint); color: var(--wine); }
.dp-blank { background: transparent; cursor: default; }
.dp-today { box-shadow: inset 0 0 0 1px var(--wine); color: var(--wine); }
.dp-selected { background: var(--wine); color: #fff; }
.dp-selected:hover { background: var(--wine-deep); color: #fff; }
