/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --success:       #16a34a;
  --danger:        #dc2626;
  --warning:       #d97706;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --sidebar-width: 200px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

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

/* ── Top Navigation ──────────────────────────────────────────── */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  height: 48px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

.nav-brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .5px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-links a {
  color: rgba(255,255,255,.9);
  font-size: 13px;
}
.nav-links a:hover { color: #fff; text-decoration: none; }

.nav-username {
  color: rgba(255,255,255,.7);
  font-size: 13px;
}

.nav-logout-form { margin: 0; }
.btn-logout {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }

/* ── Main Content ────────────────────────────────────────────── */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* ── Flash Messages ──────────────────────────────────────────── */
.messages-container { margin-bottom: 16px; }

.message {
  padding: 10px 16px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 14px;
}
.message-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.message-error, .message-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.message-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.message-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }

.btn-primary  { background: var(--primary);  color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }

.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #15803d; }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-full { width: 100%; text-align: center; display: block; }

/* ── Login ───────────────────────────────────────────────────── */
.login-container {
  max-width: 360px;
  margin: 60px auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 36px 32px;
}

.login-title {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 24px;
}

.login-form .form-group { margin-bottom: 16px; }
.login-form label { display: block; font-weight: 500; margin-bottom: 4px; }
.login-form input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 14px;
}
.login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.login-form .btn-full { margin-top: 8px; padding: 10px; font-size: 15px; }

/* ── Admin Layout ────────────────────────────────────────────── */
.admin-layout {
  display: flex;
  gap: 0;
  min-height: calc(100vh - 96px);
}

.admin-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
}

.admin-nav { display: flex; flex-direction: column; }

.admin-nav-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  padding: 12px 16px 6px;
  margin: 8px 8px 4px;
  border-bottom: 1px solid var(--border);
}

.admin-nav a {
  display: block;
  padding: 8px 16px;
  color: var(--text);
  font-size: 13px;
  border-left: 3px solid transparent;
}
.admin-nav a:hover { background: var(--bg); text-decoration: none; }
.admin-nav a.active { border-left-color: var(--primary); color: var(--primary); font-weight: 600; background: #eff6ff; }

.admin-main {
  flex: 1;
  padding: 24px;
  min-width: 0;
}

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.page-header h1 { font-size: 20px; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-left: 12px; }
.header-actions { display: flex; gap: 8px; }
.page-desc { color: var(--text-muted); margin-bottom: 20px; }

/* ── Tables ──────────────────────────────────────────────────── */
.admin-table, .appt-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-size: 13px;
}

.admin-table th, .appt-table th {
  background: var(--bg);
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.admin-table td, .appt-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table tr:last-child td,
.appt-table tr:last-child td { border-bottom: none; }

.admin-table tbody tr:hover,
.appt-table tbody tr:hover { background: #f8fafc; }

.narrow-table { max-width: 500px; }
.narrow-table th { width: 140px; }

.empty-row { text-align: center; color: var(--text-muted); padding: 20px !important; }

.actions { white-space: nowrap; }
.actions form { display: inline; }

.row-delivered td { color: var(--text-muted); }
.row-overdue td { background: #fff7ed !important; }
.row-inactive td { color: var(--text-muted); font-style: italic; }
.row-hidden td { color: var(--text-muted); font-style: italic; opacity: .6; }

.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* ── Filter Form ─────────────────────────────────────────────── */
.filter-details { margin-bottom: 16px; }
.filter-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding: 6px 0;
  user-select: none;
  width: fit-content;
}
.filter-active-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  padding: 1px 7px;
  border-radius: 10px;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.filter-form select,
.filter-form input[type="number"] {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  background: var(--surface);
}

/* ── Admin Forms ─────────────────────────────────────────────── */
.admin-form {
  max-width: 540px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
}

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 5px;
  color: var(--text);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}

.form-group.has-error input,
.form-group.has-error select,
.form-group.has-error textarea {
  border-color: var(--danger);
}

.help-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

.radio-group { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.radio-label { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.radio-label input[type="radio"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Checkbox list (Cohort members) */
.checkbox-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 8px;
  background: var(--surface);
}

.checkbox-list li { list-style: none; padding: 4px 6px; }
.checkbox-list li:hover { background: var(--bg); border-radius: 4px; }
.checkbox-list label { font-weight: normal; cursor: pointer; display: flex; gap: 8px; align-items: center; }

/* ── Balance Box ─────────────────────────────────────────────── */
.balance-box {
  display: flex;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 24px;
  max-width: 480px;
}

.balance-box.compact { margin-bottom: 0; }

.balance-item {
  flex: 1;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.balance-divider {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
}

.balance-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
}

.balance-amount {
  font-size: 28px;
  font-weight: 700;
  color: var(--success);
}

.balance-amount.negative { color: var(--danger); }
.balance-note { font-size: 11px; color: var(--text-muted); }

/* ── Customer Dashboard ──────────────────────────────────────── */
.dashboard h1 { font-size: 24px; font-weight: 700; margin-bottom: 20px; }

.attention-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
}

.attention-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--warning);
  margin-bottom: 8px;
}

.attention-box p { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.attention-box .appt-table { margin-top: 8px; }

.month-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.month-nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
}
.month-nav-arrow:hover { background: var(--bg); text-decoration: none; }

.month-nav-label { font-size: 16px; font-weight: 600; }

.month-section { margin-bottom: 32px; }
.month-heading { font-size: 16px; font-weight: 700; margin-bottom: 12px; }

.week-cell { font-weight: 600; vertical-align: top !important; padding-top: 11px !important; }

.row-overdue td { background: #fff7ed !important; }
.badge-overdue {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: #fed7aa;
  color: #92400e;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  text-transform: uppercase;
}
.badge-inactive {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: #e5e7eb;
  color: #6b7280;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  text-transform: uppercase;
}
.badge-hidden {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: #ede9fe;
  color: #5b21b6;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  text-transform: uppercase;
}

.row-delivered td { color: var(--text-muted); }
.empty-note { color: var(--text-muted); font-style: italic; font-size: 13px; padding: 12px 0; }

.badge-funded {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: #dcfce7;
  color: #166534;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  text-transform: uppercase;
}
.badge-unfunded {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: #fee2e2;
  color: #991b1b;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  text-transform: uppercase;
}

.payment-history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}
.payment-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.payment-history-meta { font-weight: 600; }
.payment-history-amount { font-weight: 700; color: var(--success); }
.payment-history-amount.negative { color: var(--danger); }
.payment-history-card .appt-table { border: none; border-radius: 0; }
.payment-history-card .empty-note { padding: 12px 16px; }
.text-right { text-align: right; }
.table-total-row td { border-top: 2px solid var(--border); background: var(--bg-alt); }

/* ── Confirm Delete ──────────────────────────────────────────── */
.confirm-box {
  max-width: 540px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
}

.confirm-box > p { margin-bottom: 16px; font-size: 15px; }

.warning-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  padding: 12px 16px;
  margin: 16px 0;
  font-size: 13px;
  color: var(--text);
}

.confirm-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Detail Page ─────────────────────────────────────────────── */
.detail-grid { margin-bottom: 24px; }
.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  display: inline-block;
}
.detail-card h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); margin-bottom: 12px; }

.back-link { margin-top: 24px; font-size: 13px; }

/* ── Event Log ───────────────────────────────────────────────── */
.log-container {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  background: #0f172a;
  color: #94a3b8;
  border-radius: 8px;
  padding: 16px;
  max-height: 72vh;
  overflow-y: auto;
  overflow-x: auto;
}

.log-line {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  line-height: 1.6;
  white-space: pre;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.page-info { font-size: 13px; color: var(--text-muted); }

/* ── Section Headings in Detail View ────────────────────────── */
.admin-main h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 24px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.admin-main h2:first-of-type { margin-top: 0; }

/* ── Tom Select ─────────────────────────────────────────────── */
.form-group .ts-wrapper { width: 100%; }
.form-group .ts-control { overflow: hidden; }

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Tighten page padding */
  .main-content { padding: 12px; }
  .admin-main { padding: 16px 12px; }

  /* Sidebar → horizontal scrolling strip */
  .admin-layout { flex-direction: column; }
  .admin-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
  }
  .admin-nav {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 8px;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .admin-nav::-webkit-scrollbar { display: none; }
  .admin-nav-section { display: none; }
  .admin-nav a {
    display: inline-block;
    white-space: nowrap;
    flex-shrink: 0;
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 10px 12px;
  }
  .admin-nav a:hover { background: transparent; }
  .admin-nav a.active {
    border-left-color: transparent;
    border-bottom-color: var(--primary);
    background: transparent;
  }

  /* Scrollable admin tables */
  .admin-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Larger touch targets for xs buttons */
  .btn-xs { padding: 6px 10px; font-size: 12px; }

  /* Filter form stacks vertically */
  .filter-form {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-form select,
  .filter-form input[type="number"] { width: 100%; }

  /* Balance box full width */
  .balance-box { max-width: 100%; }

  /* Month nav wraps */
  .month-nav { flex-wrap: wrap; }

  /* Dashboard appointment tables → card layout */
  .appt-table { display: block; }
  .appt-table thead { display: none; }
  .appt-table tbody { display: block; }
  .appt-table tr {
    display: block;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--surface);
  }
  .appt-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
  }
  .appt-table tr td:last-child { border-bottom: none; }
  .appt-table td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-right: 12px;
  }
  .week-cell { display: none; }
  .row-overdue td { background: #fff7ed !important; }
}

/* Bulk actions toolbar */
.bulk-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.bulk-select-all-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

/* Checkbox column */
.col-cb {
  width: 40px;
  text-align: center;
  padding-left: 8px !important;
  padding-right: 8px !important;
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
}
.col-cb input[type="checkbox"],
.bulk-select-all-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* Session schedule — template section */
.template-section {
  margin-bottom: 28px;
}
.template-section-heading {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.template-save-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.template-name-input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  width: 240px;
}

/* Session schedule rows */
.session-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 10px;
}
.session-row-fields {
  display: flex;
  gap: 16px;
  flex: 1;
  flex-wrap: wrap;
}
.session-row .form-group {
  flex: 1;
  min-width: 160px;
  margin-bottom: 0;
}

/* Drag-and-drop sort list */
.sort-list {
  max-width: 480px;
  margin-bottom: 24px;
}
.sort-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
}
.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  font-size: 20px;
  line-height: 1;
  padding: 2px 4px;
  user-select: none;
  flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }
.sort-item-ghost { opacity: 0.35; }
.sort-item-name { font-size: 14px; }

/* Tom Select overrides */
.ts-wrapper { flex: 1 1 auto; min-width: 120px; }
.ts-control {
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  background: var(--surface) !important;
  font-size: 14px !important;
  padding: 5px 8px !important;
  box-shadow: none !important;
}
.ts-control:focus-within { border-color: var(--primary) !important; }
.ts-dropdown {
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  font-size: 14px !important;
}
.ts-dropdown .option.selected,
.ts-dropdown .option:hover { background: var(--primary) !important; color: #fff !important; }

/* Touch-friendly clickable rows */
@media (hover: none) {
  tr.clickable-row {
    cursor: pointer;
  }
  tr.clickable-row:active td {
    background-color: #e0e7ff;
  }
}
