/* ============================================================
   Trail App — Design System
   Colors: --accent #C46849, --bg #F5F3EB
   Font: Inter
   ============================================================ */

:root {
  --bg: #F5F3EB;
  --bg-card: #FFFDF7;
  --text: #141413;
  --text-muted: #6B6963;
  --accent: #C46849;
  --accent-hover: #D4785A;
  --accent-light: rgba(196, 104, 73, 0.12);
  --border: rgba(20, 20, 19, 0.08);
  --border-strong: rgba(20, 20, 19, 0.16);
  --shadow: 0 2px 12px rgba(20, 20, 19, 0.08);
  --shadow-lg: 0 8px 32px rgba(20, 20, 19, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ============================================================
   Reset & Base
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button {
  cursor: pointer;
  font-family: var(--font);
  border: none;
  background: none;
}

input, textarea, select {
  font-family: var(--font);
  font-size: 15px;
}

/* ============================================================
   Header
   ============================================================ */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--accent);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  transition: background 0.3s ease;
}

.status-dot.offline {
  background: #f97316;
}

.status-text {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ============================================================
   Tab Navigation
   ============================================================ */

.tab-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 57px;
  z-index: 9;
}

.tab-btn {
  flex: 1;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
  letter-spacing: 0.01em;
}

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

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

/* ============================================================
   Main & Screens
   ============================================================ */

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* ============================================================
   Session Screen
   ============================================================ */

.trip-input-wrap {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.trip-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.trip-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease;
}

.trip-input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

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

/* ============================================================
   Chat Area
   ============================================================ */

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.chat-welcome {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
}

.welcome-text {
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 260px;
}

/* Chat bubbles */
.chat-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  animation: fadeInUp 0.25s ease;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.ai {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble.thinking {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  padding: 14px 20px;
}

.thinking-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: thinkingPulse 1.2s infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ============================================================
   Session Controls
   ============================================================ */

.session-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px 20px 32px;
  border-top: 1px solid var(--border);
}

.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
  position: relative;
}

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

.mic-btn:active {
  transform: scale(0.96);
}

.mic-btn.recording {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  animation: micPulse 1.5s infinite;
}

.mic-icon {
  width: 28px;
  height: 28px;
}

.end-btn {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 8px 20px;
  border-radius: 20px;
  border: 1px solid var(--border-strong);
  background: transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.end-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ============================================================
   Recap Screen
   ============================================================ */

.recap-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.recap-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.recap-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.recap-fields {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}

.recap-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recap-field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.recap-field input,
.recap-field textarea {
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease;
  width: 100%;
  resize: vertical;
}

.recap-field input:focus,
.recap-field textarea:focus {
  border-color: var(--accent);
}

.recap-field textarea {
  min-height: 80px;
  line-height: 1.5;
}

.recap-field input[type="number"] {
  -moz-appearance: textfield;
}

.recap-field input[type="number"]::-webkit-outer-spin-button,
.recap-field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.recap-actions {
  display: flex;
  gap: 12px;
  padding: 16px 20px 32px;
  border-top: 1px solid var(--border);
}

.btn-primary {
  flex: 1;
  padding: 14px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  transition: background 0.2s ease, transform 0.15s ease;
}

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

.btn-primary:active {
  transform: scale(0.98);
}

.btn-ghost {
  padding: 14px 20px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* ============================================================
   Journal Screen
   ============================================================ */

.journal-filter {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.filter-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.filter-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M6 9l6 6 6-6' stroke='%236B6963' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
  cursor: pointer;
}

.filter-select:focus {
  border-color: var(--accent);
}

.entries-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.entries-empty {
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
  padding: 40px 0;
}

/* Journal entry card */
.entry-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  animation: fadeInUp 0.2s ease;
}

.entry-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

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

.entry-date {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.entry-km {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.entry-route {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.entry-story {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entry-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 10px;
  background: var(--accent-light);
  color: var(--accent);
}

/* ============================================================
   Entry Detail Modal
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 19, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}

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

.modal-content {
  background: var(--bg);
  width: 100%;
  max-height: 85dvh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  z-index: 1;
}

.modal-close svg {
  width: 16px;
  height: 16px;
}

.modal-close:hover {
  background: var(--border-strong);
  color: var(--text);
}

.modal-body {
  overflow-y: auto;
  padding: 24px 20px 40px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* Modal detail sections */
.modal-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
  padding-right: 40px;
}

.modal-date {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 20px;
}

.modal-section {
  margin-bottom: 20px;
}

.modal-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.modal-section-value {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}

.modal-section-value.highlight {
  background: var(--accent-light);
  color: var(--accent);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.modal-tag {
  font-size: 13px;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.modal-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.modal-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.modal-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================
   Offline Recorder
   ============================================================ */

.offline-recorder {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 2px solid var(--accent);
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 50;
  animation: slideUp 0.3s ease;
}

.offline-recorder.hidden {
  display: none !important;
}

.offline-icon svg {
  width: 48px;
  height: 48px;
}

.offline-timer {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.offline-label {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ============================================================
   Animations
   ============================================================ */

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

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes micPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(196, 104, 73, 0.4);
  }
  50% {
    box-shadow: 0 0 0 16px rgba(196, 104, 73, 0);
  }
}

@keyframes thinkingPulse {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================================
   Utility
   ============================================================ */

.hidden {
  display: none !important;
}

/* ============================================================
   Responsive — Desktop (centered, bordered)
   ============================================================ */

@media (min-width: 600px) {
  body {
    align-items: center;
  }

  .app-header,
  .tab-nav,
  .app-main {
    width: 100%;
    max-width: 480px;
  }

  body::before {
    content: '';
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    width: 480px;
    top: 0;
    bottom: 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    pointer-events: none;
    z-index: 0;
  }

  .app-header {
    position: fixed;
    top: 0;
    z-index: 10;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .tab-nav {
    position: fixed;
    top: 57px;
    z-index: 9;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  body {
    padding-top: 105px;
  }

  .modal-content {
    max-width: 480px;
    margin: 0 auto;
  }

  .offline-recorder {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
