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

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --blue:      #007AFF;
  --green:     #34C759;
  --red:       #FF3B30;
  --gray-1:    #8E8E93;
  --gray-6:    #F2F2F7;
  --bg:        #F2F2F7;
  --card:      #FFFFFF;
  --text:      #000000;
  --text-2:    #6C6C70;
  --sep:       #C6C6C8;
  --tab-h:     83px;
}

/* ── Dark theme ────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:     #000000;
  --card:   #1C1C1E;
  --text:   #FFFFFF;
  --text-2: #AEAEB2;
  --sep:    #3A3A3C;
  --gray-6: #2C2C2E;
}

[data-theme="dark"] .tab-bar {
  background: rgba(28,28,30,.88);
  border-top-color: #3A3A3C;
}

[data-theme="dark"] .period-tabs { background: rgba(116,116,128,.2); }
[data-theme="dark"] .period-tab.active { background: #3A3A3C; box-shadow: none; }

[data-theme="dark"] .modal { background: #1C1C1E; }
[data-theme="dark"] .form-input { background: #2C2C2E; border-color: #3A3A3C; color: #fff; }
[data-theme="dark"] .form-input:focus { background: #3A3A3C; border-color: var(--blue); }

[data-theme="dark"] .btn-secondary { background: #3A3A3C; color: #fff; }

/* ── Auth pages ────────────────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

.auth-subtitle {
  font-size: 16px;
  color: var(--text-2);
  margin-top: 8px;
  margin-bottom: 28px;
}

.auth-card {
  width: 100%;
  max-width: 340px;
}

.auth-error {
  background: rgba(255, 59, 48, .12);
  color: var(--red);
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  text-align: center;
}

/* ── User grid (login) ─────────────────────────────────────────────────────── */
.user-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.user-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 12px;
  width: 100px;
  background: var(--card);
  border-radius: 16px;
  border: none;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  transition: transform .1s, opacity .1s;
  -webkit-tap-highlight-color: transparent;
}

.user-card:active { transform: scale(.96); opacity: .85; }

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar-add {
  background: var(--gray-6);
  color: var(--text-2);
  font-size: 28px;
  font-weight: 300;
}

.user-card-name {
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-btn {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  padding: 0 0 20px;
  display: block;
}

/* ── PIN input ─────────────────────────────────────────────────────────────── */
.pin-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 4px;
}

.pin-digit, .del-pin {
  width: 56px;
  height: 64px;
  border: 1.5px solid var(--sep);
  border-radius: 14px;
  background: var(--gray-6);
  color: var(--text);
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  outline: none;
  -webkit-text-security: disc;
  caret-color: transparent;
  transition: border-color .2s, background .2s;
}

.pin-digit:focus, .del-pin:focus {
  border-color: var(--blue);
  background: var(--card);
}

/* ── Logout button ─────────────────────────────────────────────────────────── */
.btn-logout {
  position: fixed;
  top: 14px;
  left: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  text-decoration: none;
  z-index: 50;
  transition: background .2s;
}

.btn-logout:active { background: var(--gray-6); }

/* ── Theme toggle button ───────────────────────────────────────────────────── */
.btn-theme {
  position: fixed;
  top: 14px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 50;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: background .2s;
}

/* ── User name ─────────────────────────────────────────────────────────────── */
.user-name {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  margin-top: 6px;
  margin-bottom: 2px;
  padding: 2px 6px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}

.user-name:active { background: var(--gray-6); }

.name-edit-icon {
  color: var(--text-2);
  opacity: .5;
  flex-shrink: 0;
}

.name-input {
  font-size: 20px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-bottom: 2px solid var(--blue);
  background: transparent;
  color: var(--text);
  text-align: center;
  outline: none;
  width: 180px;
  max-width: 100%;
}

/* ── Base ──────────────────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ─────────────────────────────────────────────────────────────── */
.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
}

/* ── Page ──────────────────────────────────────────────────────────────────── */
.page {
  padding: 0 16px;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.page-header {
  padding: 56px 0 24px;
  text-align: center;
}

.logo {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 5px;
  color: var(--blue);
}

.subtitle {
  font-size: 14px;
  color: var(--text-2);
  margin-top: 4px;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
}

/* ── Status card ───────────────────────────────────────────────────────────── */
.status-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 20px;
}

.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gray-1);
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.is-active {
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   rgba(52,199,89,.5); }
  70%  { box-shadow: 0 0 0 10px rgba(52,199,89,0);  }
  100% { box-shadow: 0 0 0 0   rgba(52,199,89,0);  }
}

.status-label {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 4px;
}

.status-time {
  font-size: 30px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  min-height: 36px;
}

/* ── Clock button ──────────────────────────────────────────────────────────── */
.clock-btn {
  display: block;
  width: 100%;
  height: 64px;
  border: none;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  margin-bottom: 12px;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.clock-btn:active {
  opacity: .85;
  transform: scale(.98);
}

.clock-btn.is-out {
  background: var(--red);
}

.clock-btn:disabled {
  opacity: .5;
}

/* ── Summary card ──────────────────────────────────────────────────────────── */
.summary-card { text-align: center; }

.summary-label {
  font-size: 12px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}

.summary-total {
  font-size: 52px;
  font-weight: 700;
  letter-spacing: -2px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.summary-sessions {
  font-size: 14px;
  color: var(--text-2);
  margin-top: 6px;
}

/* ── Today's entries ───────────────────────────────────────────────────────── */
.section-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.entries-list { list-style: none; }

.entry-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--sep);
}

.entry-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.entry-range {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.arrow { color: var(--gray-1); font-size: 12px; }

.badge-active {
  font-size: 12px;
  color: var(--green);
  font-weight: 500;
}

.entry-dur {
  font-size: 15px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* ── Tab bar ───────────────────────────────────────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-h);
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--sep);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 8px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-decoration: none;
  color: var(--gray-1);
  font-size: 10px;
  font-weight: 500;
  padding: 0 32px;
  transition: color .2s;
}

.tab.active { color: var(--blue); }

/* ── History page ──────────────────────────────────────────────────────────── */
.history-page { padding: 0 16px; }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  text-align: left;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
}

.btn-export {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── Period tabs ───────────────────────────────────────────────────────────── */
.period-tabs {
  display: flex;
  background: rgba(116,116,128,.12);
  border-radius: 10px;
  padding: 2px;
  margin-bottom: 12px;
}

.period-tab {
  flex: 1;
  text-align: center;
  padding: 7px 0;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: background .2s;
  -webkit-tap-highlight-color: transparent;
}

.period-tab.active {
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

/* ── Total banner ──────────────────────────────────────────────────────────── */
.total-banner { text-align: center; }

.total-label {
  font-size: 12px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 4px;
}

.total-value {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

/* ── Day groups ────────────────────────────────────────────────────────────── */
.day-group { margin-bottom: 16px; }

.day-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
  padding-left: 4px;
}

.history-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--card);
  border-radius: 12px;
  margin-bottom: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.entry-left { display: flex; flex-direction: column; gap: 2px; }

.entry-times {
  font-size: 16px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.entry-note { font-size: 13px; color: var(--text-2); }

.entry-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.entry-dur-h {
  font-size: 15px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:active { background: var(--gray-6); }
.btn-icon.is-delete { color: var(--red); }

/* ── Add entry button ──────────────────────────────────────────────────────── */
.btn-add-entry {
  display: block;
  width: 100%;
  padding: 14px;
  border: 1.5px dashed var(--sep);
  border-radius: 12px;
  background: transparent;
  color: var(--blue);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  margin-bottom: 16px;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-add-entry:active { background: var(--gray-6); }

/* ── Past entry link (index page) ──────────────────────────────────────────── */
.link-past {
  display: block;
  text-align: center;
  font-size: 14px;
  color: var(--blue);
  text-decoration: none;
  padding: 8px 0 4px;
  margin-bottom: 4px;
}

/* ── Secondary action button (e.g. change PIN) ─────────────────────────────── */
.btn-secondary-action {
  display: block;
  width: 100%;
  padding: 14px;
  margin: 24px 0 8px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text-1);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-secondary-action:active { background: var(--bg-2); }

/* ── Delete account button ─────────────────────────────────────────────────── */
.btn-delete-account {
  display: block;
  width: 100%;
  padding: 14px;
  margin: 8px 0 8px;
  border: 1.5px solid var(--red);
  border-radius: 12px;
  background: transparent;
  color: var(--red);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-delete-account:active { background: rgba(255,59,48,.08); }

/* ── States ────────────────────────────────────────────────────────────────── */
.loading, .empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-2);
  font-size: 16px;
}

/* ── Edit modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,.72,0,1);
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 20px;
}

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

.form-label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--sep);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--gray-6);
  color: var(--text);
  appearance: none;
}

.form-input:focus {
  outline: none;
  border-color: var(--blue);
  background: #fff;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  flex: 1;
  height: 50px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn-secondary { background: var(--gray-6); color: var(--text); }
.btn-primary   { background: var(--blue);   color: #fff; }
