/* ==========================================================
   BookFlow — shared design system
   ========================================================== */
:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-light: #eff6ff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --err: #dc2626;
  --err-bg: #fef2f2;
  --info: #0891b2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .16);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: .8125rem; }

/* ── Layout ─────────────────────────────────────────────── */
.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.container-sm { max-width: 660px; margin: 0 auto; padding: 0 20px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .875em; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 22px; }
.card-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-body { padding: 22px; }
.card-foot { padding: 14px 22px; border-top: 1px solid var(--line); background: #fafbfc; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px;
  font: inherit; font-size: .9375rem; font-weight: 600;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; border-color: var(--muted-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #1e293b; }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--ink); }
.btn-sm { padding: 6px 12px; font-size: .8125rem; }
.btn-lg { padding: 13px 26px; font-size: 1rem; }
.btn-block { width: 100%; }

/* ── Forms ──────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
label, .label {
  display: block; margin-bottom: 6px;
  font-size: .8125rem; font-weight: 600; color: var(--ink-2);
}
.label-hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=url], input[type=number], input[type=date], input[type=time],
input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; padding: 10px 12px;
  font: inherit; font-size: .9375rem; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}
input:disabled, select:disabled, textarea:disabled { background: #f8fafc; color: var(--muted); }
textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
select { appearance: none; background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; font-weight: 400; font-size: .875rem; color: var(--ink-2); }
.check input { width: 16px; height: 16px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--brand); cursor: pointer; }
.help { margin: 5px 0 0; font-size: .78125rem; color: var(--muted); line-height: 1.5; }
.required { color: var(--err); }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 12px 15px; border-radius: var(--radius-sm);
  font-size: .875rem; border: 1px solid; margin-bottom: 16px;
}
.alert-error { background: var(--err-bg); border-color: #fecaca; color: #991b1b; }
.alert-ok { background: var(--ok-bg); border-color: #bbf7d0; color: #166534; }
.alert-warn { background: var(--warn-bg); border-color: #fde68a; color: #92400e; }
.alert-info { background: var(--brand-light); border-color: #bfdbfe; color: #1e40af; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; line-height: 1.5;
  background: #f1f5f9; color: var(--ink-2); white-space: nowrap;
}
.badge-confirmed { background: var(--ok-bg); color: #166534; }
.badge-pending   { background: var(--warn-bg); color: #92400e; }
.badge-cancelled { background: var(--err-bg); color: #991b1b; }
.badge-completed { background: #f1f5f9; color: #475569; }
.badge-no_show   { background: #fdf2f8; color: #9d174d; }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th {
  text-align: left; padding: 11px 14px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: #f8fafc;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: 12px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
table.data tbody tr:hover { background: #fafbfc; }
table.data tbody tr:last-child td { border-bottom: none; }

/* ── Spinner & skeleton ─────────────────────────────────── */
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--line);
  border-top-color: var(--brand); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
.spinner-lg { width: 30px; height: 30px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px 20px; color: var(--muted); font-size: .875rem; }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 2.2rem; margin-bottom: 10px; opacity: .45; }
.empty h3 { color: var(--ink-2); margin-bottom: 4px; }

/* ── Toasts ─────────────────────────────────────────────── */
#toasts {
  position: fixed; bottom: 22px; right: 22px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px; max-width: 360px;
}
.toast {
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--ink); color: #fff; font-size: .875rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn .22s cubic-bezier(.2,.8,.3,1);
}
.toast-ok { background: #15803d; }
.toast-err { background: #b91c1c; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.97); } }

/* ── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 1000; backdrop-filter: blur(2px);
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh;
  display: flex; flex-direction: column;
  animation: modalIn .2s cubic-bezier(.2,.8,.3,1);
}
.modal-lg { max-width: 820px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.985); } }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 15px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; background: #fafbfc; border-radius: 0 0 var(--radius) var(--radius); }
.modal-close { background: none; border: none; font-size: 1.4rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.modal-close:hover { background: #f1f5f9; color: var(--ink); }

/* ── Utility spacing ────────────────────────────────────── */
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; } .mt-4 { margin-top: 32px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; }

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  h1 { font-size: 1.45rem; }
  .card-pad, .card-body { padding: 17px; }
  .card-head { padding: 14px 17px; }
  #toasts { left: 14px; right: 14px; bottom: 14px; max-width: none; }
}

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .card { box-shadow: none; border-color: #cbd5e1; }
}
