/* === Design Tokens === */
:root {
  --bg: #1a1a2e;
  --bg-card: rgba(22, 33, 62, 0.75);
  --bg-input: rgba(15, 52, 96, 0.8);
  --text: #eee;
  --text-muted: #aaa;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --success: #2ed573;
  --danger: #ff4757;
  --border: rgba(255, 255, 255, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --max-w: 600px;
  --nav-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}


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

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + 16px);
  -webkit-tap-highlight-color: transparent;
}

/* Fixed background layer — avoids mobile background-attachment:fixed bugs */
#bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background-color: var(--bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* === Container === */
.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 16px;
  transition: opacity 0.15s ease;
}
.container.fading {
  opacity: 0;
}

/* === Bottom Nav === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.3);
  display: flex;
  justify-content: center;
  z-index: 100;
}

.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 80px;
  max-width: 120px;
  flex: 1;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.nav-tab.active { color: var(--accent); }
.nav-tab:hover { color: var(--accent-hover); }
.nav-icon-svg { width: 24px; height: 24px; margin-bottom: 2px; }

/* === Flash Messages === */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  animation: slideDown 0.3s ease;
}

.flash-success { background: rgba(46,213,115,0.15); border: 1px solid var(--success); color: var(--success); }
.flash-error { background: rgba(255,71,87,0.15); border: 1px solid var(--danger); color: var(--danger); }

.flash-dismiss {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Section Titles === */
.section-title {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.section-subtitle {
  color: var(--text-muted);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

/* === Logo === */
.app-logo {
  text-align: center;
  padding: 16px 0 0;
  flex-shrink: 0;
}

.app-logo-img {
  max-width: 420px;
  width: 100%;
  height: auto;
}

/* === Quick Log === */
.quick-log {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--nav-h) - 32px);
}

.log-step {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Step 1: type picker */
.log-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: 1;
  align-content: center;
  padding: 8px 0;
}

@media (max-width: 600px) {
  .log-buttons {
    grid-template-columns: 1fr;
  }
}

.log-btn {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  padding: 16px 24px;
  transition: transform 0.15s, background 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  display: block;
}

.log-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
}

.log-btn:active {
  transform: scale(0.95);
}

.log-btn-icon {
  width: 100%;
  height: 100%;
  max-height: 22vh;
  object-fit: contain;
  display: block;
}

.today-count {
  text-align: center;
  color: var(--text-muted);
  padding: 12px 0;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.today-count strong {
  color: var(--accent);
  font-size: 1.2rem;
}

/* Step 2: details + submit */
.step-back {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 8px 0;
  text-align: left;
  font-family: var(--font);
}

.step-back:hover { color: var(--text); }

.log-detail-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
}

.log-detail-form .form-group { margin-bottom: 20px; }

.label-hint {
  color: var(--text-muted);
  font-weight: 400;
}

.log-type-indicator {
  text-align: center;
  padding: 16px 0;
}

.log-type-icon {
  max-height: 15vh;
  object-fit: contain;
}

.btn-log {
  margin-top: 24px;
  padding: 18px;
  font-size: 1.15rem;
}

/* === Details / Forms === */
.details-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
}

.details-toggle {
  padding: 14px 16px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  list-style: none;
}

.details-toggle::-webkit-details-marker { display: none; }
.details-toggle::before { content: '+ '; }
details[open] .details-toggle::before { content: '- '; }

.details-form {
  padding: 0 16px 16px;
}

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

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
}

.form-group textarea { resize: vertical; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* === Buttons === */
.btn {
  display: inline-block;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: opacity 0.2s, transform 0.1s;
  font-family: var(--font);
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.form-actions {
  display: flex;
  gap: 12px;
}

.form-actions .btn { flex: 1; }

/* === History === */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 1rem;
}

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

.history-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

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

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.history-item-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.history-type-img { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }

.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-time { font-weight: 600; font-size: 0.95rem; }
.history-duration { font-size: 0.8rem; color: var(--text-muted); }
.history-notes {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-sm {
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-family: var(--font);
}

.btn-edit { background: var(--border); color: var(--text); }
.btn-delete { background: rgba(255,71,87,0.15); color: var(--danger); }
.inline-form { display: inline; }

/* === Insights === */
.range-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.range-btn {
  flex: 1;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  font-family: var(--font);
}

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

.chart-card {
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.chart-title {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.chart-card canvas {
  width: 100% !important;
  max-height: 250px;
}

.ai-card {
  border-style: dashed;
}

.ai-placeholder {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 20px 0;
}

/* === Edit page === */
.edit-entry .details-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* === Error page === */
.error-page {
  text-align: center;
  padding: 40px 0;
}

.error-page p {
  color: var(--text-muted);
  margin: 12px 0 24px;
}

/* === Utilities === */
@media (min-width: 640px) {
  .bottom-nav {
    max-width: var(--max-w);
    left: 50%;
    transform: translateX(-50%);
    border-radius: var(--radius) var(--radius) 0 0;
  }
}
