/* ============================================================
   BUS TRACKER — STYLES
   Mobile-first. Breakpoints: 640px, 1100px
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Reset & base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:         #1D9E75;
  /* Upload mode colours */
  --cal-color:     #27AE60;
  --cal-light:     #E9F7EF;
  --email-color:   #4A90D9;
  --email-light:   #EBF3FC;
  --enc-color:     #C0392B;
  --enc-light:     #FCEAE9;
  --green-light:   #E1F5EE;
  --green-dark:    #0F6E56;
  --amber:         #BA7517;
  --amber-light:   #FAEEDA;
  --amber-dark:    #854F0B;
  --red:           #E24B4A;
  --red-light:     #FCEBEB;
  --red-dark:      #A32D2D;

  --bg:            #F4F3EF;
  --surface:       #FFFFFF;
  --border:        rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.14);
  --text-primary:  #1A1A18;
  --text-secondary:#5A5A56;
  --text-tertiary: #9A9A96;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --font-sans: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;

  --tab-bar-h: 64px;

  /* Mode colours */
  --cal-color:    #27AE60;
  --cal-light:    #E9F7EF;
  --cal-dark:     #1E8449;
  --email-color:  #4A90D9;
  --email-light:  #EBF3FC;
  --email-dark:   #2C6FAC;
  --enc-color:    #C0392B;
  --enc-light:    #FCEAE9;
  --enc-dark:     #922B21;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #111110;
    --surface:       #1C1C1A;
    --border:        rgba(255,255,255,0.08);
    --border-strong: rgba(255,255,255,0.14);
    --text-primary:  #F0EFEA;
    --text-secondary:#9A9A96;
    --text-tertiary: #5A5A56;
    --green-light:   #0D3D2D;
    --green-dark:    #5DCAA5;
    --amber-light:   #3D2800;
    --amber-dark:    #FAC775;
    --red-light:     #3D1010;
    --red-dark:      #F09595;
    --cal-light:     #0D3320;
    --email-light:   #0D2340;
    --enc-light:     #3D1010;
  }
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
  padding-bottom: var(--tab-bar-h);
}

.hidden { display: none !important; }

/* ── Header ──────────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border-strong);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 200;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-primary);
}

.title-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.refresh-btn {
  background: none;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  min-height: 44px;
  padding: 0 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.15s;
}

.refresh-btn:active   { background: var(--bg); }
.refresh-btn:disabled { opacity: 0.5; cursor: default; }

/* ── Search bar ──────────────────────────────────────────── */
.search-row { display: flex; gap: 0.5rem; }

.search-input {
  flex: 1;
  background: var(--bg);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.875rem;
  font-size: 0.9375rem;
  font-family: var(--font-mono);
  color: var(--text-primary);
  outline: none;
  min-height: 44px;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.search-input::placeholder { color: var(--text-tertiary); font-family: var(--font-sans); }
.search-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29,158,117,0.15);
}

.search-go {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 1rem;
  min-height: 44px;
  font-size: 0.9375rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.search-go:active { opacity: 0.75; }

/* ── Tab bar ─────────────────────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tab-bar-h);
  background: var(--surface);
  border-top: 0.5px solid var(--border-strong);
  display: flex;
  align-items: stretch;
  z-index: 300;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 44px;
}

.tab-item.active { color: var(--green); }
.tab-icon  { font-size: 1.375rem; line-height: 1; }
.tab-label { font-size: 0.6875rem; font-weight: 500; }

/* ── Views ───────────────────────────────────────────────── */
.view {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

#view-mrt {
  max-width: 100%;
  padding: 0;
  height: calc(100dvh - var(--tab-bar-h) - 52px);
}

.pdf-frame { width: 100%; height: 100%; border: none; display: block; }

/* ── Section label ───────────────────────────────────────── */
.section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin: 1.25rem 0 0.625rem;
}

/* ── Stop grid ───────────────────────────────────────────── */
.stop-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }

@media (min-width: 640px) {
  .stop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1100px) {
  .stop-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ── Stop card ───────────────────────────────────────────── */
.stop-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: 1rem;
  transition: opacity 0.2s;
}

.stop-card.loading { opacity: 0.5; }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.card-name { font-size: 1rem; font-weight: 600; color: var(--text-primary); line-height: 1.2; }
.card-code { font-size: 0.75rem; color: var(--text-tertiary); font-family: var(--font-mono); margin-top: 2px; }

.custom-badge {
  font-size: 0.6875rem; font-weight: 500;
  background: var(--green-light); color: var(--green-dark);
  padding: 2px 8px; border-radius: 20px;
  white-space: nowrap; flex-shrink: 0; margin-left: 0.5rem;
}

/* ── Bus table ───────────────────────────────────────────── */
.bus-table { width: 100%; border-collapse: collapse; table-layout: fixed; }

.bus-table thead th {
  font-size: 0.6875rem; font-weight: 500;
  color: var(--text-tertiary); text-align: center;
  padding-bottom: 0.375rem; letter-spacing: 0.03em;
}

.bus-table thead th:first-child { text-align: left; }
.bus-table tbody tr { border-top: 0.5px solid var(--border); }

.bus-table tbody td { padding: 0.5rem 0; text-align: center; vertical-align: middle; }
.bus-table tbody td:first-child { text-align: left; }

.col-num   { width: 52px; }
.col-next  { width: calc(50% - 26px); }
.col-after { width: calc(50% - 26px); }

.bus-service-no { font-size: 0.9375rem; font-weight: 500; font-family: var(--font-mono); color: var(--text-primary); }

.arrival-cell { display: flex; flex-direction: column; align-items: center; gap: 3px; }

.arrival-time { font-size: 1rem; font-weight: 500; font-family: var(--font-mono); }
.arrival-time.green { color: var(--arrival-green); }
.arrival-time.amber { color: var(--arrival-green); } /* amber now maps to green */
.arrival-time.red   { color: var(--arrival-red); }
.arrival-time.muted { color: var(--arrival-grey); font-size: 0.8125rem; font-weight: 400; }

.load-pill { font-size: 0.625rem; font-weight: 500; padding: 1px 6px; border-radius: 20px; white-space: nowrap; }
.load-sea { background: var(--green-light); color: var(--green-dark); }
.load-sda { background: var(--amber-light); color: var(--amber-dark); }
.load-lsd { background: var(--red-light);   color: var(--red-dark); }

.no-services { font-size: 0.875rem; color: var(--text-tertiary); text-align: center; padding: 1rem 0 0.5rem; }
.card-error  { font-size: 0.8125rem; color: var(--red); padding: 0.5rem 0; }

/* ── Skeleton ────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--border-strong) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px; height: 14px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Upload view ─────────────────────────────────────────── */
.upload-wrap { max-width: 520px; margin: 0 auto; padding-bottom: 1rem; }

.upload-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* File + photo row */
.upload-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.upload-drop-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 1.25rem 0.75rem;
  text-align: center;
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; gap: 0.375rem;
  min-height: 90px; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: border-color 0.15s, background 0.15s;
}
.upload-drop-zone:active { background: var(--bg); border-color: var(--green); }
.drop-icon  { font-size: 1.625rem; line-height: 1; }
.drop-label { font-size: 0.8125rem; color: var(--text-secondary); font-weight: 500; }
.file-input-hidden { display: none; }

/* Note textarea */
.text-input {
  width: 100%;
  background: var(--bg);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.9375rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  resize: vertical; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}
.text-input::placeholder { color: var(--text-tertiary); }
.text-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(29,158,117,0.15); }

/* ── 3 icon options ──────────────────────────────────────── */
.icon-options {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.icon-opt {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 6px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: all 0.15s;
  position: relative;
}

.opt-icon { font-size: 1.75rem; line-height: 1; }

/* Selected states */
.icon-opt.active-calendar { border-color: var(--cal-color);   background: var(--cal-light); }
.icon-opt.active-email    { border-color: var(--email-color);  background: var(--email-light); }
.icon-opt.active-encrypt  { border-color: var(--enc-color);    background: var(--enc-light); }

/* Active dot indicator */
.icon-opt.active-calendar::after,
.icon-opt.active-email::after,
.icon-opt.active-encrypt::after {
  content: '';
  position: absolute;
  top: 5px; right: 5px;
  width: 7px; height: 7px;
  border-radius: 50%;
}
.icon-opt.active-calendar::after { background: var(--cal-color); }
.icon-opt.active-email::after    { background: var(--email-color); }
.icon-opt.active-encrypt::after  { background: var(--enc-color); }

/* ── Slider ──────────────────────────────────────────────── */
.slider-wrap {
  position: relative;
  height: 52px;
  border-radius: 26px;
  overflow: hidden;
  user-select: none;
  transition: background 0.25s;
}

.slider-wrap.calendar-mode { background: #D5F0E0; }
.slider-wrap.email-mode    { background: #D6E9F8; }
.slider-wrap.encrypt-mode  { background: #F5D5D3; }

.slider-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  transition: opacity 0.1s;
}
.slider-label.calendar-mode { color: var(--cal-dark); }
.slider-label.email-mode    { color: var(--email-dark); }
.slider-label.encrypt-mode  { color: var(--enc-dark); }

.slider-thumb {
  position: absolute;
  left: 4px; top: 4px;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  cursor: grab;
  transition: background 0.25s, left 0.3s;
}
.slider-thumb.calendar-mode { background: var(--cal-color); }
.slider-thumb.email-mode    { background: var(--email-color); }
.slider-thumb.encrypt-mode  { background: var(--enc-color); }

/* ── Status + progress ───────────────────────────────────── */
.upload-status { font-size: 0.875rem; min-height: 1.25rem; line-height: 1.5; text-align: center; }
.upload-status.idle    { color: var(--text-secondary); }
.upload-status.loading { color: var(--text-secondary); }
.upload-status.success { color: var(--green); }
.upload-status.error   { color: var(--red); }
.upload-status.warn    { color: var(--amber); }

.progress-track { width: 100%; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-bar   { height: 100%; background: var(--green); border-radius: 2px; width: 0%; transition: width 0.3s ease; }

/* ── PWA install banner ──────────────────────────────────── */
.install-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--green-light);
  border-bottom: 0.5px solid rgba(29,158,117,0.2);
  padding: 0.625rem 1rem;
  font-size: 0.8125rem;
  color: var(--green-dark);
}

.install-banner.visible { display: flex; }
.install-banner-text    { flex: 1; }

.install-btn {
  background: var(--green); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 6px 14px;
  font-size: 0.8125rem; font-family: var(--font-sans);
  font-weight: 500; cursor: pointer; white-space: nowrap;
}

.dismiss-btn {
  background: none; border: none;
  color: var(--green-dark); font-size: 1.125rem;
  cursor: pointer; padding: 4px 8px; min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
