:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface2: #24242f;
  --border: #2e2e3a;
  --text: #f0f0f5;
  --muted: #8888a0;
  --accent: #6ee7b7;
  --accent-dim: #34d399;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
}

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

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Login */
#login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, #1a2e28 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  padding: 40px 32px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.logo { font-size: 48px; margin-bottom: 12px; }
.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 28px; }

.login-card input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }

.error { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* Buttons */
.btn {
  padding: 12px 24px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s, opacity .15s;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #0f0f13; }
.btn.primary:hover { background: var(--accent-dim); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
.btn.sm { padding: 8px 16px; font-size: 13px; }
.btn-icon { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px; }

.login-card .btn { width: 100%; }

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  background: rgba(15,15,19,.85);
  backdrop-filter: blur(12px);
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.header-left { display: flex; align-items: center; gap: 10px; }
.logo-sm { font-size: 22px; }
.header h1 { font-size: 18px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; }

#app { max-width: 720px; margin: 0 auto; padding-bottom: 48px; }

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 16px 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
}

.kpi-card.accent {
  background: linear-gradient(135deg, #1a2e28, #1a1a22);
  border-color: rgba(110,231,183,.3);
}

.kpi-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.kpi-value { display: block; font-size: 22px; font-weight: 700; }
.kpi-card.accent .kpi-value { color: var(--accent); }

/* Cards */
.card {
  margin: 0 20px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card h2 { font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 16px; }

.chart-wrap { position: relative; height: 220px; }

/* Compare slider */
.compare-card { overflow: hidden; }

.compare-slider {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  max-height: 420px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface2);
  user-select: none;
}

.compare-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.compare-before-wrap {
  position: absolute;
  inset: 0;
  width: 50%;
  overflow: hidden;
  border-right: 2px solid var(--accent);
}

.compare-before-wrap .compare-img {
  width: 200%;
  max-width: none;
}

.compare-range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: ew-resize;
  z-index: 10;
}

.compare-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 50%;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
}
.compare-handle::before,
.compare-handle::after {
  content: '';
  display: block;
  width: 0; height: 0;
  border: 5px solid transparent;
}
.compare-handle::before { border-right-color: #0f0f13; margin-right: 2px; }
.compare-handle::after { border-left-color: #0f0f13; margin-left: 2px; }

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

.compare-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--muted);
  font-size: 14px;
}

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 12px; }

.timeline-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--surface2);
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color .15s;
}
.timeline-item:hover { border-color: var(--accent); }

.timeline-date { text-align: center; }
.timeline-day { font-size: 22px; font-weight: 700; line-height: 1; }
.timeline-month { font-size: 11px; color: var(--muted); }

.timeline-body { min-width: 0; }
.timeline-weight { font-size: 18px; font-weight: 600; color: var(--accent); margin-bottom: 6px; }
.timeline-photos { display: flex; gap: 8px; }
.timeline-photos img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.timeline-note { font-size: 13px; color: var(--muted); margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  border-top: 1px solid var(--border);
}

@media (min-width: 640px) {
  .modal { align-items: center; padding: 24px; }
  .modal-content { border-radius: var(--radius); max-height: 85dvh; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 18px; font-weight: 600; color: var(--text); margin: 0; }

#entry-form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

#entry-form input[type="date"],
#entry-form input[type="number"],
#entry-form textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
#entry-form input:focus, #entry-form textarea:focus { border-color: var(--accent); }

.photo-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.photo-upload input { display: none; }
.photo-box {
  aspect-ratio: 1;
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s;
  font-size: 13px;
  color: var(--muted);
}
.photo-box:hover { border-color: var(--accent); }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-icon { font-size: 28px; }

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 8px;
}
.form-actions .btn.primary { flex: 1; max-width: 200px; }
