:root, [data-theme="light"] {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  --color-bg: #f7f6f2;
  --color-surface: #f9f8f5;
  --color-surface-2: #fbfbf9;
  --color-border: #d4d1ca;
  --color-text: #28251d;
  --color-text-muted: #7a7974;
  --color-primary: #01696f;
  --color-primary-hover: #0c4e54;
  --color-success: #437a22;
  --color-blue: #006494;
  --color-orange: #da7101;
  --color-error: #a12c7b;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(40, 37, 29, 0.06);
  --shadow-md: 0 8px 20px rgba(40, 37, 29, 0.08);

  --font-body: 'Satoshi', 'Inter', sans-serif;
}

[data-theme="dark"] {
  --color-bg: #171614;
  --color-surface: #1c1b19;
  --color-surface-2: #201f1d;
  --color-border: #393836;
  --color-text: #cdccca;
  --color-text-muted: #979694;
  --color-primary: #4f98a3;
  --color-primary-hover: #227f8b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 12px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: none; text-size-adjust: none; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  padding-bottom: 5.5rem;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
input, textarea, select {
  width: 100%;
  padding: 0.95rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  color: var(--color-text);
}
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  background: var(--color-surface);
  padding: .5rem .75rem;
  border-radius: var(--radius-md);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--color-bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.logo {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--color-primary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.theme-toggle,
.text-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle {
  min-width: 44px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
}

.app-shell,
.auth-shell,
.form-shell {
  width: min(100%, 42rem);
  margin: 0 auto;
  padding: var(--space-4);
  display: grid;
  gap: var(--space-4);
}

.auth-shell {
  min-height: calc(100dvh - 5rem);
  place-items: center;
}

.auth-card,
.hero-card,
.list-card,
.form-card,
.chart-card,
.stat-card,
.insight-card {
  background: var(--color-surface);
  border: 1px solid rgba(40, 37, 29, 0.10);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.auth-card,
.hero-card,
.list-card,
.form-card,
.chart-card,
.stat-card,
.insight-card {
  padding: var(--space-4);
}

.hero-card {
  display: grid;
  gap: var(--space-4);
}

.hero-card--compact {
  padding-bottom: var(--space-3);
}

.eyebrow {
  margin: 0 0 .25rem;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--color-text-muted);
}

h1 {
  margin: 0;
  font-size: var(--text-xl);
  line-height: 1.15;
}

h2 {
  margin: 0;
  font-size: var(--text-lg);
}

.muted {
  color: var(--color-text-muted);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.quick-actions-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.quick-capture-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.quick-capture-card {
  background: var(--color-surface);
  border: 1px solid rgba(40, 37, 29, 0.10);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.quick-capture-card h3 {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.quick-capture-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.quick-capture-btn {
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.quick-capture-btn:hover {
  background: var(--color-primary-hover);
}

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

.quick-capture-btn[data-method=""] {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.timer-btn {
  background: var(--color-blue);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.timer-btn:hover {
  background: #004a80;
}

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

.timer-stop-btn {
  background: var(--color-orange);
}

.timer-stop-btn:hover {
  background: #b85e00;
}

.now-panel {
  margin-bottom: var(--space-4);
}

.now-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: color-mix(in srgb, var(--color-primary) 8%, var(--color-surface));
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  border: 1px solid color-mix(in srgb, var(--color-primary) 20%, var(--color-border));
}

.now-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.now-emoji {
  font-size: 1.25rem;
}

.now-label {
  color: var(--color-text-muted);
  flex: 1;
}

.now-time {
  font-weight: 600;
  color: var(--color-text);
}

.action-card {
  min-height: 92px;
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  display: flex;
  align-items: end;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.action-card.feed { background: color-mix(in srgb, var(--color-primary) 12%, var(--color-surface)); }
.action-card.sleep { background: color-mix(in srgb, var(--color-blue) 12%, var(--color-surface)); }
.action-card.diaper { background: color-mix(in srgb, var(--color-success) 12%, var(--color-surface)); }
.action-card.tummy { background: color-mix(in srgb, var(--color-blue) 10%, var(--color-surface)); }
.action-card.medicine { background: color-mix(in srgb, var(--color-error) 10%, var(--color-surface)); }
.action-card.note { background: color-mix(in srgb, var(--color-orange) 14%, var(--color-surface)); }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.chart-head {
  margin-bottom: var(--space-3);
}

.timeline {
  display: grid;
  gap: var(--space-3);
}

.timeline-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: var(--space-3);
  align-items: start;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  margin-top: .45rem;
  border-radius: 999px;
  background: var(--color-primary);
}

.timeline-top {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: .25rem;
}

.timeline-body p,
.timeline-body small {
  margin: 0;
}

.timeline-body small {
  color: var(--color-text-muted);
}

.comment-line {
  display: block;
  margin-top: .35rem;
  color: var(--color-text-muted);
}

.summary-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
  margin: 0;
}

.dashboard-grid {
  display: grid;
  gap: .9rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-grid--insights {
  grid-template-columns: 1fr;
}

.stat-card,
.insight-card {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.dashboard-card,
.insight-card {
  min-height: 116px;
  justify-content: center;
}

.stat-label {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.stat-number {
  font-size: clamp(1.35rem, 1.1rem + 1.2vw, 2rem);
  line-height: 1.1;
}

.chart-stack {
  display: grid;
  gap: var(--space-4);
}

.chart-card {
  overflow: hidden;
}

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

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.stack-form {
  display: grid;
  gap: var(--space-4);
}

.stack-form label {
  display: grid;
  gap: .45rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.btn {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius-lg);
  padding: .85rem 1.1rem;
  font-weight: 700;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
}

.btn-large {
  min-height: 56px;
  font-size: var(--text-base);
}

.alert {
  background: color-mix(in srgb, var(--color-error) 10%, var(--color-surface));
  color: var(--color-text);
  border: 1px solid color-mix(in srgb, var(--color-error) 30%, var(--color-border));
  padding: .85rem 1rem;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
}

.collapsible-fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

.collapsible-toggle {
  display: block;
  padding: 0;
  margin: 0;
}

.toggle-btn {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-weight: 600;
  font-size: inherit;
  padding: 0;
  text-align: left;
}

.toggle-btn:hover {
  text-decoration: underline;
}

.collapsible-body {
  margin-top: var(--space-3);
}

.collapsible-body[hidden] {
  display: none;
}

.caregiver-group {
  border: none;
  padding: 0;
  margin: 0;
}

.pill-group {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}

.pill-option {
  position: relative;
}

.pill-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pill-option span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 48px;
  padding: .65rem 1rem;
  border-radius: 999px;
  background: #eef2ff;
  color: #1f2937;
  font-weight: 700;
}

.pill-option input:checked + span {
  background: #0f766e;
  color: #fff;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .5rem;
  padding: .75rem;
  background: color-mix(in srgb, var(--color-bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-border);
  z-index: 30;
}

.bottom-nav a {
  min-height: 48px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.bottom-nav a.active {
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 700;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toast {
  animation: slideUp 0.3s ease;
}

@media (max-width: 720px) {
  .form-row {
    grid-template-columns: 1fr;
  }

  .timeline-top {
    flex-direction: column;
    gap: .15rem;
  }
}

@media (min-width: 768px) {
  .app-shell,
  .auth-shell,
  .form-shell {
    padding: var(--space-6);
  }

  .hero-card {
    grid-template-columns: 1.1fr .9fr;
    align-items: start;
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .dashboard-grid--insights {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chart-wrap {
    height: 250px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.lang-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.lang-toggle .text-link {
  padding: 0 .6rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  opacity: 0.8;
}

.lang-toggle .text-link.active-lang {
  opacity: 1;
  font-weight: 700;
  background: var(--color-surface-2);
}

/* Logs View */
.logs-view {
  padding: var(--space-4);
}

/* View Navigation */
.view-nav {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  border-bottom: 2px solid var(--color-border);
  overflow-x: auto;
}

.view-nav-link {
  padding: var(--space-2) var(--space-3);
  border: none;
  background: none;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.2s ease;
}

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

.view-nav-link.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.logs-container {
  margin-top: var(--space-4);
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
}

.logs-table thead {
  background: color-mix(in srgb, var(--color-primary) 8%, var(--color-surface-2));
  border-bottom: 2px solid var(--color-border);
}

.logs-table th {
  padding: var(--space-3);
  text-align: left;
  font-weight: 600;
  color: var(--color-text);
  font-size: var(--text-sm);
}

.logs-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background 0.2s ease;
}

.logs-table tbody tr:hover {
  background: var(--color-surface-2);
}

.logs-table td {
  padding: var(--space-3);
  vertical-align: top;
  font-size: var(--text-sm);
}

.log-date {
  min-width: 80px;
}

.date-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.date-group .date {
  font-weight: 600;
  color: var(--color-text);
}

.date-group .time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.log-type {
  min-width: 120px;
}

.entry-type-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--color-surface-2);
  color: var(--color-text);
}

.entry-type-feed {
  background: color-mix(in srgb, #4CAF50 15%, var(--color-surface-2));
  color: #2E7D32;
}

.entry-type-sleep {
  background: color-mix(in srgb, #2196F3 15%, var(--color-surface-2));
  color: #1565C0;
}

.entry-type-diaper {
  background: color-mix(in srgb, #FF9800 15%, var(--color-surface-2));
  color: #E65100;
}

.entry-type-medicine {
  background: color-mix(in srgb, #9C27B0 15%, var(--color-surface-2));
  color: #6A1B9A;
}

.entry-type-tummy_time {
  background: color-mix(in srgb, #FF5722 15%, var(--color-surface-2));
  color: #D84315;
}

.entry-type-measurement {
  background: color-mix(in srgb, #009688 15%, var(--color-surface-2));
  color: #00695C;
}

.log-details {
  min-width: 200px;
  flex: 1;
}

.entry-details {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--color-text);
}

.entry-caregiver {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.log-actions {
  white-space: nowrap;
  text-align: right;
  min-width: 80px;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.2rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 0.2s ease;
}

.btn-icon:hover {
  background: var(--color-surface-2);
}

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

.empty-state {
  text-align: center;
  padding: var(--space-6);
  color: var(--color-text-muted);
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: -1;
}

.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
  margin: 0;
  font-size: var(--text-lg);
  color: var(--color-text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  color: var(--color-text-muted);
  transition: color 0.2s ease;
}

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

.edit-form {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.edit-form fieldset {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border: none;
  padding: 0;
  margin: 0;
}

.edit-form label {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.edit-form input,
.edit-form select,
.edit-form textarea {
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: inherit;
}

.edit-form input:focus,
.edit-form select:focus,
.edit-form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
}

.modal-actions .btn {
  flex: 1;
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
  .logs-table thead {
    display: none;
  }

  .logs-table,
  .logs-table tbody,
  .logs-table tr,
  .logs-table td {
    display: block;
    width: 100%;
  }

  .logs-table tr {
    margin-bottom: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    background: var(--color-surface-2);
  }

  .logs-table td {
    padding: var(--space-2) 0;
    border: none;
    position: relative;
  }

  .log-date::before,
  .log-type::before,
  .log-details::before,
  .log-actions::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    margin-bottom: 0.25rem;
  }

  .log-actions {
    display: flex;
    gap: var(--space-2);
    text-align: left;
    margin-top: var(--space-2);
  }

  .modal-content {
    width: 95%;
    max-height: 100vh;
  }
}