/* ========================================
   Digital Twin — Design Tokens
   ======================================== */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255,255,255,0.03);
  --bg-card-hover: rgba(255,255,255,0.06);
  --text-primary: #f0f0f5;
  --text-secondary: #8a8a9a;
  --text-muted: #55556a;
  --accent: #10b981;
  --accent-secondary: #06b6d4;
  --blue: #3b82f6;
  --cyan: #06b6d4;
  --success: #22c55e;
  --error: #f87171;
  --warning: #fbbf24;
  --border-subtle: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --gradient-primary: linear-gradient(135deg, #10b981, #06b6d4);
  --gradient-text: linear-gradient(135deg, #34d399, #22d3ee);
  --gradient-glow: linear-gradient(135deg, rgba(16,185,129,0.15), rgba(6,182,212,0.15));
  --radius: 12px;
  --radius-lg: 20px;
}

/* ========================================
   Reset & Base
   ======================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  padding-bottom: 80px;
  min-height: 100vh;
}

/* ========================================
   Login View
   ======================================== */

.login-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 4px;
  background: var(--gradient-text);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-card .login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.pin-input-wrapper {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 24px;
}

.pin-digit {
  width: 52px;
  height: 60px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  font-family: 'Outfit', sans-serif;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
  -webkit-text-security: disc;
}

.pin-digit:focus {
  border-color: var(--accent);
}

.login-error {
  color: var(--error);
  font-size: 13px;
  margin-top: -12px;
  margin-bottom: 16px;
  display: none;
}

.login-error.visible {
  display: block;
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--gradient-primary);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-btn:hover { opacity: 0.9; }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========================================
   Bottom Navigation
   ======================================== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
  text-decoration: none;
}

.nav-item.active { color: var(--accent); }
.nav-item:hover { color: var(--text-secondary); }

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ========================================
   Dashboard View
   ======================================== */

.dashboard-view { padding-top: 24px; }

.dashboard-header {
  margin-bottom: 24px;
}

.dashboard-header h1 {
  font-size: 22px;
  margin-bottom: 4px;
}

.dashboard-header .date-label {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Metric cards grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px;
}

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

.metric-card .value {
  font-family: 'Outfit', sans-serif;
  font-size: 24px;
  font-weight: 700;
}

.metric-card .unit {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}

.metric-card .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.metric-card.recovery .value { color: var(--accent); }
.metric-card.hrv .value { color: var(--accent-secondary); }
.metric-card.sleep .value { color: var(--blue); }
.metric-card.strain .value { color: var(--warning); }

/* Section cards */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.section-card .section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Quick actions */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-secondary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.quick-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.quick-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Water progress bar */
.water-bar {
  height: 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.water-bar-fill {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: 4px;
  transition: width 0.3s;
}

/* Nutrition summary row */
.macro-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}

.macro-row .macro-label { color: var(--text-secondary); }
.macro-row .macro-value { font-weight: 600; }

/* Digest card */
.digest-content {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.digest-content p {
  margin-bottom: 8px;
}

/* Weather inline */
.weather-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.weather-temp {
  font-family: 'Outfit', sans-serif;
  font-size: 28px;
  font-weight: 700;
}

.weather-details {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Connect prompt */
.connect-prompt {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.connect-prompt a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

/* ========================================
   Log Hub View
   ======================================== */

.log-hub { padding-top: 24px; }

.log-hub h1 {
  font-size: 22px;
  margin-bottom: 20px;
}

.log-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.log-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
}

.log-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.log-card svg {
  width: 28px;
  height: 28px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.log-card span {
  font-size: 13px;
  font-weight: 600;
}

/* ========================================
   Form View
   ======================================== */

.form-view { padding-top: 24px; }

.form-view h1 {
  font-size: 22px;
  margin-bottom: 24px;
}

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

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

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.5;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-muted); }

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a8a9a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

/* Slider (RPE, mood, etc) */
.slider-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-group input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  outline: none;
  border: none;
  padding: 0;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gradient-primary);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
}

.slider-value {
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 700;
  min-width: 32px;
  text-align: center;
  color: var(--accent);
}

/* Option buttons (workout type, etc) */
.option-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.option-btn {
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.option-btn.active {
  border-color: var(--accent);
  background: rgba(16,185,129,0.08);
  color: var(--text-primary);
}

/* Form actions */
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 28px;
}

.btn {
  flex: 1;
  padding: 14px;
  border-radius: 10px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  border: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-secondary {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.btn-danger {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
  color: var(--error);
}

.btn:hover { opacity: 0.9; }

/* ========================================
   Chat View
   ======================================== */

.chat-view { padding-top: 24px; }

.chat-view h1 {
  font-size: 22px;
  margin-bottom: 16px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 200px;
}

.chat-msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--gradient-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.ai {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: 72px;
  background: var(--bg-primary);
  padding: 8px 0;
}

.chat-input-row input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14px;
  outline: none;
}

.chat-input-row input:focus { border-color: var(--accent); }
.chat-input-row input::placeholder { color: var(--text-muted); }

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-send-btn:disabled { opacity: 0.4; }

.chat-send-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.quick-prompts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.quick-prompt-btn {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.quick-prompt-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* ========================================
   Settings View
   ======================================== */

.settings-view { padding-top: 24px; }

.settings-view h1 {
  font-size: 22px;
  margin-bottom: 20px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h2 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.settings-row:hover { background: var(--bg-card-hover); }

.settings-row .settings-label {
  font-size: 14px;
  font-weight: 500;
}

.settings-row .settings-value {
  font-size: 13px;
  color: var(--text-muted);
}

.settings-row .settings-chevron {
  color: var(--text-muted);
  font-size: 16px;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.status-badge.connected {
  background: rgba(34,197,94,0.1);
  color: var(--success);
}

.status-badge.disconnected {
  background: rgba(248,113,113,0.1);
  color: var(--error);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ========================================
   History View
   ======================================== */

.history-view { padding-top: 24px; }

.history-view h1 {
  font-size: 22px;
  margin-bottom: 16px;
}

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-select {
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a9a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.filter-select:focus { border-color: var(--accent); }

/* List items */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.list-item:hover { background: var(--bg-card-hover); }

.list-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}

.list-icon.meal { background: rgba(251,191,36,0.1); color: var(--warning); }
.list-icon.water { background: rgba(59,130,246,0.1); color: var(--blue); }
.list-icon.supplement { background: rgba(16,185,129,0.1); color: var(--accent); }
.list-icon.workout { background: rgba(248,113,113,0.1); color: var(--error); }
.list-icon.journal { background: rgba(139,92,246,0.1); color: #8b5cf6; }
.list-icon.pt { background: rgba(6,182,212,0.1); color: var(--cyan); }

.list-details {
  flex: 1;
  min-width: 0;
}

.list-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.list-badge {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

/* Date group header */
.date-group {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 16px 0 8px;
}

/* ========================================
   Empty / Loading / Error States
   ======================================== */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 4px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto 12px;
}

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

.error-banner {
  padding: 12px 16px;
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: 10px;
  color: var(--error);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ========================================
   Desktop Adjustments
   ======================================== */

@media (min-width: 768px) {
  #app {
    max-width: 600px;
  }

  .bottom-nav {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }
}
