/* ============ RESET ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e0;
  --border-focus: #3b82f6;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --primary: #1e3a8a;
  --primary-hover: #1e40af;
  --primary-light: #eff6ff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --success: #059669;
  --success-bg: #d1fae5;
  --info: #2563eb;
  --info-bg: #dbeafe;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.05);
  --shadow-md: 0 4px 6px -1px rgba(15,23,42,0.07), 0 2px 4px -1px rgba(15,23,42,0.04);
  --shadow-lg: 0 10px 20px -3px rgba(15,23,42,0.08), 0 4px 8px -2px rgba(15,23,42,0.04);
  --shadow-xl: 0 20px 40px -4px rgba(15,23,42,0.10);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============ LOGIN ============ */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 30%, rgba(30,58,138,0.05), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(37,99,235,0.05), transparent 40%),
    var(--bg);
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--border);
}
.auth-logo {
  display: block;
  height: 56px;
  margin: 0 auto 28px;
  object-fit: contain;
}
.auth-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 14px;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-label span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.auth-label input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-label input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.auth-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid #fecaca;
}
.auth-success {
  background: var(--success-bg);
  color: var(--success);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ============ BUTTONS ============ */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.btn-secondary:hover { background: var(--surface-alt); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--surface-alt); border-color: var(--border-strong); }
.btn-icon.refreshing svg { animation: spin 0.8s linear infinite; }

/* ============ TOPBAR ============ */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 30;
  height: 56px;
}
.topbar-left { display: flex; align-items: center; gap: 20px; height: 100%; }
.topbar-logo { height: 32px; object-fit: contain; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* View Switcher inside dropdown */
.dropdown-section {
  padding: 10px 14px 12px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
.dropdown-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.view-switcher-dropdown {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px;
  border-radius: 7px;
  gap: 2px;
  width: 100%;
}
.view-switcher-dropdown .view-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  border-radius: 5px;
  transition: all 0.15s;
}
.view-switcher-dropdown .view-btn:hover { color: var(--text); }
.view-switcher-dropdown .view-btn.active {
  background: var(--primary);
  color: white;
}

/* Attribution — "by X · date" */
.attribution {
  font-size: 11px;
  color: var(--text-light);
  font-style: italic;
  margin-top: 4px;
}
.attribution strong { color: var(--text-muted); font-style: normal; font-weight: 600; }

/* ============ SECTION BAR (Parent Tabs) ============ */
.section-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.parent-tabs {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 10px;
  gap: 2px;
}
.parent-tab {
  background: transparent;
  border: none;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.18s;
  white-space: nowrap;
}
.parent-tab .ptab-icon { opacity: 0.7; }
.parent-tab:hover {
  color: var(--text);
  background: rgba(255,255,255,0.5);
}
.parent-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(15,23,42,0.10), 0 1px 2px rgba(15,23,42,0.05);
}
.parent-tab.active .ptab-icon { opacity: 1; }

/* ============ USER MENU ============ */
.user-menu { position: relative; }
.btn-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 10px 5px 5px;
  border-radius: 20px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}
.btn-user:hover { background: var(--surface-alt); }
.user-avatar {
  width: 26px;
  height: 26px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.user-name { font-weight: 500; }

.dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  overflow: hidden;
  z-index: 40;
}
.dropdown-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 12px;
}
.dropdown-header strong { display: block; font-size: 13px; color: var(--text); margin-bottom: 2px; }
.dropdown-header span { color: var(--text-muted); }
.dropdown-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}
.dropdown-item:hover { background: var(--surface-alt); }
.dropdown-danger { color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ============ SUB TABS ============ */
.sub-tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: thin;
  align-items: center;
}
.sub-tab {
  background: none;
  border: none;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: all 0.15s;
  font-weight: 500;
}
.sub-tab:hover { color: var(--text); }
.sub-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.badge {
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  min-width: 22px;
  text-align: center;
}
.sub-tab.active .badge { background: var(--primary); color: white; }
.orders-stage-tabs { display: contents; }

/* ============ TOOLBAR ============ */
.toolbar {
  background: var(--surface);
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 400px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  border: none;
  outline: none;
  flex: 1;
  font-size: 13px;
  font-family: inherit;
  background: transparent;
  color: var(--text);
}
.search-box:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(59,130,246,0.12); }

.toolbar-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Filter group (date filter) */
.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.date-filter-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.date-filter-wrap .filter-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}
.date-filter-wrap select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 30px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  font-weight: 500;
}
.date-filter-wrap select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.custom-range {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
}
.custom-range input[type="date"] {
  border: none;
  padding: 2px 4px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  width: 120px;
  outline: none;
}
.custom-range input[type="date"]:focus { color: var(--primary); }
.range-sep {
  font-size: 11px;
  color: var(--text-muted);
}
#custom-clear {
  padding: 2px 6px;
  font-size: 14px;
  line-height: 1;
  color: var(--text-muted);
  border: none;
  background: transparent;
}
#custom-clear:hover { color: var(--danger); background: var(--surface-alt); }

/* Stale dot indicator */
.stale-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  margin-right: 8px;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(220,38,38,0.15);
}
.result-count {
  color: var(--text-muted);
  font-size: 12px;
}
.sync-pill {
  background: var(--success-bg);
  color: var(--success);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.sync-pill.error { background: var(--danger-bg); color: var(--danger); }
.sync-pill.loading { background: var(--info-bg); color: var(--info); }

/* ============ TABLE ============ */
.table-wrapper {
  padding: 16px 24px 60px;
  position: relative;
  min-height: 300px;
}
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table thead {
  background: var(--surface-alt);
}
.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.data-table th.sortable:hover { background: var(--border); color: var(--text); }
.data-table th .sort-icon {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.35;
  vertical-align: middle;
  transition: opacity 0.15s;
}
.data-table th.sortable:hover .sort-icon { opacity: 0.7; }
.data-table th.sort-active .sort-icon { opacity: 1; color: var(--primary); }
.data-table th.sort-active { color: var(--primary); }

/* Days until badge — plain-language format */
.days-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.days-badge.overdue {
  background: var(--danger-bg);
  color: var(--danger);
}
.days-badge.today {
  background: var(--warning-bg);
  color: var(--warning);
}
.days-badge.upcoming {
  background: var(--warning-bg);
  color: var(--warning);
}
.days-badge.future {
  background: var(--surface-alt);
  color: var(--text-muted);
}

/* Settings modal — tabbed */
.modal-wide { max-width: 620px; }
.settings-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.settings-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  border-radius: 6px;
  transition: all 0.15s;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(15,23,42,0.10);
}
.settings-panel { min-height: 240px; }
.settings-panel > .settings-desc { margin-bottom: 14px; }
.settings-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}
#password-form { display: flex; flex-direction: column; gap: 14px; }

.color-labels-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding: 2px;
  margin-bottom: 14px;
}
.color-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  position: relative;
}
.color-label-row:hover { background: var(--surface-alt); }
.color-label-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}
.color-label-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}
.color-label-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.color-label-input::placeholder { color: var(--text-light); font-style: italic; }
.color-label-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  line-height: 1;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.color-label-row:hover .color-label-remove { opacity: 1; }
.color-label-remove:hover { color: var(--danger); background: var(--surface); }
.color-label-badge {
  font-size: 9px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
  flex-shrink: 0;
}

.add-custom-color {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
}
.add-custom-color input[type="color"] {
  width: 40px;
  height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 2px;
  background: var(--surface);
}
.add-custom-color input[type="text"] {
  flex: 1;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 12px;
  font-family: inherit;
}
.add-custom-color input[type="text"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.add-custom-color .btn-primary {
  padding: 7px 14px;
  font-size: 12px;
}

/* Audit Log */
.audit-log-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.audit-log-list {
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.audit-entry {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  font-size: 12px;
}
.audit-entry:last-child { border-bottom: none; }
.audit-entry:hover { background: var(--surface-hover); }
.audit-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--primary-light);
  color: var(--primary);
}
.audit-icon.success { background: var(--success-bg); color: var(--success); }
.audit-icon.warn { background: var(--warning-bg); color: var(--warning); }
.audit-icon.danger { background: var(--danger-bg); color: var(--danger); }
.audit-body { flex: 1; min-width: 0; }
.audit-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.audit-title { color: var(--text); font-weight: 500; word-break: break-word; }
.audit-title strong { color: var(--primary); font-weight: 600; }
.audit-time {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}
.audit-detail {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
  line-height: 1.4;
}
.audit-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Weight History display */
.weight-history {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.weight-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.weight-entry:last-child { border-bottom: none; }
.weight-entry .w-date { color: var(--text-muted); }
.weight-entry .w-value { font-weight: 600; color: var(--text); }
.weight-entry .w-source {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text-muted);
}
.weight-entry .w-source.manual { background: var(--info-bg); color: var(--info); }
.log-weight-btn {
  margin-top: 8px;
  width: 100%;
  padding: 8px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.log-weight-btn:hover { background: var(--surface-alt); color: var(--text); border-color: var(--text-muted); }
.log-weight-form {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.log-weight-form input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
}
.log-weight-form input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.log-weight-form button {
  padding: 6px 14px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
}
.log-weight-form button:hover { background: var(--primary-hover); }
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Row coloring overrides default backgrounds */
.data-table tbody tr[data-color] td {
  background: var(--row-color) !important;
}

.cell-name { font-weight: 600; color: var(--text); cursor: pointer; }
.cell-name:hover { color: var(--primary); }
.cell-muted { color: var(--text-muted); font-size: 12px; }
.cell-mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }

.days-overdue { color: var(--danger); font-weight: 700; }
.days-upcoming { color: var(--warning); font-weight: 600; }
.days-future { color: var(--text-muted); }

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-paid { background: var(--success-bg); color: var(--success); }
.status-partial { background: var(--warning-bg); color: var(--warning); }
.status-overdue { background: var(--danger-bg); color: var(--danger); }
.status-sent { background: var(--info-bg); color: var(--info); }
.status-draft { background: var(--surface-alt); color: var(--text-muted); }
.status-neutral { background: var(--surface-alt); color: var(--text); }

.amount-due { color: var(--danger); font-weight: 700; }
.amount-paid { color: var(--success); }

.notes-cell { position: relative; min-width: 220px; }
.notes-input {
  width: 100%;
  padding: 6px 28px 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
  min-height: 32px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.notes-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.notes-input.dirty {
  border-color: #f59e0b;
  background: #fffbeb;
}
.notes-input.dirty:focus {
  box-shadow: 0 0 0 2px rgba(245,158,11,0.15);
}
.notes-input.saved {
  border-color: #10b981;
}

/* Save indicator inside notes cell */
.notes-status {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.notes-status.visible { opacity: 1; }
.notes-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
}
.notes-status .mini-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--info);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.notes-status .check {
  color: #10b981;
}
.notes-status .err {
  color: var(--danger);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-btn {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  position: relative;
  font-size: 0;
}
.color-btn::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 2px;
  background: var(--swatch-color, repeating-conic-gradient(#e5e7eb 0% 25%, white 0% 50%) 50% / 6px 6px);
}
.color-btn:hover { border-color: var(--text); }

.checkbox-wrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.checkbox-wrap input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* ============ COLOR POPOVER (Google Sheets-style) ============ */
.color-popover {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 10px;
  z-index: 50;
  width: 260px;
}
.color-popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.color-popover-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  border-radius: 3px;
}
.color-popover-close:hover { color: var(--danger); background: var(--surface-alt); }
.color-none {
  width: 24px;
  height: 22px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  background: white;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.color-none:hover { border-color: var(--text); }
.color-grid {
  display: grid;
  grid-template-columns: repeat(10, 22px);
  gap: 3px;
}
.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.1s;
}
.color-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  z-index: 2;
}
.color-swatch.selected {
  border: 2px solid var(--primary);
  outline: 1px solid white;
  outline-offset: -2px;
}
.color-hint {
  margin-top: 8px;
  padding: 6px 8px;
  background: var(--surface-alt);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text);
  min-height: 26px;
  line-height: 1.3;
}
.color-hint:empty { display: none; }

/* ============ SUGGESTIONS POPOVER ============ */
.suggestions-popover {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  max-width: 320px;
  max-height: 200px;
  overflow-y: auto;
}
.suggestion-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item.active { background: var(--primary-light); }

/* ============ EMPTY / LOADING ============ */
.empty-state, .loading-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state svg { display: block; margin: 0 auto 12px; opacity: 0.4; }
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ SLIDE-OVER PANEL (Patient Detail) ============ */
.slideover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 90;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.18s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.slideover {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 100vw;
  background: var(--surface);
  z-index: 100;
  box-shadow: -8px 0 24px rgba(15,23,42,0.10);
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.22s ease-out;
}
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.slideover-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.slideover-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
.slideover-contact {
  font-size: 13px;
  color: var(--text-muted);
}
.slideover-contact a {
  color: var(--text-muted);
  text-decoration: none;
}
.slideover-contact a:hover { color: var(--primary); text-decoration: underline; }
.slideover-close {
  background: none;
  border: none;
  font-size: 26px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.slideover-close:hover { background: var(--surface-alt); color: var(--text); }

.slideover-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 40px;
}

.detail-pill-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.detail-section {
  margin-top: 22px;
}
.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.detail-section-title .count {
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 8px;
  font-size: 10px;
  margin-left: 6px;
}
.detail-section-title .edit-link {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}
.detail-section-title .edit-link:hover { text-decoration: underline; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
}
.detail-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.detail-field-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}
.detail-field-value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  word-break: break-word;
}
.detail-field-value.muted { color: var(--text-muted); font-weight: 400; }

/* Tags row */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.tag-chip {
  background: var(--primary-light);
  color: var(--primary);
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

/* Order history list */
.order-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.order-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto auto;
  gap: 10px;
  padding: 10px 12px;
  font-size: 12px;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.order-row:last-child { border-bottom: none; }
.order-row:hover { background: var(--surface-hover); }
.order-row .order-date { color: var(--text-muted); white-space: nowrap; }
.order-row .order-program { color: var(--text); font-weight: 500; }
.order-row .order-amount { font-weight: 600; color: var(--text); }

/* GHL notes list */
.ghl-notes {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}
.ghl-note {
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  border-left: 3px solid var(--primary);
}
.ghl-note-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}
.ghl-note-body {
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.ghl-notes-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 16px;
  text-align: center;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
}
.detail-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 0;
}
.detail-loading .mini-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--info);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.detail-notes-box {
  position: relative;
}
.detail-notes-box textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  min-height: 90px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.detail-notes-box textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.detail-notes-box textarea.dirty {
  border-color: #f59e0b;
  background: #fffbeb;
}
.detail-notes-box textarea.saved {
  border-color: #10b981;
}
.detail-notes-status {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.85);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.detail-notes-status.visible { opacity: 1; }
.detail-notes-status.unsaved { color: #d97706; }
.detail-notes-status.saving { color: var(--info); }
.detail-notes-status.saved { color: #10b981; }
.detail-notes-status.error { color: var(--danger); }

/* ============ MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-xl);
  position: relative;
}
.modal-content h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
  padding-right: 30px;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-alt); }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}
#password-form { display: flex; flex-direction: column; gap: 14px; }

.info-content {
  font-size: 13px;
  color: var(--text);
  line-height: 1.7;
}
.info-content .info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.info-content .info-row:last-child { border-bottom: none; }
.info-content .info-label { color: var(--text-muted); font-weight: 500; }
.info-content .info-value { color: var(--text); font-weight: 600; }

/* ============ TOAST ============ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease-out;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .topbar { padding: 0 14px; }
  .topbar-left { gap: 12px; }
  .section-bar { padding: 10px 14px; }
  .parent-tab { padding: 8px 14px; font-size: 13px; }
  .parent-tab .ptab-icon { display: none; }
  .sub-tabs, .toolbar, .table-wrapper { padding-left: 14px; padding-right: 14px; }
  .user-name { display: none; }
  .refresh-text { display: none; }
  .view-btn { padding: 5px 8px; font-size: 11px; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 10px; }
  .slideover { width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  .toolbar { flex-wrap: wrap; }
  .custom-range input[type="date"] { width: 110px; }
  .color-labels-grid { grid-template-columns: 1fr; }
}
