:root {
  --bg-night: #0B1120;
  --bg-surface: #131C31;
  --bg-elevated: #1E293B;
  --border-subtle: #2A3750;
  --text-primary: #E2E8F0;
  --text-muted: #94A3B8;
  --amber: #F59E0B;
  --amber-soft: rgba(245, 158, 11, 0.16);
  --amber-hover: #D97706;
  --sleep-bar: #3B82F6;
  --sleep-bar-soft: rgba(59, 130, 246, 0.25);
  --nap-bar: #10B981;
  --danger: #EF4444;
  --success: #22C55E;
  --radius: 14px;
  --radius-sm: 10px;
  --nav-height: 68px;
}

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

html, body {
  background-color: var(--bg-night);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body {
  padding-bottom: calc(var(--nav-height) + 84px);
}

a {
  color: var(--amber);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(11, 17, 32, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 1.5rem;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Main */
.app-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.tab-panel.active {
  display: flex;
}

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

.card-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.card h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--amber);
}

.kpi-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  color: var(--text-primary);
}

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

.btn-sm {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
  margin-top: 12px;
}

.btn-primary {
  background: var(--amber);
  color: #0B1120;
}
.btn-primary:hover {
  background: var(--amber-hover);
}

.btn-amber {
  background: var(--amber);
  color: #0B1120;
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-subtle);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-muted);
}

.btn-icon {
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.badge-pro {
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

/* Range pills */
.range-pills {
  display: inline-flex;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.pill-btn {
  min-height: 36px;
  padding: 0 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.active {
  background: var(--amber);
  color: #0B1120;
}

/* Timeline 18h -> 18h */
.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 5px;
}

.swatch-sleep { background: var(--sleep-bar); }
.swatch-awake {
  background: repeating-linear-gradient(
    45deg,
    rgba(245, 158, 11, 0.35),
    rgba(245, 158, 11, 0.35) 4px,
    rgba(11, 17, 32, 0.6) 4px,
    rgba(11, 17, 32, 0.6) 8px
  );
  border: 1px solid var(--amber);
}
.swatch-nap { background: var(--nap-bar); }

.timeline-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-x: auto;
}

.timeline-axis {
  display: grid;
  grid-template-columns: 78px 1fr 48px;
  align-items: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-subtle);
}

.timeline-axis-hours {
  display: flex;
  justify-content: space-between;
}

.timeline-row {
  display: grid;
  grid-template-columns: 78px 1fr 48px;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

.timeline-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.timeline-track {
  position: relative;
  height: 22px;
  background: var(--bg-elevated);
  border-radius: 6px;
  overflow: hidden;
}

.timeline-seg-awake {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 4px;
  background: repeating-linear-gradient(
    45deg,
    rgba(245, 158, 11, 0.35),
    rgba(245, 158, 11, 0.35) 4px,
    rgba(11, 17, 32, 0.6) 4px,
    rgba(11, 17, 32, 0.6) 8px
  );
  border: 1px solid rgba(245, 158, 11, 0.6);
}

.timeline-seg-sleep {
  position: absolute;
  top: 2px;
  bottom: 2px;
  background: var(--sleep-bar);
  border-radius: 4px;
}

.timeline-seg-nap {
  position: absolute;
  top: 4px;
  bottom: 4px;
  background: var(--nap-bar);
  border-radius: 4px;
}

.timeline-eff {
  font-size: 0.78rem;
  font-weight: 600;
  text-align: right;
}

/* Nights list */
.nights-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.night-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.night-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.night-item-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.night-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Forms & Chips */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
}

.field span {
  color: var(--text-muted);
  font-weight: 500;
}

input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"],
.input-select {
  min-height: 44px;
  padding: 0 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.stepper-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stepper-ctrl {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stepper-ctrl input {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.step-btn {
  min-width: 44px;
  min-height: 44px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--amber);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}

.chip-group, .rating-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip, .rate-btn {
  min-height: 44px;
  padding: 0 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 0.88rem;
  cursor: pointer;
}

.rate-btn {
  min-width: 44px;
  padding: 0;
  justify-content: center;
}

.chip.active, .rate-btn.active {
  background: var(--amber-soft);
  border-color: var(--amber);
  color: var(--amber);
  font-weight: 600;
}

/* Aids counters */
.aids-counters, .aids-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.aid-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.aid-qty-ctrl {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-preview {
  padding: 12px;
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.92rem;
}

/* ISI Form */
.isi-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.isi-question {
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.isi-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.isi-opt-btn {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px;
}

.isi-opt-btn.active {
  background: var(--amber);
  color: #0B1120;
  font-weight: 700;
}

.isi-history {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

/* Exports & Settings */
.exports-grid, .settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 768px) {
  .exports-grid, .settings-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.export-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  margin-bottom: 8px;
}

.feature-list {
  margin-top: 10px;
  padding-left: 18px;
  font-size: 0.9rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stack-form, .button-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.inline-form input {
  flex: 1;
  min-width: 120px;
}

.transfer-box {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.transfer-box input {
  flex: 1;
}

/* Bottom Nav & FAB */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(19, 28, 49, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 40;
}

.nav-item {
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  min-height: 44px;
}

.nav-item.active {
  color: var(--amber);
}

@media (min-width: 768px) {
  body {
    padding-bottom: 24px;
  }

  .bottom-nav {
    top: 68px;
    left: 0;
    right: auto;
    bottom: 0;
    width: 220px;
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 6px;
    padding: 16px 12px;
    border-top: none;
    border-right: 1px solid var(--border-subtle);
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    min-height: 46px;
  }

  .nav-item.active {
    background: var(--amber-soft);
  }

  .nav-label {
    font-size: 0.92rem;
  }

  .app-main {
    margin-left: 220px;
    max-width: calc(100% - 220px);
    padding: 20px 28px;
  }
}

.nav-icon {
  font-size: 1.2rem;
}

.nav-label {
  font-size: 0.72rem;
  font-weight: 600;
}

.fab-add {
  position: fixed;
  right: 16px;
  bottom: calc(var(--nav-height) + 14px);
  z-index: 35;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  border: none;
  background: var(--amber);
  color: #0B1120;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

@media (min-width: 768px) {
  .fab-add {
    display: none;
  }
}

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

@media (min-width: 640px) {
  .modal {
    align-items: center;
    padding: 16px;
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-sheet {
  position: relative;
  z-index: 61;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 18px 18px 0 0;
  padding: 18px;
}

@media (min-width: 640px) {
  .modal-sheet {
    border-radius: 18px;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.night-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Banners & Toast */
.ios-banner, .consent-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav-height) + 12px);
  z-index: 50;
  background: var(--bg-elevated);
  border: 1px solid var(--amber);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
}

.consent-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--amber);
  color: #0B1120;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.app-footer {
  text-align: center;
  padding: 16px 0;
  font-size: 0.82rem;
}

.btn-link-muted {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px 6px;
}
.btn-link-muted:hover {
  color: var(--amber);
}
