/* ── Design Tokens (Dark Mode) ─────────────────────────────────────────────── */
:root {
  --accent: #0A84FF;
  --accent-light: #0A2240;
  --bg: #000000;
  --card-bg: #1C1C1E;
  --secondary-bg: #2C2C2E;
  --text: #FFFFFF;
  --secondary-text: #8E8E93;
  --destructive: #FF453A;
  --green: #30D158;
  --orange: #FF9F0A;
  --purple: #BF5AF2;
  --border: rgba(255, 255, 255, 0.1);
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --tab-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ── Back to Site ──────────────────────────────────────────────────────────── */
.back-home {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  font-size: 16px;
  color: var(--secondary-text);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--border-radius-sm);
  transition: color 0.15s, background 0.15s;
}

.back-home:hover {
  color: var(--text);
  background: var(--secondary-bg);
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
.view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--tab-height) + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Tab Bar ───────────────────────────────────────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  z-index: 100;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--tab-height);
  border: none;
  background: none;
  cursor: pointer;
  color: var(--secondary-text);
  transition: color 0.15s;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* ── Page Headers ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

/* Push the + button to the right without shifting the centred title */
.page-header .btn-icon {
  position: absolute;
  right: 16px;
}

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

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 2px;
  transition: opacity 0.15s;
}

.btn-icon:active {
  opacity: 0.7;
}

/* ── Cards / List ──────────────────────────────────────────────────────────── */
.list-section {
  padding: 0 16px 16px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  overflow: hidden;
}

.card-row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.card-row:last-child {
  border-bottom: none;
}

.card-row:active {
  background: var(--secondary-bg);
}

.card-row-content {
  flex: 1;
  min-width: 0;
}

.card-row-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-row-subtitle {
  font-size: 13px;
  color: var(--secondary-text);
  margin-top: 2px;
}

.card-row-chevron {
  color: var(--secondary-text);
  font-size: 14px;
  flex-shrink: 0;
}

.card-row-delete {
  background: var(--destructive);
  border: none;
  color: white;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s;
}

.card-row:hover .card-row-delete {
  opacity: 1;
}

/* On touch devices always show delete */
@media (hover: none) {
  .card-row-delete {
    opacity: 1;
  }
}

/* ── Empty State ───────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 32px;
  text-align: center;
  gap: 12px;
}

.empty-state-icon {
  font-size: 48px;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.empty-state-message {
  font-size: 15px;
  color: var(--secondary-text);
  line-height: 1.5;
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  width: 100%;
  max-height: 95vh;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
  }
  .modal-content {
    max-width: 520px;
    margin: 0 auto;
    border-radius: 20px;
    max-height: 90vh;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ── Modal Header ──────────────────────────────────────────────────────────── */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 17px;
  cursor: pointer;
  padding: 4px 0;
}

.btn-text.destructive {
  color: var(--destructive);
}

.btn-text:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Form Sections ─────────────────────────────────────────────────────────── */
.form-section {
  margin: 12px 16px 0;
}

.form-section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--secondary-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 4px 6px;
}

.form-card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.form-row:last-child {
  border-bottom: none;
}

.form-label {
  font-size: 15px;
  font-weight: 400;
  flex-shrink: 0;
}

.form-value {
  font-size: 15px;
  color: var(--secondary-text);
  font-weight: 400;
}

.form-input {
  background: none;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--secondary-text);
  text-align: right;
  font-family: inherit;
  min-width: 0;
  max-width: 160px;
  color-scheme: dark;
}

.form-input:focus {
  color: var(--accent);
}

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child {
  border-bottom: none;
}

.toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--secondary-bg);
  border-radius: 15.5px;
  transition: background 0.2s;
}

.toggle input:checked + .toggle-track {
  background: var(--green);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s;
}

.toggle input:checked ~ .toggle-thumb {
  transform: translateX(20px);
}

/* Custom stepper */
.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stepper-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--secondary-bg);
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.1s;
  flex-shrink: 0;
}

.stepper-btn:active {
  background: #3A3A3C;
}

.stepper-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.stepper-value {
  font-size: 15px;
  color: var(--secondary-text);
  min-width: 48px;
  text-align: center;
}

/* ── Rating Picker ─────────────────────────────────────────────────────────── */
.rating-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.rating-row:last-child {
  border-bottom: none;
}

.rating-label {
  font-size: 15px;
  margin-bottom: 8px;
}

.rating-picker {
  display: flex;
  gap: 10px;
}

.rating-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(142, 142, 147, 0.2);
  color: var(--secondary-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.rating-btn.selected {
  background: var(--accent);
  color: white;
}

.tired-remove-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 69, 58, 0.15);
  color: var(--destructive);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tired-remove-btn:active {
  background: rgba(255, 69, 58, 0.3);
}

.rating-hints {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  padding: 0 2px;
  font-size: 11px;
  color: var(--secondary-text);
}

/* ── Star Display ──────────────────────────────────────────────────────────── */
.stars {
  display: flex;
  gap: 2px;
}

.star {
  font-size: 16px;
  line-height: 1;
}

.star.filled {
  color: #FFD700;
}

.star.empty {
  color: #3A3A3C;
}

/* ── Detail View ───────────────────────────────────────────────────────────── */
.detail-section {
  margin: 12px 16px 0;
}

.detail-section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--secondary-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 4px 6px;
}

.detail-card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.detail-row:last-child {
  border-bottom: none;
}

.detail-field {
  font-size: 15px;
  color: var(--secondary-text);
}

.detail-value {
  font-size: 15px;
  font-weight: 500;
  text-align: right;
}

.detail-spacer {
  height: 20px;
}

/* ── Trends / Charts ───────────────────────────────────────────────────────── */
.segmented-control {
  display: flex;
  background: var(--secondary-bg);
  border-radius: var(--border-radius-sm);
  padding: 2px;
  margin: 0 16px 16px;
}

.segmented-btn {
  flex: 1;
  padding: 7px 4px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--secondary-text);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.segmented-btn.active {
  background: #3A3A3C;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.chart-container {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin: 0 16px 16px;
  padding: 16px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.chart-canvas-wrap {
  position: relative;
  height: 200px;
}

.chart-detail-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.chart-detail-date {
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary-text);
  margin-bottom: 6px;
}

.chart-detail-values {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.chart-detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chart-detail-label {
  font-size: 11px;
  color: var(--secondary-text);
}

.chart-detail-value {
  font-size: 17px;
  font-weight: 600;
}

.chart-hint {
  font-size: 12px;
  color: var(--secondary-text);
  text-align: center;
  margin-top: 8px;
}

/* ── Settings ──────────────────────────────────────────────────────────────── */
.settings-section {
  margin: 12px 16px 0;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--secondary-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 4px 6px;
}

.settings-card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-label {
  font-size: 15px;
}

.settings-row-value {
  font-size: 15px;
  color: var(--secondary-text);
}

.btn-export {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 14px 16px;
  font-size: 15px;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  border-bottom: 1px solid var(--border);
}

.btn-export:last-child {
  border-bottom: none;
}

.btn-export:disabled {
  color: var(--secondary-text);
  cursor: default;
}

.notification-note {
  font-size: 12px;
  color: var(--secondary-text);
  padding: 6px 4px 0;
  line-height: 1.4;
}

/* ── Bottom spacing ────────────────────────────────────────────────────────── */
.bottom-spacer {
  height: 20px;
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.text-accent { color: var(--accent); }
.text-secondary { color: var(--secondary-text); }
.text-destructive { color: var(--destructive); }
.font-mono { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ── Warning Banner ────────────────────────────────────────────────────────── */
.warning-banner {
  background: rgba(255, 159, 10, 0.15);
  border: 1px solid rgba(255, 159, 10, 0.3);
  border-radius: var(--border-radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--orange);
  margin: 8px 16px 0;
  line-height: 1.4;
}
