/* mobile.css — 智慧誘捕籠 Mobile-First Design System */

:root {
  --bg-primary: #FFFFFF;
  --bg-secondary: #F9FAFB;
  --bg-tertiary: #F3F4F6;
  --text-primary: #1F2937;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --success-bg: #DCFCE7;
  --success-text: #166534;
  --success-accent: #10B981;
  --warning-bg: #FEF3C7;
  --warning-text: #92400E;
  --warning-accent: #F59E0B;
  --danger-bg: #FEE2E2;
  --danger-text: #991B1B;
  --danger-accent: #EF4444;
  --info-bg: #DBEAFE;
  --info-text: #1E40AF;
  --info-accent: #3B82F6;
  --border-light: #E5E7EB;
  --border-medium: #D1D5DB;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --nav-h: 60px;
  --bottom-nav-h: 64px;
}

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

html { font-size: 16px; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-secondary);
  -webkit-tap-highlight-color: transparent;
}

/* ── Top Nav ── */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: #fff;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  z-index: 100;
  gap: 0.75rem;
}
.top-nav .nav-brand {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
}
.top-nav .nav-spacer { flex: 1; }
.top-nav .nav-user {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--success-accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

/* ── Device Selector in nav ── */
.device-select-wrap {
  flex: 1;
  max-width: 200px;
}
.device-select-wrap select {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 12px;
  padding-right: 1.75rem;
}

/* ── Bottom Nav (mobile) ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: #fff;
  border-top: 1px solid var(--border-light);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-tertiary);
  font-size: 0.7rem;
  font-weight: 500;
  transition: color 0.15s;
  padding: 0.35rem 0;
}
.bottom-nav a i { font-size: 1.15rem; }
.bottom-nav a.active { color: var(--success-accent); }
.bottom-nav a:hover { color: var(--text-secondary); }

/* ── Page wrapper ── */
.page-body {
  padding-top: calc(var(--nav-h) + 0.75rem);
  padding-bottom: calc(var(--bottom-nav-h) + 0.75rem);
  min-height: 100vh;
}
.container-page {
  width: 100%;
  padding: 0 0.875rem;
}

/* ── Cards ── */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  margin-bottom: 0.875rem;
  overflow: hidden;
}
.card-body { padding: 1rem; }
.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.625rem;
}

/* ── Status cards ── */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
  margin-bottom: 0.875rem;
}
.status-card {
  border-radius: var(--radius-lg);
  padding: 1rem;
  text-align: center;
}
.status-card.success { background: var(--success-bg); }
.status-card.warning { background: var(--warning-bg); }
.status-card.danger  { background: var(--danger-bg); }
.status-card.info    { background: var(--info-bg); }
.status-card.neutral { background: var(--bg-tertiary); }

.status-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}
.status-card.success .status-label { color: var(--success-text); }
.status-card.warning .status-label { color: var(--warning-text); }
.status-card.danger  .status-label { color: var(--danger-text); }
.status-card.info    .status-label { color: var(--info-text); }
.status-card.neutral .status-label { color: var(--text-secondary); }

.status-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 600;
}
.status-card.success .status-value { color: var(--success-text); }
.status-card.warning .status-value { color: var(--warning-text); }
.status-card.danger  .status-value { color: var(--danger-text); }
.status-card.info    .status-value { color: var(--info-text); }
.status-card.neutral .status-value { color: var(--text-primary); }

/* ── Online indicator ── */
.online-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.online  { background: var(--success-accent); box-shadow: 0 0 0 3px rgba(16,185,129,0.2); }
.dot.offline { background: var(--text-tertiary); }
.dot.warning { background: var(--warning-accent); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
  min-height: 48px;
  user-select: none;
}
.btn:active { opacity: 0.8; transform: scale(0.98); }
.btn-block { width: 100%; display: flex; }
.btn-success { background: var(--success-accent); color: #fff; }
.btn-danger  { background: var(--danger-accent);  color: #fff; }
.btn-primary { background: var(--info-accent);    color: #fff; }
.btn-warning { background: var(--warning-accent); color: #fff; }
.btn-light   { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border-medium); }
.btn-outline { background: transparent; color: var(--text-primary); border: 1px solid var(--border-medium); }
.btn-sm { padding: 0.45rem 0.85rem; font-size: 0.88rem; min-height: 36px; }
.btn-disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Stat grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  text-align: center;
}
.stat-item { padding: 0.5rem 0; }
.stat-num {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}
.stat-num.green  { color: var(--success-accent); }
.stat-num.yellow { color: var(--warning-accent); }
.stat-num.red    { color: var(--danger-accent); }
.stat-lbl {
  display: block;
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Camera image ── */
.camera-wrap {
  background: #111;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  aspect-ratio: 4/3;
}
.camera-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #555;
  font-size: 0.9rem;
  gap: 0.5rem;
}
.camera-placeholder i { font-size: 2rem; }
.camera-ts {
  position: absolute;
  bottom: 8px; right: 10px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ── History list ── */
.history-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-light);
}
.history-item:last-child { border-bottom: none; }
.history-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.history-info { flex: 1; min-width: 0; }
.history-time { font-size: 0.75rem; color: var(--text-secondary); }
.history-main { font-size: 0.95rem; font-weight: 500; margin: 1px 0; }
.history-sub  { font-size: 0.82rem; color: var(--text-secondary); }
.history-img {
  width: 52px; height: 52px;
  border-radius: var(--radius-md);
  object-fit: cover;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Tabs ── */
.tab-bar {
  display: flex;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  padding: 3px;
  margin-bottom: 1rem;
}
.tab-btn {
  flex: 1;
  padding: 0.55rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.tab-btn.active {
  background: #fff;
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ── Form fields ── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}
.form-control {
  width: 100%;
  padding: 0.65rem 0.875rem;
  font-size: 1rem;
  border: 1.5px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.form-control:focus { border-color: var(--success-accent); }
.form-control::placeholder { color: var(--text-tertiary); }

/* ── Date picker ── */
.date-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.875rem;
}
.date-row label { font-size: 0.88rem; color: var(--text-secondary); white-space: nowrap; }
.date-row input[type="date"] {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  background: #fff;
  color: var(--text-primary);
  min-height: 44px;
  outline: none;
}
.date-row input[type="date"]:focus { border-color: var(--success-accent); }

/* ── Alert banner ── */
.alert-banner {
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  margin-bottom: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-weight: 500;
}
.alert-banner.success { background: var(--success-bg); color: var(--success-text); }
.alert-banner.danger  { background: var(--danger-bg);  color: var(--danger-text); }
.alert-banner.warning { background: var(--warning-bg); color: var(--warning-text); }
.alert-banner.info    { background: var(--info-bg);    color: var(--info-text); }

/* ── Section heading ── */
.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 0.35rem 0 0.5rem;
}

/* ── List rows (settings style) ── */
.list-row {
  display: flex;
  align-items: center;
  padding: 0.875rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--border-light);
  text-decoration: none;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.12s;
}
.list-row:last-child { border-bottom: none; }
.list-row:active { background: var(--bg-tertiary); }
.list-row i.lead { color: var(--text-secondary); width: 22px; font-size: 1rem; }
.list-row .row-label { flex: 1; font-size: 0.97rem; margin-left: 0.625rem; }
.list-row i.chevron { color: var(--text-tertiary); font-size: 0.8rem; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1F2937;
  color: #fff;
  padding: 0.6rem 1.25rem;
  border-radius: 999px;
  font-size: 0.88rem;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-secondary);
}
.empty-state i { font-size: 2.5rem; color: var(--text-tertiary); margin-bottom: 0.75rem; }
.empty-state p { margin: 0; font-size: 0.92rem; }

/* ── Loading spinner ── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border-medium);
  border-top-color: var(--success-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Photo modal ── */
.photo-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.photo-modal-backdrop.show {
  opacity: 1;
  pointer-events: all;
}
.photo-modal-backdrop img {
  max-width: 90vw;
  max-height: 80vh;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

/* ── Desktop overrides ── */
@media (min-width: 768px) {
  .bottom-nav { display: none; }
  .page-body {
    padding-top: calc(var(--nav-h) + 1.25rem);
    padding-bottom: 2rem;
  }
  .container-page { max-width: 100%; padding: 0 2rem; }
  .desktop-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: start;
  }
  .desktop-left { grid-column: 1; }
  .desktop-right { grid-column: 2; }
  .top-nav { padding: 0 1.5rem; }
  .device-select-wrap { max-width: 260px; }
  .top-nav-links { display: flex; gap: 0.25rem; }
  .top-nav-link {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.15s;
  }
  .top-nav-link:hover { background: var(--bg-tertiary); color: var(--text-primary); }
  .top-nav-link.active { color: var(--success-accent); background: var(--success-bg); }
}

/* ── Large desktop (1024px+): wider containers + two-column layouts ── */
@media (min-width: 1024px) {
  .container-page {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 3rem;
  }

  /* History page: sidebar (filters) + main (list) */
  .history-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.25rem;
    align-items: start;
  }
  .history-sidebar { grid-column: 1; position: sticky; top: calc(var(--nav-h) + 1rem); }
  .history-main    { grid-column: 2; }

  /* GPS page: map (60%) + info panel (40%) */
  .gps-layout {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 1.25rem;
    align-items: start;
  }
  .gps-map-col  { grid-column: 1; }
  .gps-info-col { grid-column: 2; position: sticky; top: calc(var(--nav-h) + 1rem); }

  /* Settings page (charts): sidebar (device list) + content */
  .settings-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.25rem;
    align-items: start;
  }
  .settings-sidebar { grid-column: 1; position: sticky; top: calc(var(--nav-h) + 1rem); }
  .settings-content { grid-column: 2; }

  /* WiFi form: two columns */
  .wifi-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  /* Mode cards: side by side */
  .mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }
}

@media (max-width: 767px) {
  .top-nav-links { display: none; }
  .desktop-grid { display: block; }
}

@media (max-width: 1023px) {
  .history-layout { display: block; }
  .gps-layout     { display: block; }
  .settings-layout { display: block; }
  .wifi-fields    { display: block; }
  .mode-grid      { display: block; }
}