:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --accent: #49c3b3;
  --accent-dark: #3aa89a;
  --ink: #1f254b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

/* Layout */
.container {
  flex: 1;
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 20px 40px;
  width: 100%;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}

/* Header */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  background: transparent;
  margin-top: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.logo img {
  height: 32px;
  width: auto;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.05));
}

.nav-link {
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  transition: 0.2s;
  font-size: 1rem;
}

.nav-link:hover {
  background: #eef2ff;
  color: var(--accent);
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 800px;
  /* Default for index */
}

/* Admin Card Override */
main .card {
  max-width: 600px;
}

h2 {
  margin: 0 0 16px 0;
  font-size: 1.5rem;
}

p {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 24px;
}

/* Toolbar & Buttons */
.toolbar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 28px;
}

.toolbar button {
  min-height: 48px;
  font-size: 16px;
  padding: 14px 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.grow {
  flex: 1;
}

button {
  appearance: none;
  cursor: pointer;
  user-select: none;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--ink);
  background: var(--surface);
  transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover:not([disabled]) {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

button:active:not([disabled]) {
  transform: translateY(0);
}

button[disabled] {
  opacity: .5;
  cursor: not-allowed;
  background: var(--bg);
}

.btn-accent,
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(73, 195, 179, 0.3);
  width: auto;
  /* Default */
}

.btn-primary {
  width: 100%;
  font-size: 1rem;
  padding: 14px;
}

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

.btn-secondary:hover:not([disabled]) {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

/* Admin button style */

.btn-accent:hover:not([disabled]),
.btn-primary:hover:not([disabled]) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  box-shadow: 0 6px 16px rgba(73, 195, 179, 0.4);
}

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

.btn-ghost:hover {
  background: var(--bg);
  color: var(--ink);
}

/* Recording Animation */
.rec-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

.recording .rec-dot {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
  }

  70% {
    box-shadow: 0 0 0 6px rgba(255, 255, 255, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

/* Form Elements */
.grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(12, 1fr);
}

.field,
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"],
input[type="date"],
textarea {
  width: 100%;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  outline: none;
  font-size: 15px;
  transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(73, 195, 179, .15);
  background: var(--surface);
}

/* Meter */
.meter {
  height: 6px;
  border-radius: 3px;
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 24px;
}

.meter>div {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.1s linear;
}

/* Preview Area */
.preview {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 20px;
  min-height: 80px;
  white-space: pre-wrap;
  color: var(--ink);
  font-size: 15px;
}

.muted {
  color: var(--muted);
  font-style: italic;
}

.status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: right;
  font-weight: 500;
}

/* Footer */
.site-footer {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 24px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: auto;
}

/* Toast */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  padding: 12px 20px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px);
  transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 500;
  font-size: 14px;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: none;
}

/* Intent Card */
.intent-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: none;
  animation: slideDown 0.3s ease-out;
}

.intent-card.show {
  display: flex;
}

.intent-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  flex-shrink: 0;
}

.intent-content {
  flex: 1;
}

.intent-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  margin-bottom: 2px;
}

.intent-desc {
  font-size: 13px;
  color: var(--muted);
}

/* Intent Variants */
.intent-new .intent-icon {
  background: #dcfce7;
  color: #166534;
}

.intent-new {
  border-left: 4px solid #22c55e;
}

.intent-update .intent-icon {
  background: #dbeafe;
  color: #1e40af;
}

.intent-update {
  border-left: 4px solid #3b82f6;
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Admin Specific */
#status-area {
  margin-top: 24px;
  padding: 16px;
  border-radius: 12px;
  background: #f1f5f9;
  display: none;
}

#status-area.success {
  background: #dcfce7;
  color: #166534;
}

#status-area.error {
  background: #fee2e2;
  color: #991b1b;
}

.log-item {
  font-size: 0.9rem;
  margin-bottom: 4px;
  display: flex;
  gap: 8px;
}

.log-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ===========================
   Mobile Optimizations
   =========================== */

@media (max-width: 640px) {

  /* Header - Stack on mobile */
  .site-header {
    flex-direction: column;
    gap: 12px;
    padding: 16px 20px;
    align-items: flex-start;
  }

  .header-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
  }

  .nav-link {
    font-size: 0.9rem;
    padding: 6px 10px;
  }

  /* Bottom Navigation for Mobile */
  .site-header {
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(248, 249, 252, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  }

  .header-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
  }

  .nav-link {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    padding: 8px;
    text-align: center;
    color: var(--muted);
  }

  .nav-link:hover,
  .nav-link:active {
    background: transparent;
    color: var(--accent);
  }

  /* Hide logout button in bottom nav to save space, maybe move to settings or keep as icon */
  .header-nav button {
    display: none;
    /* Hide logout button in bottom bar */
  }

  /* Adjust main padding to account for bottom nav */
  body {
    padding-bottom: 80px;
  }

  /* Containers - Reduce padding */
  .container {
    padding: 20px 16px;
  }

  main {
    padding: 16px;
  }

  .card {
    padding: 20px;
    border-radius: 12px;
  }

  /* Typography - Slightly smaller on mobile */
  h2 {
    font-size: 1.25rem;
  }

  p {
    font-size: 0.95rem;
  }

  /* Buttons - Touch-friendly sizes (min 44x44px) */
  button {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 15px;
  }

  .btn-primary {
    padding: 14px 16px;
  }

  .toolbar {
    gap: 8px;
  }

  /* Grid - Stack to single column */
  .grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .field {
    grid-column: span 1 !important;
  }

  /* Form elements - Better mobile UX */
  input[type="text"],
  input[type="date"],
  textarea {
    font-size: 16px;
    /* Prevents iOS zoom on focus */
    padding: 12px 14px;
  }

  textarea {
    min-height: 100px;
  }

  /* Toast - Position better on mobile */
  .toast {
    right: 16px;
    bottom: 16px;
    left: 16px;
    text-align: center;
  }

  /* Intent card - Smaller on mobile */
  .intent-card {
    padding: 12px 16px;
    gap: 12px;
  }

  .intent-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .intent-title {
    font-size: 14px;
  }

  .intent-desc {
    font-size: 12px;
  }

  /* Preview area - Better mobile sizing */
  .preview {
    padding: 16px;
    font-size: 14px;
    min-height: 60px;
  }

  /* Audio player - Full width on mobile */
  audio {
    width: 100%;
    max-width: 100%;
  }

  /* Footer - Smaller padding */
  .site-footer {
    padding: 16px;
    font-size: 12px;
  }

  /* Logo - Slightly smaller */
  .logo {
    font-size: 1.1rem;
  }

  .logo img {
    height: 28px;
  }
}

/* Extra small devices (< 380px) */
@media (max-width: 380px) {
  .site-header {
    padding: 12px 16px;
  }

  .card {
    padding: 16px;
  }

  h2 {
    font-size: 1.15rem;
  }

  button {
    font-size: 14px;
    padding: 10px 14px;
  }
}