/* ===== Design Tokens ===== */
:root {
  --bg-base: #0a0e27;
  --bg-navy: #131838;
  --bg-card: rgba(255, 255, 255, 0.05);
  --bg-card-hover: rgba(255, 255, 255, 0.08);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(108, 92, 231, 0.4);
  --divider: rgba(255, 255, 255, 0.06);

  --gradient: linear-gradient(135deg, #6C5CE7, #4A90D9, #45B7D1);
  --purple: #6C5CE7;
  --blue: #4A90D9;
  --cyan: #45B7D1;
  --light-purple: #A29BFE;

  --text-primary: #FFFFFF;
  --text-secondary: #B0B8D1;
  --text-muted: #6B7394;
  --text-accent: #45B7D1;

  --good: #2ED573;
  --warning: #FFA502;
  --bad: #FF4757;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --radius-btn: 14px;
  --radius-card: 20px;
  --radius-modal: 24px;
  --glass-blur: blur(20px) saturate(120%);
}

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

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.1px;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) 0 0 0;
  overflow-x: hidden;
}

/* ===== Login Banner ===== */
.login-banner {
  margin: 20px 0;
  padding: 16px 20px;
  border: 1px solid rgba(108, 92, 231, 0.2);
}
.login-banner-text strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.login-banner-text p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}
.login-banner-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}
.btn-google-sm {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #ffffff;
  color: #1d1d1f;
  border: none;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-google-sm:hover { background: #f0f0f0; }
.btn-google-sm:active { transform: scale(0.98); }
.btn-dismiss {
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
}
.btn-dismiss:hover { color: var(--text-secondary); }

/* ===== User Bar ===== */
.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 4px;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.user-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sync-badge {
  font-size: 10px;
  color: var(--good);
  background: rgba(46, 213, 115, 0.1);
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 500;
}
.btn-logout {
  padding: 4px 12px;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-logout:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* ===== Loading ===== */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  color: var(--text-muted);
  font-size: 15px;
}

/* ===== Layout ===== */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px 96px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Page Header ===== */
.page-header {
  padding: 24px 0 16px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.3px;
}
.header-date {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

/* ===== Period Navigation ===== */
.period-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.period-label {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  flex: 1;
}

/* ===== Glass Card ===== */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-card);
  padding: 20px;
}

/* ===== Today Card ===== */
.today-card {
  margin-bottom: 20px;
  text-align: center;
}
.today-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.today-times {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 12px;
}
.today-time-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.today-time-value {
  font-size: 48px;
  font-weight: 200;
  line-height: 1.0;
  letter-spacing: -1.5px;
  font-variant-numeric: tabular-nums;
}
.today-arrow {
  color: var(--text-muted);
  font-size: 20px;
  margin-top: 16px;
}
.today-duration {
  font-size: 36px;
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -1px;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}
.today-date-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Buttons ===== */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 28px;
  background: var(--gradient);
  color: var(--text-primary);
  border: none;
  border-radius: var(--radius-btn);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.3);
  transition: box-shadow 0.2s, transform 0.1s;
}
.btn-primary:hover {
  box-shadow: 0 6px 24px rgba(108, 92, 231, 0.4);
}
.btn-primary:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.2);
}

.btn-secondary {
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-btn);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.1); }

.btn-danger {
  padding: 12px 24px;
  background: rgba(255, 71, 87, 0.1);
  color: var(--bad);
  border: 1px solid rgba(255, 71, 87, 0.2);
  border-radius: var(--radius-btn);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-danger:hover { background: rgba(255, 71, 87, 0.2); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }

/* ===== Section ===== */
.section-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  margin-bottom: 16px;
  color: var(--text-primary);
}
.records-section {
  margin-top: 32px;
}

/* ===== Sleep Record Card ===== */
.record-card {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-card);
  padding: 16px 20px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  overflow: hidden;
}
.record-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gradient);
}
.record-card:hover {
  background: var(--bg-card-hover);
}
.record-date {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 56px;
}
.record-date-weekday {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
}
.record-times {
  flex: 1;
  text-align: center;
  font-size: 15px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.record-times .arrow {
  color: var(--text-muted);
  margin: 0 6px;
  font-size: 12px;
}
.record-duration {
  font-size: 20px;
  font-weight: 300;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  text-align: right;
}

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

/* ===== Sleep Timing Bar ===== */
.timing-section {
  margin-top: 32px;
}
.timing-chart-wrap {
  padding: 16px 12px;
}
.timing-chart-wrap canvas {
  width: 100%;
}

/* ===== Record Edit Icon ===== */
.record-edit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-left: 8px;
  color: var(--text-muted);
  opacity: 0.4;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.record-card:hover .record-edit {
  opacity: 0.8;
}

/* ===== Show More ===== */
.btn-show-more {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 4px;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-btn);
  color: var(--text-accent);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-show-more:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* ===== Stat Grid ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0 24px;
}
.stat-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-card);
  padding: 16px 12px;
  text-align: center;
}
.stat-value {
  font-size: 28px;
  font-weight: 300;
  line-height: 1.2;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-top: 4px;
}

/* ===== Chart ===== */
.chart-container {
  margin-bottom: 24px;
}
.chart-container canvas {
  width: 100%;
  height: 220px;
  margin-top: 12px;
}

/* ===== Bottom Tab Bar ===== */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: rgba(10, 14, 39, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--divider);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 100;
}
.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active {
  color: var(--cyan);
}
.tab-btn svg {
  transition: color 0.2s;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }

.modal {
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-modal);
  padding: 24px;
  animation: slideUp 0.3s ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.modal-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-group input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-btn);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 17px;
  font-weight: 400;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  color-scheme: dark;
}
.form-group input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-preview {
  text-align: center;
  font-size: 22px;
  font-weight: 300;
  letter-spacing: -0.5px;
  padding: 12px 0;
  min-height: 48px;
}
.form-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text-primary);
  padding: 14px 24px;
  border-radius: var(--radius-btn);
  font-size: 15px;
  z-index: 300;
  animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
}
.toast.hidden { display: none; }

/* ===== Duration Colors ===== */
.duration-good { color: var(--good); }
.duration-warning { color: var(--warning); }
.duration-bad { color: var(--bad); }

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
