/* Douglas App - v1.0 shared design system
 * Synced palette with chat (style.css). Mobile-first iOS PWA.
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ===== Design tokens ===== */
:root {
  --bg-base: #0E0E0E;
  --bg-surface-1: #1A1A1A;
  --bg-surface-2: #222222;
  --bg-surface-3: #2C2C2C;
  --bg-overlay: #333333;

  --accent: #3B82F6;
  --accent-light: #60A5FA;
  --accent-dark: #2563EB;
  --achieve: #F59E0B;
  --success: #22C55E;
  --danger: #EF4444;

  --text-primary: #F5F5F5;
  --text-secondary: #A0A0A0;
  --text-tertiary: #666666;
  --text-disabled: #444444;

  --border-subtle: #252525;
  --border-default: #333333;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 9999px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --header-height: 56px;
  --tabbar-height: 56px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
input, select, textarea { font: inherit; color: inherit; background: transparent; border: 0; }

/* ===== App shell ===== */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 50;
  padding-top: var(--safe-top);
  background: rgba(14,14,14,.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}
.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  height: var(--header-height);
}
.app-header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.01em;
}
.app-header-actions {
  display: flex;
  gap: var(--space-3);
}
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--text-primary);
  padding: 8px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--bg-surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.has-badge::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* Main scroll area - tighter, more breathing room on cards */
.app-main {
  flex: 1;
  padding: var(--space-4) var(--space-5);
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 24px);
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* Sub-tabs (segmented control) */
.subtabs {
  display: flex;
  gap: var(--space-2);
  background: var(--bg-surface-1);
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}
.subtab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.subtab.active {
  background: var(--bg-surface-3);
  color: var(--text-primary);
}

/* Card */
.card {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
.card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}
.card-row:last-child { border-bottom: 0; padding-bottom: 0; }

/* Stats */
.stat-big {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1;
  color: var(--text-primary);
}
.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}
.stat-cell .stat-value {
  font-size: 17px;
  font-weight: 600;
}
.stat-cell .stat-key {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: 2px;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge.public { background: rgba(34,197,94,.15); color: var(--success); }
.badge.restricted { background: rgba(245,158,11,.15); color: var(--achieve); }
.badge.admin_only { background: rgba(239,68,68,.15); color: var(--danger); }

/* Compound row */
.compound-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}
.compound-row:last-child { border-bottom: 0; }
.compound-meta { flex: 1; min-width: 0; }
.compound-time {
  font-size: 11px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.compound-name { font-size: 15px; font-weight: 500; margin-top: 2px; }
.compound-dose { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.check-btn {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--border-default);
  color: var(--text-tertiary);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.check-btn.taken {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Compliance bar */
.compliance {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}
.compliance .pct { font-size: 22px; font-weight: 700; color: var(--accent); }
.compliance .label { font-size: 12px; color: var(--text-secondary); }

/* Quick actions */
.quick-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.action-btn {
  background: var(--bg-surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
}
.action-btn.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Tab-bar (bottom) */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  background: rgba(14,14,14,.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: 1fr 1fr 72px 1fr 1fr;
  align-items: center;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
}
.tab {
  background: transparent;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 500;
  padding: 6px 0;
}
.tab.active { color: var(--text-primary); }
.tab.active svg { color: var(--accent); }
.tab svg { width: 24px; height: 24px; }

/* Plus button (center divider) */
.tab-plus {
  display: flex;
  justify-content: center;
  align-items: center;
}
.tab-plus-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: 4px solid var(--bg-base);
  box-shadow: 0 4px 12px rgba(59,130,246,.4);
  font-size: 28px;
  font-weight: 300;
  margin-top: -28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tab-plus-btn:active { transform: scale(.95); background: var(--accent-dark); }

/* Plus modal (bottom sheet) */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.bottom-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 201;
  background: var(--bg-surface-1);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: var(--space-3) var(--space-4) calc(var(--space-6) + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4, 0, .2, 1);
  max-height: 75vh;
  overflow-y: auto;
}
.bottom-sheet.open { transform: translateY(0); }
.bottom-sheet-handle {
  width: 40px; height: 4px;
  background: var(--text-tertiary);
  border-radius: var(--radius-pill);
  margin: 0 auto var(--space-4);
}
.bottom-sheet-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: var(--space-3);
  text-align: center;
}
.sheet-action {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  margin-bottom: var(--space-2);
  width: 100%;
  border: 0;
  text-align: left;
  color: var(--text-primary);
  font-size: 15px;
}
.sheet-action:active { background: var(--bg-surface-3); }
.sheet-action .ico {
  width: 36px; height: 36px;
  background: var(--bg-surface-3);
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sheet-action .ico svg { width: 20px; height: 20px; color: var(--accent); }

/* Empty + loading states */
.loading, .empty {
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  padding: var(--space-4) 0;
}

/* Kebab dropdown (verticale ⋮) */
.kebab-menu {
  position: absolute;
  top: 48px;
  right: 16px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  z-index: 80;
  min-width: 180px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity .2s, transform .2s;
}
.kebab-menu.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.kebab-item {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 14px;
}
.kebab-item:active { background: var(--bg-surface-3); }
.kebab-item.danger { color: var(--danger); }

/* Notification banner */
.notif-banner {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: white;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.notif-banner.subtle {
  background: var(--bg-surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}
.notif-banner .ico { font-size: 20px; }
.notif-banner .txt { flex: 1; font-size: 14px; }

/* Score circle */
.score-circle {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: var(--bg-surface-2);
  border: 4px solid var(--accent);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.score-circle .num {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.score-circle .lbl {
  font-size: 9px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* List item link-style */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  text-align: left;
  font-size: 15px;
}
.list-item:last-child { border-bottom: 0; }
.list-item .chev { color: var(--text-tertiary); font-size: 18px; }

/* Mode banner (training-active etc.) */
.mode-banner {
  position: sticky;
  top: var(--header-height);
  z-index: 40;
  background: var(--accent-dark);
  color: white;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mode-banner.training { background: var(--accent); }
