@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg-primary:    #090e1c;
  --bg-secondary:  #0d1427;
  --bg-card:       #111928;
  --bg-input:      #0b1220;
  --border:        #1a2b45;
  --border-hover:  #263d5e;
  --accent:        #38bdf8;
  --accent-soft:   rgba(56, 189, 248, 0.1);
  --accent-glow:   rgba(56, 189, 248, 0.18);
  --success:       #4ade80;
  --success-dim:   rgba(74, 222, 128, 0.08);
  --success-border:rgba(74, 222, 128, 0.25);
  --danger:        #f87171;
  --danger-dim:    rgba(248, 113, 113, 0.08);
  --text-primary:  #dde5f0;
  --text-secondary:#4e6a8a;
  --text-muted:    #2a3d57;
  --top-bar-height:52px;
  --drawer-width:  260px;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ===== TOP BAR ===== */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-bar-height);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 200;
  border-bottom: 1px solid var(--border);
}

.top-bar h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar-icon {
  width: 20px;
  height: 20px;
  color: var(--accent);
  flex-shrink: 0;
}

/* ===== BURGER BUTTON ===== */
.burger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  width: 40px;
  height: 40px;
}

.burger-btn span {
  display: block;
  width: 20px;
  height: 1.5px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: all 0.22s ease;
  transform-origin: center;
}

.burger-btn.open span:nth-child(1) {
  transform: translateY(6.5px) rotate(45deg);
  background: var(--text-primary);
}
.burger-btn.open span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.burger-btn.open span:nth-child(3) {
  transform: translateY(-6.5px) rotate(-45deg);
  background: var(--text-primary);
}

/* ===== DRAWER ===== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--drawer-width);
  background: var(--bg-secondary);
  z-index: 400;
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  padding-top: var(--top-bar-height);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px 20px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  border-left: 2px solid transparent;
}

.drawer-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.drawer-item.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.drawer-item.active svg {
  opacity: 1;
}

/* ===== VIEWS ===== */
.view {
  display: none;
  position: fixed;
  top: var(--top-bar-height);
  left: 0;
  right: 0;
  bottom: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px;
}

.view.active {
  display: block;
}

/* ===== SECTION LABEL ===== */
.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
  margin-top: 4px;
}

/* ===== FORM ===== */
#sleep-form {
  overflow: hidden;
}

.form-group {
  margin-bottom: 24px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 10px;
  letter-spacing: 0.01em;
}

.form-group label .optional {
  font-weight: 400;
  font-size: 12px;
  opacity: 0.55;
}

/* Date input */
input[type="date"] {
  display: block;
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 16px;
  color-scheme: dark;
  font-family: inherit;
  font-weight: 500;
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s;
}

input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Sliders */
.slider-value {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  outline: none;
  touch-action: pan-y;
  cursor: pointer;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--fill, 20%),
    var(--bg-input) var(--fill, 20%),
    var(--bg-input) 100%
  );
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 0 2px var(--accent-glow), 0 2px 8px rgba(0,0,0,0.4);
  transition: box-shadow 0.15s;
}

input[type="range"]::-webkit-slider-thumb:active {
  box-shadow: 0 0 0 5px var(--accent-glow), 0 2px 8px rgba(0,0,0,0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Pill buttons */
.pill-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-group.scale {
  justify-content: space-between;
  flex-wrap: nowrap;
}

.pill {
  flex: 1;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.pill.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.pill:active {
  transform: scale(0.95);
}

/* Scale labels */
.scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Notes */
textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  min-height: 64px;
  transition: border-color 0.15s;
  line-height: 1.5;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea::placeholder {
  color: var(--text-muted);
}

/* Save button */
.btn-save {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #050c18;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  margin-top: 8px;
  margin-bottom: 36px;
  letter-spacing: 0.01em;
}

.btn-save:active {
  opacity: 0.85;
  transform: scale(0.99);
}

/* Today already logged banner */
.today-banner {
  margin-bottom: 20px;
}

.today-banner-inner {
  background: var(--success-dim);
  border: 1px solid var(--success-border);
  border-radius: 12px;
  padding: 14px 16px;
}

.today-banner-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 600;
  color: var(--success);
  margin-bottom: 5px;
}

.today-banner-title svg {
  flex-shrink: 0;
}

.today-banner-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.today-banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.today-banner-edit {
  background: none;
  border: 1px solid var(--success-border);
  color: var(--success);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.today-banner-edit:active {
  background: var(--success-dim);
}

.today-banner-new {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.today-banner-new:active {
  opacity: 0.8;
}

/* Save success screen */
.save-success {
  text-align: center;
  padding: 48px 20px;
}

.success-icon {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--success-dim);
  border: 1px solid var(--success-border);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.success-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.success-meta {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 36px;
  line-height: 1.8;
}

.btn-new-entry {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 11px 24px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-new-entry:active {
  border-color: var(--accent);
  color: var(--accent);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card);
  border: 1px solid var(--success-border);
  color: var(--success);
  padding: 10px 24px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 14px;
  opacity: 0;
  transition: all 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== HISTORY ===== */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.history-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.btn-export {
  padding: 8px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-export:active {
  border-color: var(--accent);
  color: var(--accent);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 36px;
}

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.history-card.expanded {
  border-color: var(--border-hover);
}

.card-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-date {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.card-duration {
  font-size: 15px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.card-meta {
  display: flex;
  gap: 14px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.card-details {
  display: none;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.history-card.expanded .card-details {
  display: block;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
}

.detail-row .detail-label {
  color: var(--text-secondary);
}

.detail-notes {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.5;
  border: 1px solid var(--border);
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.card-actions button {
  flex: 1;
  padding: 10px;
  border: 1px solid;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-edit {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.25);
  color: var(--accent);
}

.btn-delete {
  background: var(--danger-dim);
  border-color: rgba(248, 113, 113, 0.2);
  color: var(--danger);
}

.card-actions button:active {
  opacity: 0.7;
}

/* ===== STATS ===== */
.stats-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

.stats-period {
  flex: 1;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.stats-period.active {
  background: var(--bg-card);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.stats-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

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

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 4px;
  letter-spacing: 0.01em;
}

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 36px;
}

.chart-container h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#sleep-chart {
  width: 100%;
  height: 180px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 48px 20px;
  font-size: 14px;
  line-height: 1.6;
  display: none;
}

.empty-state.show {
  display: block;
}
