:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-elevated: #2c2c2e;
  --surface-hover: #3a3a3c;
  --border: rgba(255, 255, 255, 0.1);
  --hairline: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --muted: #98989d;
  --tertiary: #636366;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --green: #30d158;
  --red: #ff453a;
  --amber: #ff9f0a;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.shell {
  max-width: 980px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 2px 2px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.status-dots {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.dot-muted { background: var(--tertiary); }
.dot-ok { background: var(--green); }
.dot-warn { background: var(--amber); }

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 11px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 1.12fr 0.88fr;
  gap: 14px;
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.primary-col,
.secondary-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

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

.card-compact {
  padding: 12px 14px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.section-label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.mini-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

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

.auth-card {
  margin-bottom: 14px;
  border-color: rgba(10, 132, 255, 0.35);
}

.auth-card .muted-text {
  margin-bottom: 10px;
}

/* Recents strip */
.recents-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recents-head,
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2px;
}

.recents-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.recents-scroll::-webkit-scrollbar {
  display: none;
}

.recent-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 7px 11px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-chip:hover {
  background: var(--surface-elevated);
}

.recent-chip .recent-sub {
  color: var(--muted);
  font-size: 0.78rem;
}

/* Segmented control */
.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #121214;
  border: 1px solid var(--hairline);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
  margin-bottom: 12px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 7px 4px;
  min-height: 36px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn.active {
  background: var(--surface-elevated);
  color: var(--text);
}

/* Grouped Apple Maps Origin / Destination well */
.route-well {
  background: var(--surface-elevated);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  margin-bottom: 12px;
  position: relative;
}

.route-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 12px;
}

.route-row input {
  background: transparent;
  border: none;
  padding: 10px 0;
  min-height: 42px;
  border-radius: 0;
}

.route-row input:focus {
  outline: none;
}

.route-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.origin-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.22);
}

.dest-dot {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(255, 69, 58, 0.22);
}

.route-divider {
  height: 1px;
  background: var(--hairline);
  margin-left: 31px;
  position: relative;
}

.swap-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2;
}

.swap-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

/* Autocomplete dropdown */
.autocomplete-wrap {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  left: -1px;
  right: -1px;
  top: calc(100% + 6px);
  z-index: 30;
  background: #242426;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  max-height: 260px;
  overflow-y: auto;
}

.autocomplete-header {
  padding: 6px 12px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tertiary);
  background: #1f1f21;
  border-bottom: 1px solid var(--hairline);
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--hairline);
  padding: 9px 12px;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item:focus {
  background: rgba(10, 132, 255, 0.18);
  outline: none;
}

.ac-pin {
  font-size: 0.9rem;
  flex: 0 0 auto;
  opacity: 0.85;
}

.ac-text {
  min-width: 0;
  flex: 1;
}

.ac-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-sub {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Inputs & Timing row */
.field {
  margin-bottom: 10px;
}

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  min-height: 40px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  font: inherit;
  font-size: 0.92rem;
  background: var(--surface-elevated);
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: var(--tertiary);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(10, 132, 255, 0.35);
  border-color: var(--accent);
}

.timing-row {
  display: grid;
  grid-template-columns: 1fr 94px;
  gap: 10px;
  margin-bottom: 2px;
}

.unit-input {
  display: flex;
  align-items: center;
  background: var(--surface-elevated);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding-right: 10px;
}

.unit-input input {
  border: none;
  background: transparent;
  padding-right: 4px;
  text-align: right;
}

.unit-input input:focus {
  outline: none;
}

.unit-input span {
  color: var(--muted);
  font-size: 0.84rem;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.inline-row {
  display: flex;
  gap: 8px;
}

.inline-row input {
  flex: 1;
}

@media (max-width: 640px) {
  .two-col { grid-template-columns: 1fr; }
  input, select, textarea { font-size: 16px; min-height: 44px; }
  .btn { min-height: 44px; }
}

/* Collapsible options */
.options-panel {
  margin: 4px 0 12px;
  border-top: 1px solid var(--hairline);
  padding-top: 10px;
}

.options-panel summary {
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.options-panel summary::after {
  content: "›";
  font-size: 1.1rem;
  transition: transform 0.15s ease;
}

.options-panel[open] summary::after {
  transform: rotate(90deg);
}

.options-body {
  margin-top: 12px;
}

/* Buttons */
.actions {
  display: flex;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 11px;
  padding: 10px 14px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-grow {
  flex: 1;
}

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

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

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

.btn-secondary:hover { background: var(--surface-hover); }

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

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

.btn-sm {
  padding: 5px 10px;
  min-height: 32px;
  font-size: 0.8rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}

.feedback {
  margin-top: 8px;
  font-size: 0.84rem;
}

.feedback.ok { color: var(--green); }
.feedback.err { color: var(--red); }

.hidden { display: none !important; }

/* Preview */
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.maps-pill {
  background: rgba(10, 132, 255, 0.16);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
}

.timeline-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 132, 255, 0.12);
  border: 1px solid rgba(10, 132, 255, 0.28);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 10px;
}

.timeline-banner strong {
  font-size: 1.05rem;
}

.timeline-banner .arrow {
  color: var(--accent);
  font-weight: 700;
}

.preview-summary {
  font-size: 0.94rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.route-trace {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.warnings {
  background: rgba(255, 159, 10, 0.14);
  color: var(--amber);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  margin-top: 10px;
}

.ics-details {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

.ics-details summary {
  cursor: pointer;
}

pre {
  background: #0d0d0f;
  border: 1px solid var(--hairline);
  color: #d1d1d6;
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.74rem;
  max-height: 220px;
}

/* Upcoming events */
.events-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.event-item {
  background: var(--surface-elevated);
  border: 1px solid var(--hairline);
  border-radius: 11px;
  padding: 9px 11px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.event-info {
  min-width: 0;
  flex: 1;
}

.event-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.event-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.icon-btn-danger {
  color: var(--red);
  border-color: rgba(255, 69, 58, 0.3);
}

.shortcut-summary {
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
}

.shortcut-guide {
  margin-top: 10px;
  font-size: 0.82rem;
}

.shortcut-guide p {
  margin: 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82em;
  color: #d1d1d6;
}
