/* ============================================================
   PULSE — Main Stylesheet
   Design tokens, layout, components
   ============================================================ */

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

:root {
  --bg:        #1c1e22;
  --surface:   #23262b;
  --input:     #2a2d34;
  --text:      #e8eaf0;
  --muted:     #555c6e;
  --accent:    #3b82f6;
  --green:     #22c55e;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --border:    0.5px solid rgba(255,255,255,0.055);
  --radius-card:  14px;
  --radius-input: 9px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* --- App Shell --- */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0 16px;
  gap: 4px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.sidebar-logo .logo-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-radius: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}

.nav-item.active {
  color: var(--text);
  background: rgba(59,130,246,0.12);
}

.nav-item .ti {
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-spacer { flex: 1; }

.sidebar-user {
  padding: 12px 20px;
  border-top: var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-logout {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s;
}

.sidebar-logout:hover { color: var(--red); }

/* --- Main Content --- */
.main-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: var(--border);
  flex-shrink: 0;
}

.topbar-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.topbar-date {
  font-size: 13px;
  color: var(--muted);
}

/* --- Page Body --- */
.page-body {
  padding: 28px 32px;
  flex: 1;
  max-width: 900px;
  width: 100%;
}

/* --- Cards --- */
.card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-card);
  padding: 20px 24px;
}

.card-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* --- Deficit Hero --- */
.deficit-hero {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-card);
  padding: 28px 32px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.deficit-number {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: -2px;
  line-height: 1;
  color: var(--green);
}

.deficit-number.surplus {
  color: var(--red);
}

.deficit-number.neutral {
  color: var(--amber);
}

.deficit-label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.deficit-meta {
  text-align: right;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.8;
}

/* --- Two-up Stat Cards --- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-card);
  padding: 20px 24px;
}

.stat-card-value {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1.1;
}

.stat-card-value.amber { color: var(--amber); }
.stat-card-value.blue  { color: var(--accent); }
.stat-card-value.green { color: var(--green); }
.stat-card-value.red   { color: var(--red); }

.stat-card-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.stat-card-icon {
  font-size: 22px;
  margin-bottom: 12px;
  opacity: 0.7;
}

/* --- Progress Bar --- */
.progress-wrap {
  margin-bottom: 20px;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--input);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.progress-bar-fill.over { background: var(--red); }

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* --- Macros Row --- */
.macros-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.macro-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-card);
  padding: 14px 18px;
  text-align: center;
}

.macro-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.macro-unit {
  font-size: 12px;
  color: var(--muted);
}

.macro-name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}

/* --- AI Meal Input --- */
.ai-input-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-card);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.ai-input-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.ai-input-card .subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

.ai-textarea {
  width: 100%;
  background: var(--input);
  border: var(--border);
  border-radius: var(--radius-input);
  color: var(--text);
  font-size: 14px;
  padding: 12px 14px;
  resize: vertical;
  min-height: 72px;
  outline: none;
  transition: border-color 0.15s;
}

.ai-textarea:focus {
  border-color: rgba(59,130,246,0.5);
}

.ai-textarea::placeholder {
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { opacity: 0.88; }

.btn-ghost {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.btn-ghost:hover { background: rgba(255,255,255,0.1); }

.btn-danger {
  background: rgba(239,68,68,0.12);
  color: var(--red);
}

.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-full { width: 100%; justify-content: center; }

/* --- AI Preview --- */
.ai-preview {
  background: var(--input);
  border: var(--border);
  border-radius: var(--radius-input);
  padding: 14px 16px;
  margin-top: 14px;
}

.ai-preview-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.ai-preview-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  padding: 5px 0;
  border-bottom: var(--border);
  gap: 8px;
}

.ai-preview-item:last-of-type { border-bottom: none; }

.ai-preview-item-name {
  color: var(--text);
  flex: 1;
}

.ai-preview-item-cals {
  color: var(--amber);
  font-weight: 600;
  white-space: nowrap;
}

.ai-preview-macros {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.ai-preview-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 0.5px solid rgba(255,255,255,0.1);
  font-size: 13px;
  font-weight: 700;
}

.ai-preview-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Meal List --- */
.meal-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.meal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  background: var(--surface);
  border: var(--border);
  border-radius: 10px;
  font-size: 13px;
  transition: background 0.1s;
}

.meal-item:hover { background: #25282e; }

.meal-item-desc {
  flex: 1;
  color: var(--text);
  font-size: 14px;
}

.meal-item-cals {
  color: var(--amber);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.meal-item-macros {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.meal-item-time {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.meal-item-delete {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

.meal-item-delete:hover {
  color: var(--red);
  background: rgba(239,68,68,0.1);
}

.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state .ti {
  font-size: 28px;
  display: block;
  margin-bottom: 8px;
  opacity: 0.4;
}

/* --- Section Header --- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* --- Forms (Auth) --- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-card);
  padding: 36px 40px;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 28px;
  letter-spacing: -0.5px;
}

.auth-logo .logo-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.auth-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  background: var(--input);
  border: var(--border);
  border-radius: var(--radius-input);
  color: var(--text);
  font-size: 14px;
  padding: 10px 13px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: rgba(59,130,246,0.5);
}

.form-input::placeholder {
  color: var(--muted);
}

.auth-footer {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 20px;
}

.auth-footer a {
  color: var(--accent);
}

.auth-footer a:hover { text-decoration: underline; }

/* --- Alert / Flash --- */
.alert {
  border-radius: var(--radius-input);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-error {
  background: rgba(239,68,68,0.1);
  border: 0.5px solid rgba(239,68,68,0.3);
  color: #fca5a5;
}

.alert-success {
  background: rgba(34,197,94,0.1);
  border: 0.5px solid rgba(34,197,94,0.3);
  color: #86efac;
}

.alert-info {
  background: rgba(59,130,246,0.1);
  border: 0.5px solid rgba(59,130,246,0.3);
  color: #93c5fd;
}

/* --- Weight Page --- */
.weight-hero {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.weight-number {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: -2px;
  color: var(--text);
}

.weight-unit {
  font-size: 18px;
  color: var(--muted);
  font-weight: 500;
}

.weight-goal-bar {
  margin-top: 12px;
}

.weight-history {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.weight-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  background: var(--surface);
  border: var(--border);
  border-radius: 10px;
  font-size: 13px;
}

.weight-row-date { color: var(--muted); }
.weight-row-val  { font-weight: 600; color: var(--text); font-size: 15px; }
.weight-row-delta-down { color: var(--green); font-size: 12px; }
.weight-row-delta-up   { color: var(--red); font-size: 12px; }

/* --- WHOOP Card --- */
.whoop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
}

.whoop-stat {
  background: var(--input);
  border: var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
}

.whoop-stat-val,
.whoop-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.whoop-stat-value.green { color: var(--green); }
.whoop-stat-value.amber { color: var(--amber); }
.whoop-stat-value.red   { color: var(--red); }

.whoop-stat-value .whoop-unit {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 2px;
}

.whoop-divider {
  border-top: var(--border);
  margin: 16px 0 0;
}

.whoop-stat-label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --- Utility --- */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }

.flex         { display: flex; }
.items-center { align-items: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.text-muted   { color: var(--muted); }
.text-sm      { font-size: 13px; }
.text-xs      { font-size: 11px; }
.font-bold    { font-weight: 700; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator  { display: inline-flex; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* --- Responsive: collapse sidebar below 768px --- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .page-body { padding: 20px 16px; }
  .topbar { padding: 16px 20px; }
  .deficit-number { font-size: 40px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .macros-row { grid-template-columns: repeat(3, 1fr); }
  .whoop-grid { grid-template-columns: repeat(2, 1fr); }
}
