/* Ainult tume režiim */
:root {
  --bg: #121118;
  --surface: #1e1c27;
  --text: #f2f1f7;
  --text-dim: #9d9aae;
  --border: #2b2937;
  --sleep: #6366f1;
  --sleep-soft: #a5a7f8;
  --wake: #f59e0b;
  --feed: #10b981;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.28);
  --radius: 18px;
}
:root { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

.app { max-width: 520px; margin: 0 auto; padding: 20px 16px 56px; }

/* Header */
.app-header {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 22px; padding-top: env(safe-area-inset-top);
}
.app-header__home {
  display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0;
  background: none; border: 0; padding: 0; cursor: pointer; color: inherit;
  font-family: inherit; text-align: left; -webkit-tap-highlight-color: transparent;
}
.app-header__text { min-width: 0; }
.app-header__icon {
  font-size: 40px; width: 52px; height: 52px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.app-header__title { display: block; margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.app-header__sub { display: block; margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }
.hamburger {
  flex: 0 0 auto; background: none; border: 0; cursor: pointer;
  padding: 8px 4px; display: flex; flex-direction: column; gap: 5px;
  -webkit-tap-highlight-color: transparent;
}
.hamburger span { display: block; width: 24px; height: 2px; background: var(--text); border-radius: 2px; }
.menu[hidden] { display: none; }
.menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 80;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); padding: 6px; min-width: 190px;
}
.menu__item {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  color: var(--text); font-size: 15px; font-weight: 600; padding: 12px 14px;
  border-radius: 10px; cursor: pointer; font-family: inherit;
}
.menu__item:active { background: var(--bg); }
#view-home[hidden], #view-stats[hidden] { display: none; }

/* Kolm nuppu */
.actions {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px;
}
.status { display: flex; flex-direction: column; gap: 5px; margin: 0 4px 24px; }
.status__item { font-size: 13.5px; color: var(--text-dim); font-weight: 600; }
.status__item:empty { display: none; }

/* Statistika vaade */
.stats-title { font-size: 24px; font-weight: 800; margin: 4px 2px 14px; }
.seg { display: flex; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.seg__btn { flex: 1; background: none; border: 0; color: var(--text-dim); font-size: 13.5px; font-weight: 700; padding: 9px 6px; border-radius: 9px; cursor: pointer; font-family: inherit; }
.seg__btn.is-active { background: var(--sleep); color: #fff; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.kpi__val { font-size: 25px; font-weight: 800; letter-spacing: -.01em; }
.kpi__lbl { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 14px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card__title { font-size: 12px; font-weight: 700; margin: 0 0 14px 2px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.chart__bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; }
.chart__col { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; height: 100%; }
.chart__bar-wrap { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.chart__bar { width: 66%; max-width: 22px; border-radius: 5px 5px 0 0; min-height: 3px; transition: height .35s ease; }
.chart__val { font-size: 10px; color: var(--text-dim); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.chart__lbl { font-size: 10px; color: var(--text-dim); margin-top: 6px; height: 12px; white-space: nowrap; }
.chart__empty { color: var(--text-dim); font-size: 14px; text-align: center; padding: 34px 0; }
.action {
  border: 1.5px solid transparent; cursor: pointer; border-radius: var(--radius);
  padding: 20px 8px; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700;
  transition: transform .12s ease, filter .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.action:active { transform: scale(.95); filter: brightness(1.3); }
.action__emoji { font-size: 30px; line-height: 1; }
.action--sleep { border-color: var(--sleep); background: rgba(99,102,241,.12); color: #aab0f9; }
.action--wake  { border-color: var(--wake); background: rgba(245,158,11,.12); color: #f6bd5f; }
.action--feed  { border-color: var(--feed); background: rgba(16,185,129,.12); color: #45d8a7; }

/* Nimekiri */
.day {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); margin: 22px 4px 10px; font-weight: 700;
}
.list .day:first-child { margin-top: 0; }
.entry {
  width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; box-shadow: var(--shadow); color: var(--text);
  -webkit-tap-highlight-color: transparent; transition: transform .1s ease;
  font-family: inherit;
}
.entry:active { transform: scale(.99); }

/* Nipsamisega kustutamine (swipe vasakule) */
.entry-wrap { position: relative; margin-bottom: 8px; border-radius: 14px; overflow: hidden; }
.entry-wrap .entry { position: relative; z-index: 1; margin-bottom: 0; touch-action: pan-y; }
.entry-wrap .entry.is-animating { transition: transform .2s ease; }
.entry-delete {
  position: absolute; inset: 0; width: 100%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: flex-end; padding-right: 20px;
  background: var(--danger); color: #fff; font-weight: 700; font-size: 15px;
  border-radius: 14px; font-family: inherit;
}
.entry__emoji {
  font-size: 20px; width: 36px; height: 36px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; border-radius: 10px;
}
.entry--sleep .entry__emoji { background: rgba(99,102,241,.14); }
.entry--wake  .entry__emoji { background: rgba(245,158,11,.16); }
.entry--feed  .entry__emoji { background: rgba(16,185,129,.16); }
.entry__body { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.entry__label { font-weight: 600; font-size: 15px; }
.entry__note {
  font-size: 13px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entry__dur { font-size: 13px; color: var(--sleep-soft); font-weight: 600; }
.entry__time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-dim); font-size: 15px; }

.empty { text-align: center; color: var(--text-dim); padding: 56px 20px; line-height: 1.7; font-size: 15px; }

/* Muutmise aken */
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(10,9,20,.45); }
.modal__sheet {
  position: relative; background: var(--surface); width: 100%; max-width: 520px;
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,.22); animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal__title { margin: 0 0 4px; font-size: 18px; font-weight: 800; }

.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin: 14px 2px 6px; }
.field {
  width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 16px; font-family: inherit;
}
.field:focus { outline: 2px solid var(--sleep); outline-offset: 1px; }
textarea.field { resize: vertical; }

.type-select { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.type-select button {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 12px; padding: 12px 4px; font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.type-select button.is-active { border-color: var(--sleep); background: rgba(99,102,241,.12); color: var(--sleep); }

.modal__actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.btn { flex: 1; border: none; border-radius: 12px; padding: 14px; font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit; }
.btn--primary { background: var(--sleep); color: #fff; }
.btn--ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn--danger { background: transparent; color: var(--danger); flex-basis: 100%; padding: 12px; }

/* Teavitus */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #1c1b22; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.3);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  z-index: 60; max-width: 90%; text-align: center;
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }
.toast--error { background: var(--danger); }

/* Kuupäev + kellaaeg kõrvuti */
.field-row { display: flex; gap: 12px; }
.field-col { flex: 1; min-width: 0; }
.field-col .field { width: 100%; }
.field--time { text-align: left; cursor: pointer; font-variant-numeric: tabular-nums; }
.date-field { position: relative; }
.date-native {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; margin: 0; padding: 0; border: 0; background: none;
  -webkit-appearance: none; appearance: none;
}

/* Kellaaja ratas + sisselogimine peidus vaikimisi */
.timepicker[hidden], .login[hidden] { display: none; }

/* Kellaaja ratas */
.timepicker { position: fixed; inset: 0; z-index: 70; display: flex; align-items: flex-end; justify-content: center; }
.timepicker__backdrop { position: absolute; inset: 0; background: rgba(10,9,20,.5); touch-action: none; }
.timepicker__sheet {
  position: relative; background: var(--surface); width: 100%; max-width: 520px;
  border-radius: 22px 22px 0 0; padding: 16px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,.3); animation: slideUp .22s ease; touch-action: none;
}
.timepicker__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.timepicker__title { font-weight: 700; font-size: 16px; }
.btn--sm { flex: 0 0 auto; padding: 9px 20px; font-size: 14px; }

.wheels { position: relative; display: flex; height: 220px; touch-action: none; }
.wheel {
  flex: 1; height: 220px; overflow-y: scroll; scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
  overscroll-behavior: contain; touch-action: pan-y;
}
.wheel::-webkit-scrollbar { display: none; }
#wheel-h { text-align: right; padding-right: 30px; }
#wheel-m { text-align: left; padding-left: 30px; }
.wheel__pad { height: 88px; }
.wheel__item {
  height: 44px; line-height: 44px; scroll-snap-align: center;
  font-size: 32px; font-weight: 700; color: var(--text-dim);
  font-variant-numeric: tabular-nums; transition: color .12s ease;
}
.wheel__item.is-sel { color: var(--sleep-soft); }
.wheel__colon {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: 30px; font-weight: 800; color: var(--text-dim); pointer-events: none;
}
.wheel__band {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: calc(100% - 24px); height: 46px; border-radius: 12px;
  background: rgba(99,102,241,.12); pointer-events: none;
}

/* Sisselogimine */
.login { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.login__card { width: 100%; max-width: 340px; text-align: center; }
.login__icon { margin: 0 auto 18px; }
.login__title { font-size: 28px; font-weight: 800; margin: 0 0 4px; letter-spacing: -.02em; }
.login__sub { color: var(--text-dim); margin: 0 0 24px; font-size: 14px; }
.login__card .field { margin-bottom: 14px; }
.login__remember { display: flex; align-items: center; gap: 8px; justify-content: center; color: var(--text-dim); font-size: 14px; margin-bottom: 20px; cursor: pointer; }
.login__remember input { width: 18px; height: 18px; accent-color: var(--sleep); }
.login__error { color: var(--danger); font-size: 14px; margin-top: 14px; }
.login .btn--primary { width: 100%; }
