@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

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

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e5e5;
  --fg: #1a1a1a;
  --muted: #737373;
  --accent: #2563eb;
  --green: #16a34a;
  --orange: #d97706;
  --font: 'IBM Plex Sans', -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', monospace;
}

html {
  font-size: 15px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.4;
  min-height: 100vh;
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

@media (max-width: 800px) {
  .app {
    display: flex;
    flex-direction: column;
  }
  .sidebar {
    border-right: none;
    border-bottom: none;
    display: contents;
  }
  .sidebar-header {
    order: 1;
    background: var(--surface);
    padding: 1rem;
    border-bottom: 1px solid var(--border);
  }
  .main {
    display: contents;
  }
  .quick-log {
    order: 2;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
  }
  .sidebar .metric,
  .sidebar .withings-status {
    order: 4;
    background: var(--surface);
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .sidebar .metric:last-of-type {
    border-bottom: 1px solid var(--border);
  }
  .main .section {
    order: 5;
    padding: 0 1rem;
  }
  .main .section:first-of-type {
    padding-top: 1rem;
  }
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--muted);
}

.header-btns {
  display: flex;
  gap: 0.4rem;
}

.sync-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.3rem 0.5rem;
  font-size: 0.65rem;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}

.sync-btn:hover {
  border-color: var(--muted);
  color: var(--fg);
}

/* Filter select */
.filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.2rem 0.4rem;
  font-size: 0.6rem;
  border-radius: 3px;
  font-family: var(--font);
  cursor: pointer;
}

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

/* Metric cards */
.metric {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}

.metric:last-child {
  border-bottom: none;
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.2rem;
}

.metric-title {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.metric-date {
  font-size: 0.6rem;
  color: var(--muted);
}

.metric-value {
  font-size: 1.4rem;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: -0.5px;
  line-height: 1.2;
  color: var(--fg);
}

.metric-unit {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--muted);
  margin-left: 0.15rem;
}

.metric-sub {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.metric-row {
  display: flex;
  gap: 1.25rem;
  align-items: baseline;
}

.metric-item {
  display: flex;
  flex-direction: column;
}

.metric-item-label {
  font-size: 0.55rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.metric-item-value {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 500;
}

/* Progress bar */
.progress-bar {
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  margin-top: 0.4rem;
  overflow: hidden;
}

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

.progress-fill.good {
  background: var(--green);
}

.progress-fill.warn {
  background: var(--orange);
}

/* No data state */
.no-data {
  color: var(--muted);
  font-size: 0.7rem;
  font-style: italic;
}

/* Main content */
.main {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  background: var(--bg);
}

.main-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 1rem;
}

.nav-links {
  display: flex;
  gap: 1rem;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  transition: color 0.15s;
}

.nav-link:hover {
  color: var(--fg);
}

/* Quick log */
.quick-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.85rem;
  margin-bottom: 1.25rem;
}

.log-form {
  display: flex;
  gap: 0.5rem;
}

.log-input-wrap {
  flex: 1;
  position: relative;
}

.log-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.5rem 0.7rem;
  border-radius: 3px;
  font-size: 0.8rem;
  font-family: var(--font);
  transition: border-color 0.15s;
}

.log-input:focus {
  outline: none;
  border-color: var(--accent);
}

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

.log-btn {
  background: var(--fg);
  border: none;
  color: white;
  padding: 0.5rem 0.85rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.log-btn:hover {
  opacity: 0.85;
}

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

.log-result {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  min-height: 1rem;
}

.log-result.success {
  color: var(--green);
}

.log-result.error {
  color: #dc2626;
}

/* Spinner */
.spinner {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.hidden {
  display: none;
}

@keyframes spin {
  to { transform: translateY(-50%) rotate(360deg); }
}

/* Section */
.section {
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 0.6rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title span {
  font-size: 0.6rem;
  font-weight: 400;
  text-transform: none;
}

/* Charts */
.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.85rem;
  margin-bottom: 0.85rem;
}

.chart-container {
  height: 160px;
}

/* Meal list */
.meal-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.4rem;
}

.meal-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.meal-text {
  font-size: 0.8rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-kcal {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.meal-time {
  font-size: 0.6rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* Activity log */
.activity-toggle {
  cursor: pointer;
  user-select: none;
}

.activity-toggle:hover {
  color: var(--fg);
}

.activity-list {
  max-height: 250px;
  overflow-y: auto;
}

.activity-list.collapsed {
  display: none;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-msg {
  flex: 1;
}

.activity-type {
  font-size: 0.55rem;
  color: var(--muted);
  text-transform: uppercase;
  margin-top: 0.1rem;
}

.activity-time {
  color: var(--muted);
  font-size: 0.65rem;
  white-space: nowrap;
  margin-left: 0.75rem;
}

/* Workouts list */
.workouts-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.workout-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
}

.workout-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.workout-date {
  font-weight: 500;
  font-size: 0.85rem;
  text-transform: capitalize;
}

.workout-goal {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.workout-goal.good {
  color: var(--green);
  background: rgba(22, 163, 74, 0.1);
}

/* Section actions */
.section-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.link-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
}

.link-btn:hover {
  background: var(--bg);
  color: var(--fg);
}

/* Calorie legend */
.calorie-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.calorie-legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.calorie-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.chart-container-tall {
  height: 180px;
}

/* Modal description */
.modal-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.workout-stats {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.workout-stat {
  text-align: center;
}

.workout-stat-value {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 500;
}

.workout-stat-label {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
}

.workout-activities {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.workout-activity {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Mood display */
.mood-row {
  display: flex;
  gap: 0.85rem;
}

.mood-item {
  text-align: center;
}

.mood-value {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 500;
}

.mood-label {
  font-size: 0.55rem;
  color: var(--muted);
  text-transform: uppercase;
}

/* Withings status */
.withings-status {
  font-size: 0.6rem;
  margin-top: 0.85rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
}

.withings-status a {
  color: var(--accent);
  text-decoration: none;
}

.withings-status .connected {
  color: var(--green);
}

/* Clickable metric */
.metric.clickable {
  cursor: pointer;
  transition: background 0.15s;
}

.metric.clickable:hover {
  background: var(--bg);
}

/* Meal cards - enhanced */
.meal-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.meal-summary {
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.meal-summary:hover {
  background: var(--bg);
}

.meal-info {
  flex: 1;
  min-width: 0;
}

.meal-title {
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.meal-macros {
  font-size: 0.65rem;
  color: var(--muted);
}

.meal-kcal {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
}

.meal-expand {
  color: var(--muted);
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.meal-expand.open {
  transform: rotate(180deg);
}

.meal-details {
  display: none;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.7rem;
}

.meal-details.open {
  display: block;
}

.meal-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  color: var(--muted);
}

.meal-detail-row span:last-child {
  color: var(--fg);
}

.meal-raw {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-style: italic;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 90%;
  max-width: 340px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--fg);
}

/* Checkin form */
.checkin-form {
  padding: 1rem;
}

.checkin-row {
  margin-bottom: 0.85rem;
}

.checkin-row label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slider-wrap input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 2px;
  cursor: pointer;
}

.slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--fg);
  border-radius: 50%;
  cursor: pointer;
}

.slider-value {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 500;
  width: 1.5rem;
  text-align: center;
}

.checkin-form textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.5rem;
  font-size: 0.8rem;
  font-family: var(--font);
  color: var(--fg);
  resize: none;
}

.checkin-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.checkin-submit {
  width: 100%;
  background: var(--fg);
  border: none;
  color: white;
  padding: 0.6rem;
  border-radius: 3px;
  font-size: 0.8rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  margin-top: 0.5rem;
}

.checkin-submit:hover {
  opacity: 0.9;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}
