/* =========================================================
   BirdAI v2 — Design tokens & global styles
   Extends v1 palette; adds streams, mobile, and stats sections.
   ========================================================= */

:root {
  --primary:        #2d6a4f;
  --primary-light:  #52b788;
  --accent:         #40916c;
  --bg:             #f0f4f0;
  --surface:        #ffffff;
  --text:           #1a2e1a;
  --text-muted:     #607060;
  --border:         #d8e8d8;
  --shadow-sm:      0 2px 8px  rgba(0, 0, 0, 0.07);
  --shadow-md:      0 4px 20px rgba(0, 0, 0, 0.10);
  --shadow-hover:   0 8px 32px rgba(45, 106, 79, 0.22);
  --radius:         16px;
  --radius-sm:      8px;
  --transition:     0.22s ease;
  /* v2 additions */
  --mobile-accent:  #7b2d8b;
  --rtsp-accent:    #1d5fa8;
  --danger:         #c0392b;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* =========================================================
   Header
   ========================================================= */

header {
  background: var(--primary);
  padding: 0.75rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  color: #fff;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-decoration: none;
}

.logo-version {
  font-size: 0.7rem;
  background: rgba(255,255,255,0.25);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 4px;
  font-weight: 600;
  letter-spacing: 0;
}

.header-nav { display: flex; gap: 1.5rem; }
.header-nav a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: color var(--transition);
}
.header-nav a:hover { color: #fff; }

/* =========================================================
   Main layout
   ========================================================= */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* =========================================================
   Home page
   ========================================================= */

.home-hero {
  text-align: center;
  padding: 3rem 0 2rem;
}

.home-hero h1 {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.6rem;
}

.home-hero > p {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 3rem;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

.cards-row {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* =========================================================
   Home card
   ========================================================= */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 280px;
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  color: inherit;
  display: block;
}

.card:hover {
  transform: translateY(-7px);
  box-shadow: var(--shadow-hover);
}

.card-banner {
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-banner--explorer { background: linear-gradient(135deg, #1b4332 0%, #52b788 100%); }
.card-banner--detect   { background: linear-gradient(135deg, #1d3557 0%, #457b9d 100%); }
.card-banner--mobile   { background: linear-gradient(135deg, #4a0072 0%, #9c27b0 100%); }
.card-banner--rtsp     { background: linear-gradient(135deg, #0d2b6b 0%, #1d5fa8 100%); }

.card-icon { font-size: 4.5rem; }

.card-body   { padding: 1.3rem; }
.card-title  { font-size: 1.2rem; font-weight: 700; color: var(--primary); margin-bottom: 0.4rem; }
.card-text   { color: var(--text-muted); font-size: 0.9rem; line-height: 1.6; }

.card-cta {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.4rem 1rem;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
}

/* =========================================================
   Page headings / nav
   ========================================================= */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}
.back-link:hover { text-decoration: underline; }

.page-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.4rem;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 2rem;
}

/* =========================================================
   Bird gallery grid
   ========================================================= */

.bird-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.5rem;
}

.bird-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  color: inherit;
  display: block;
}
.bird-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-hover); }

.bird-card-img-wrap { width: 100%; height: 200px; overflow: hidden; }
.bird-card-img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 0.35s ease;
}
.bird-card:hover .bird-card-img { transform: scale(1.05); }

.bird-card-placeholder {
  width: 100%; height: 200px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 4.5rem;
}

.bird-card-body       { padding: 1rem 1.1rem 1.1rem; }
.bird-card-name       { font-weight: 700; font-size: 1.05rem; color: var(--primary); }
.bird-card-scientific { font-style: italic; color: var(--text-muted); font-size: 0.83rem; margin-top: 0.2rem; }

/* Empty state */
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--text-muted); }
.empty-icon  { font-size: 4rem; margin-bottom: 1rem; }
.empty-hint  { font-size: 0.9rem; margin-top: 0.75rem; line-height: 1.8; }
.empty-hint code {
  background: #e8f0e8; border-radius: 4px;
  padding: 0.1rem 0.35rem; font-size: 0.88rem; color: var(--primary);
}

/* =========================================================
   Bird info detail page
   ========================================================= */

.badge-row { margin-bottom: 1.2rem; }

.badge {
  display: inline-block;
  padding: 0.3rem 0.9rem;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 600;
}
.badge--ai   { background: var(--primary); color: #fff; }
.badge--rtsp { background: var(--rtsp-accent); color: #fff; }

.bird-info-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5rem;
  align-items: start;
}

.bird-info-image {
  width: 100%; border-radius: var(--radius);
  box-shadow: var(--shadow-md); object-fit: cover;
  max-height: 420px; display: block;
}

.bird-info-placeholder {
  width: 100%; height: 380px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; font-size: 9rem;
}

.external-links { display: flex; gap: 0.75rem; margin-top: 1rem; flex-wrap: wrap; }
.ext-link {
  display: inline-block;
  padding: 0.35rem 0.9rem;
  background: #f0f7f4;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background var(--transition);
}
.ext-link:hover { background: var(--border); }

.bird-info-content h1 {
  font-size: 2.1rem; font-weight: 800; color: var(--primary); margin-bottom: 0.25rem;
}
.scientific-name { color: var(--text-muted); font-size: 1rem; margin-bottom: 1.2rem; }
.bird-description { line-height: 1.75; color: var(--text); margin-bottom: 1.4rem; }

.bird-fields { display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1.4rem; }
.bird-field  { display: flex; gap: .75rem; font-size: .92rem; }
.bird-field-label {
  flex: 0 0 80px;
  font-weight: 600;
  color: var(--text-muted, #6b7280);
  text-transform: uppercase;
  font-size: .75rem;
  letter-spacing: .04em;
  padding-top: .15rem;
}
.bird-field-value { color: var(--text); line-height: 1.5; }

.stat-spinner { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }

.section-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted); font-weight: 700; margin-bottom: 0.75rem;
}

.bird-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem;
}

.stat-item {
  background: #f3f8f3;
  border-left: 3px solid var(--primary-light);
  padding: 0.7rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.stat-label {
  font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--text-muted); margin-bottom: 0.25rem;
}
.stat-value { font-weight: 600; color: var(--text); font-size: 0.92rem; }

.stats-error {
  color: var(--danger); font-size: 0.88rem; margin-top: 1rem;
  padding: 0.6rem 1rem;
  background: #fdf0ef;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--danger);
}

/* =========================================================
   Detection page
   ========================================================= */

.detect-layout {
  display: flex; flex-direction: column;
  align-items: center; gap: 1.4rem; padding-top: 0.5rem;
}

.video-container {
  position: relative; width: 100%; max-width: 640px;
  border-radius: var(--radius); overflow: hidden;
  background: #0a0a0a; box-shadow: var(--shadow-md); aspect-ratio: 4/3;
}

#video { width: 100%; height: 100%; object-fit: cover; display: block; }

.scan-overlay { position: absolute; inset: 0; pointer-events: none; }
.scan-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: rgba(82, 183, 136, 0.75);
  box-shadow: 0 0 8px rgba(82, 183, 136, 0.8);
  animation: scan 2.4s linear infinite;
}
@keyframes scan { 0% { top: 0%; } 100% { top: 100%; } }

.scanning-indicator { display: none; align-items: center; gap: 0.7rem; color: var(--primary); font-weight: 700; font-size: 0.95rem; }
.scanning-indicator.visible { display: flex; }

.pulse {
  width: 11px; height: 11px;
  background: var(--primary-light); border-radius: 50%;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1;   transform: scale(1);   }
  50%       { opacity: 0.4; transform: scale(1.35); }
}

.detect-status        { color: var(--text-muted); font-size: 0.95rem; text-align: center; }
.detect-status.active { color: var(--primary); font-weight: 600; }
.detect-btn-row { display: flex; gap: 1rem; }

/* =========================================================
   Buttons
   ========================================================= */

.btn {
  padding: 0.72rem 1.8rem;
  border: none; border-radius: var(--radius-sm);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: transform var(--transition), background var(--transition);
}
.btn-primary          { background: var(--primary); color: #fff; }
.btn-primary:hover    { background: var(--accent); transform: translateY(-2px); }
.btn-primary:disabled { background: #aaa; cursor: not-allowed; transform: none; }
.btn-danger           { background: var(--danger); color: #fff; }
.btn-danger:hover     { background: #a93226; transform: translateY(-2px); }
.btn-icon {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; padding: 0.2rem 0.5rem;
  font-size: 0.95rem; color: var(--text-muted); vertical-align: middle;
  margin-left: 0.5rem;
}
.btn-icon:hover { background: var(--border); }
.btn-full { width: 100%; }

/* =========================================================
   RTSP Streams page
   ========================================================= */

.streams-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.streams-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.streams-panel--full {
  grid-column: 1 / -1;
}

.panel-title {
  font-size: 1.1rem; font-weight: 700; color: var(--primary);
  margin-bottom: 1.25rem; border-bottom: 1px solid var(--border);
  padding-bottom: 0.6rem;
}

.stream-form { display: flex; flex-direction: column; gap: 0.85rem; }

.form-row { display: flex; flex-direction: column; gap: 0.3rem; }
.form-row label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.form-row input {
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  width: 100%;
  transition: border-color var(--transition);
}
.form-row input:focus { outline: none; border-color: var(--primary-light); }
.optional { font-weight: 400; font-size: 0.8rem; color: var(--text-muted); }

.form-error {
  color: var(--danger); font-size: 0.85rem; padding: 0.5rem 0.75rem;
  background: #fdf0ef; border-radius: var(--radius-sm);
  border-left: 3px solid var(--danger);
}

.stream-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 0.6rem;
  gap: 1rem;
}

.stream-item-info { flex: 1; min-width: 0; }
.stream-item-name { font-weight: 700; font-size: 0.95rem; }
.stream-item-url  { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stream-item-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.status-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px;
}
.status-dot--running  { background: #27ae60; }
.status-dot--error    { background: var(--danger); }
.status-dot--stopped  { background: #aaa; }
.status-dot--starting { background: #f39c12; }

.status-badge {
  font-size: 0.78rem; font-weight: 600; padding: 0.2rem 0.55rem;
  border-radius: 100px; background: #eee; color: var(--text-muted);
}

.feed-badge {
  display: inline-block; font-size: 0.7rem; font-weight: 700;
  background: #27ae60; color: #fff; border-radius: 4px;
  padding: 2px 6px; margin-left: 6px; vertical-align: middle;
  animation: pulse 2s infinite;
}

.detection-feed { display: flex; flex-direction: column; gap: 0.6rem; max-height: 320px; overflow-y: auto; }

.detection-card {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.8rem 1rem;
  background: #f3f8f3;
  border-left: 4px solid var(--primary-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.detection-card-icon { font-size: 1.8rem; }
.detection-card-body { flex: 1; }
.detection-card-name { font-weight: 700; color: var(--primary); }
.detection-card-meta { font-size: 0.8rem; color: var(--text-muted); }
.detection-card-link { font-size: 0.82rem; color: var(--primary); font-weight: 600; text-decoration: none; }
.detection-card-link:hover { text-decoration: underline; }

.text-muted { color: var(--text-muted); font-size: 0.9rem; }

/* =========================================================
   Mobile upload page
   ========================================================= */

.mobile-layout {
  max-width: 480px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 1.25rem;
}

.upload-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 240px; border: 2px dashed var(--border);
  border-radius: var(--radius); cursor: pointer;
  background: var(--surface); transition: border-color var(--transition), background var(--transition);
  overflow: hidden; padding: 1.5rem;
}
.upload-zone:hover { border-color: var(--primary-light); background: #f5faf5; }

.upload-icon { font-size: 3.5rem; display: block; margin-bottom: 0.6rem; }
.upload-hint { color: var(--text-muted); font-size: 0.95rem; text-align: center; }

.preview-img {
  width: 100%; max-height: 320px; object-fit: contain;
  border-radius: var(--radius-sm);
}

.mobile-loading {
  display: flex; align-items: center; justify-content: center;
  gap: 0.7rem; color: var(--primary); font-weight: 600;
}

.result-box {
  border-radius: var(--radius); padding: 1.2rem 1.4rem;
  display: flex; align-items: flex-start; gap: 1rem;
}
.result-box--hit  { background: #f0faf4; border: 1px solid #a8dab5; }
.result-box--miss { background: #fdf4f4; border: 1px solid #f0a8a8; }

.result-icon { font-size: 2rem; flex-shrink: 0; }
.result-text { line-height: 1.6; }
.result-link { color: var(--primary); font-weight: 600; text-decoration: none; display: inline-block; margin-top: 0.4rem; }
.result-link:hover { text-decoration: underline; }

/* =========================================================
   Responsive
   ========================================================= */

@media (max-width: 900px) {
  .streams-layout { grid-template-columns: 1fr; }
  .streams-panel--full { grid-column: 1; }
}

@media (max-width: 720px) {
  .bird-info-layout  { grid-template-columns: 1fr; }
  .cards-row         { flex-direction: column; align-items: center; }
  .home-hero h1      { font-size: 1.9rem; }
  .bird-stats        { grid-template-columns: 1fr; }
  .header-nav        { display: none; }
}

/* =========================================================
   Admin dashboard
   ========================================================= */

.admin-login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 60vh;
}
.admin-login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2.5rem 2rem;
  width: 100%; max-width: 380px; text-align: center;
  box-shadow: var(--shadow-md);
}
.admin-login-icon  { font-size: 2.5rem; margin-bottom: .5rem; }
.admin-login-title { font-size: 1.4rem; margin: 0 0 .25rem; }
.admin-login-sub   { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.admin-login-error {
  background: #fdf0ef; border: 1px solid #f0a8a8;
  border-radius: var(--radius-sm); padding: .6rem 1rem;
  font-size: .88rem; color: var(--danger); margin-bottom: 1rem;
}
.admin-login-form  { display: flex; flex-direction: column; gap: .75rem; text-align: left; }
.admin-login-label { font-size: .85rem; font-weight: 600; color: var(--text-muted); }
.admin-login-input {
  width: 100%; padding: .6rem .85rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: .95rem;
  background: var(--bg); color: var(--text);
  box-sizing: border-box;
}
.admin-login-input:focus { outline: 2px solid var(--primary-light); border-color: var(--primary-light); }
.admin-login-btn   { margin-top: .25rem; }

.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
.admin-header h1   { margin: 0; font-size: 1.6rem; }
.admin-logout      { font-size: .85rem; color: var(--text-muted); text-decoration: none; }
.admin-logout:hover { color: var(--danger); }

.admin-summary {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 1rem; margin-bottom: 1.5rem;
}
.admin-stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem;
  text-align: center;
}
.admin-stat-value  { font-size: 2rem; font-weight: 700; color: var(--primary); }
.admin-stat-label  { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-top: .25rem; }

.admin-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1rem; margin-bottom: 1rem;
}
.admin-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem;
}
.admin-panel--full { grid-column: 1 / -1; }
.admin-panel-title { font-size: 1rem; font-weight: 700; margin: 0 0 1rem; }

.admin-table       { width: 100%; border-collapse: collapse; font-size: .88rem; }
.admin-table th    { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
.admin-table td    { padding: .5rem .5rem; border-bottom: 1px solid #f0f0f0; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table-scroll { overflow-x: auto; }
.admin-td-mono     { font-family: monospace; font-size: .82rem; }
.admin-link        { color: var(--primary); text-decoration: none; }
.admin-link:hover  { text-decoration: underline; }
.admin-empty       { color: var(--text-muted); font-size: .9rem; }

.admin-source-badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: .78rem; font-weight: 600; text-transform: capitalize;
}
.admin-source-badge--webcam { background: #e0f2fe; color: #0369a1; }
.admin-source-badge--mobile { background: #f3e8ff; color: #7c3aed; }
.admin-source-badge--rtsp   { background: #fef9c3; color: #92400e; }

.admin-type-badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: .78rem; font-weight: 600;
}
.admin-type-badge--detection  { background: #dcfce7; color: #166534; }
.admin-type-badge--page_view  { background: #f0f9ff; color: #075985; }

@media (max-width: 720px) {
  .admin-summary { grid-template-columns: 1fr; }
  .admin-grid    { grid-template-columns: 1fr; }
}
