:root {
  --bg: #0f1115;
  --surface: #171b22;
  --surface-2: #1f2530;
  --border: #2a3140;
  --text: #f3f5f8;
  --muted: #98a2b3;
  --accent: #e11d48;
  --accent-2: #f97316;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* Login */
.view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px 22px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.brand-mark h1 {
  margin: 0;
  font-size: 1.6rem;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.brand-dot.small {
  width: 10px;
  height: 10px;
}

.subtitle {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 0.95rem;
}

/* App Shell */
#main-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  background: rgba(15, 17, 21, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.content {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
}

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

/* Recorder Stage */
.recorder-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 18px 10px 22px;
}

.status-pill {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.status-pill.recording {
  color: #fecdd3;
  border-color: var(--accent);
  background: rgba(225, 29, 72, 0.16);
}

.rec-timer {
  font-variant-numeric: tabular-nums;
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 18px;
}

.record-btn-wrap {
  position: relative;
  width: 126px;
  height: 126px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.record-btn {
  width: 112px;
  height: 112px;
  border-radius: 999px;
  border: 4px solid rgba(255, 255, 255, 0.16);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

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

.record-btn-inner {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition: all 0.2s ease;
}

.record-btn.recording {
  box-shadow: 0 0 0 12px rgba(225, 29, 72, 0.18);
  animation: pulse 1.6s infinite;
}

.record-btn.recording .record-btn-inner {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.35); }
  70% { box-shadow: 0 0 0 22px rgba(225, 29, 72, 0); }
  100% { box-shadow: 0 0 0 0 rgba(225, 29, 72, 0); }
}

.rec-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.rec-secondary {
  display: flex;
  gap: 12px;
  margin-top: 14px;
}

/* Cards & Forms */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0;
}

.muted a { color: #fb7185; }

.field, label {
  display: block;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 12px 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* Buttons */
button, .photo-btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  padding: 12px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost.small, .btn-secondary.small, .btn-primary.small {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.full-width { width: 100%; margin-top: 6px; }
.danger-text { color: #fda4af; }

/* Mood chips */
.mood-row { margin-bottom: 14px; }
.field-label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }
.mood-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 12px;
  font-size: 0.85rem;
  border-radius: 999px;
}

.chip.selected {
  background: rgba(225, 29, 72, 0.18);
  color: #fecdd3;
  border-color: var(--accent);
}

/* Photos */
.photo-picker { margin-bottom: 12px; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.photo-thumb-wrap {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.photo-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.8rem;
  padding: 0;
}

.audio-preview-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}

.audio-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

audio { width: 100%; height: 38px; }

/* Entries Timeline */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.entry-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.entry-date {
  font-size: 0.82rem;
  color: var(--muted);
}

.entry-title {
  margin: 4px 0 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge.ok { color: #86efac; border-color: rgba(34, 197, 94, 0.4); }
.badge.warn { color: #fde68a; border-color: rgba(245, 158, 11, 0.45); }
.badge.err { color: #fda4af; border-color: rgba(225, 29, 72, 0.5); }

.entry-transcript {
  white-space: pre-wrap;
  margin: 10px 0;
  font-size: 0.98rem;
}

.entry-notes {
  background: var(--surface-2);
  border-left: 3px solid var(--accent-2);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  color: #e5e7eb;
  white-space: pre-wrap;
  margin: 8px 0;
}

.entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.token-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

/* Pending Banner & Feedback */
.pending-banner {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.pending-banner p { margin: 4px 0 10px; font-size: 0.88rem; color: #fde68a; }
.pending-actions { display: flex; gap: 8px; }

.error-box {
  background: rgba(225, 29, 72, 0.14);
  border: 1px solid rgba(225, 29, 72, 0.45);
  color: #fecdd3;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.info-box {
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #bbf7d0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin: 10px 0;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(23, 27, 34, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  background: transparent;
  color: var(--muted);
  border-radius: 0;
  flex-direction: column;
  gap: 2px;
  padding: 10px 6px;
  font-size: 0.78rem;
}

.nav-ico { font-size: 1.15rem; line-height: 1; }
.nav-btn.active { color: #fff; }
.nav-btn.active .nav-ico { color: var(--accent); }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox img {
  max-width: 100%;
  max-height: 90dvh;
  border-radius: 10px;
}

.lightbox-close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: 16px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 999px;
}
