/* Lexi — Apple-style design system. System fonts only: SF on Apple devices,
   Segoe UI on Windows, sensible fallback elsewhere. No font is downloaded. */

:root {
  --font: -apple-system, "SF Pro Text", "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;

  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --bg-grouped: #ffffff;
  --label: #000000;
  --label-secondary: rgba(60, 60, 67, 0.6);
  --label-tertiary: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.29);
  --accent: #0a84ff;
  --accent-contrast: #ffffff;
  --danger: #ff3b30;
  --success: #34c759;
  --warning: #ff9f0a;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --touch: 44px;
  --tabbar-height: 49px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-grouped: #1c1c1e;
    --label: #ffffff;
    --label-secondary: rgba(235, 235, 245, 0.6);
    --label-tertiary: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--label);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font-family: inherit; }

button, a { touch-action: manipulation; }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* Large-title header, Apple-style */
.app-header {
  padding: env(safe-area-inset-top) var(--space-4) var(--space-2);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: var(--space-2) 0 0;
}

.app-main {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-4) calc(var(--tabbar-height) + env(safe-area-inset-bottom) + var(--space-6));
}

/* Bottom tab bar */
.tab-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--separator);
}

.tab-bar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar-height);
  background: none;
  border: none;
  color: var(--label-secondary);
  font-size: 10px;
  font-weight: 500;
  padding: var(--space-1) 0;
  cursor: pointer;
}

.tab-bar button .tab-icon {
  font-size: 22px;
  line-height: 1;
}

.tab-bar button[aria-current="page"] {
  color: var(--accent);
}

/* Grouped inset list — the core Apple list pattern */
.grouped-list {
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
  background: var(--bg-grouped);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.grouped-list-header {
  font-size: 13px;
  font-weight: 400;
  color: var(--label-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 0 0 var(--space-2) var(--space-3);
}

.grouped-list li {
  display: flex;
  align-items: center;
  min-height: var(--touch);
  padding: var(--space-3) var(--space-4);
  border-bottom: 0.5px solid var(--separator);
}

.grouped-list li:last-child { border-bottom: none; }

.grouped-list li.tappable {
  cursor: pointer;
}

.grouped-list li.tappable:active {
  background: color-mix(in srgb, var(--label) 6%, transparent);
}

/* Forms */
.field-group {
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
  overflow: hidden;
}

.field-row {
  display: flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 var(--space-4);
  border-bottom: 0.5px solid var(--separator);
}

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

.field-row label {
  width: 110px;
  flex-shrink: 0;
  font-size: 15px;
  color: var(--label);
}

.field-row input,
.field-row select,
.field-row textarea {
  flex: 1;
  border: none;
  background: none;
  font-size: 17px;
  color: var(--label);
  padding: var(--space-3) 0;
  outline: none;
  min-height: var(--touch);
}

.field-row textarea { resize: vertical; min-height: var(--touch); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0 var(--space-5);
  border-radius: var(--radius-sm);
  border: none;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: var(--accent-contrast); width: 100%; }
.btn-primary:active { opacity: 0.8; }
.btn-text { background: none; color: var(--accent); padding: 0 var(--space-2); }
.btn-danger { color: var(--danger); }

/* Status pills */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pill-local { background: color-mix(in srgb, var(--label-tertiary) 40%, transparent); color: var(--label-secondary); }
.pill-pending { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.pill-synced { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.pill-error { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

/* Update-available toast */
.update-toast {
  position: fixed;
  left: var(--space-4);
  right: var(--space-4);
  bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + var(--space-3));
  background: var(--bg-elevated);
  color: var(--label);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  z-index: 20;
}

.update-toast[hidden] { display: none; }

.row-label { flex: 1; color: var(--label-secondary); }
.row-meta { font-size: 13px; color: var(--label-secondary); }
.back-link { display: inline-block; margin-bottom: var(--space-3); text-decoration: none; }

.empty-state {
  text-align: center;
  color: var(--label-secondary);
  padding: var(--space-6) var(--space-4);
  font-size: 15px;
}
