/* ── Variables ──────────────────────────────────────────────────────── */
:root {
  --brand:        #2D7A4A;
  --brand-dark:   #1D5634;
  --brand-light:  #4AA86A;
  --brand-bg:     #EBF5EF;

  --bg:           #F3F6F2;
  --surface:      #FFFFFF;
  --surface-2:    #F8FAF7;
  --border:       #DDE7DA;
  --border-light: #EBF0E9;

  --text:         #1A2C1C;
  --text-muted:   #6A7E6B;
  --text-faint:   #9AB09B;

  --sidebar-bg:   #182C1D;
  --sidebar-hover:#1F3A26;
  --sidebar-act:  #2D7A4A;
  --sidebar-text: #A8C5AB;
  --sidebar-w:    220px;

  --success: #43A047;
  --warning: #F59E0B;
  --danger:  #EF4444;
  --info:    #3B82F6;

  --radius:  8px;
  --radius-lg: 12px;
  --shadow:  0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --transition: 150ms ease;
}

/* ── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }
img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }

/* ── Layout ─────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--sidebar-bg); display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
}
.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-logo .brand {
  font-size: .85rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: #fff;
}
.sidebar-logo .sub {
  font-size: .7rem; color: var(--sidebar-text); margin-top: 1px;
}
.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-section { padding: 14px 18px 6px;
  font-size: .65rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: rgba(255,255,255,.25); }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px; font-size: .875rem; color: var(--sidebar-text);
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active {
  background: var(--sidebar-act); color: #fff;
  border-left-color: #7ECBA3;
}
.nav-link.active svg { opacity: 1; }
.sidebar-footer {
  padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.07);
  font-size: .8rem; color: var(--sidebar-text);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-footer .username { font-weight: 600; color: #fff; }
.logout-link { font-size: .75rem; color: var(--sidebar-text); }
.logout-link:hover { color: #fff; }
.lang-toggle { display: flex; align-items: center; gap: 5px; margin-top: 5px; font-size: .7rem; }
.lang-toggle a { color: var(--sidebar-text); opacity: .5; transition: opacity var(--transition); }
.lang-toggle a:hover, .lang-toggle a.active { color: #fff; opacity: 1; }
.lang-toggle span { color: rgba(255,255,255,.2); }

/* Main */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 28px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: .85rem; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--brand); }
.breadcrumb-sep { color: var(--border); }
.breadcrumb-current { color: var(--text); font-weight: 500; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.hamburger {
  display: none; align-items: center; justify-content: center;
  background: none; border: none; padding: 6px; border-radius: 6px;
  cursor: pointer; color: var(--text); flex-shrink: 0;
}
.hamburger:hover { background: var(--surface-2); }
.hamburger svg { width: 22px; height: 22px; stroke: currentColor; }

.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 99;
}

.content { padding: 28px; flex: 1; }

/* ── Mobile responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hamburger { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 220ms ease;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }

  .main { margin-left: 0; }
  .topbar { padding: 0 14px; gap: 8px; }
  .content { padding: 14px; }

  .form-row   { grid-template-columns: 1fr !important; }
  .form-row-3 { grid-template-columns: 1fr !important; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Tables overflow scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; }
}

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: .9rem; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer {
  padding: 14px 20px; border-top: 1px solid var(--border-light);
  background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Stats cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow);
}
.stat-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-sub { font-size: .75rem; color: var(--text-faint); margin-top: 4px; }
.stat-card.accent .stat-value { color: var(--brand); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: var(--radius); font-size: .85rem;
  font-weight: 500; border: none; transition: all var(--transition); white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: #FEF2F2; color: var(--danger); border: 1px solid #FECACA; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: .78rem; }
.btn svg { width: 14px; height: 14px; }

/* ── Forms ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .8rem; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; }
.form-control {
  width: 100%; padding: 8px 11px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  font-size: .875rem; color: var(--text); font-family: inherit;
  transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-bg); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236A7E6B'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.form-hint { font-size: .75rem; color: var(--text-faint); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Toggle */
.toggle-group { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.toggle { position: relative; display: inline-flex; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: #D1D5DB;
  border-radius: 20px; cursor: pointer;
  transition: background var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 14px; height: 14px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%;
  transition: transform var(--transition); box-shadow: var(--shadow);
}
.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }
.toggle-label { font-size: .875rem; color: var(--text); user-select: none; cursor: pointer; }

/* Schedule */
.schedule-wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 0; }
.time-tag {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--brand-bg); color: var(--brand-dark);
  border: 1px solid #B8DCC5; border-radius: 20px;
  padding: 3px 10px 3px 12px; font-size: .82rem; font-weight: 500;
}
.time-tag-remove {
  background: none; border: none; padding: 0;
  color: var(--brand); line-height: 1; font-size: 1rem; cursor: pointer;
  opacity: .6; transition: opacity var(--transition);
}
.time-tag-remove:hover { opacity: 1; }
.schedule-add { display: flex; align-items: center; gap: 6px; }
.schedule-add input[type=time] {
  padding: 5px 8px; border-radius: var(--radius);
  border: 1px solid var(--border); font-size: .82rem; color: var(--text);
  background: var(--surface);
}
.schedule-add input[type=time]:focus { outline: none; border-color: var(--brand); }
.schedule-count { font-size: .75rem; color: var(--text-faint); }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { text-align: left; padding: 10px 16px; font-size: .72rem; font-weight: 600;
     text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
     border-bottom: 1px solid var(--border); background: var(--surface-2); }
th:first-child { border-radius: var(--radius) 0 0 0; }
th:last-child { border-radius: 0 var(--radius) 0 0; }
td { padding: 11px 16px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 12px; font-size: .72rem; font-weight: 600;
}
.badge-green  { background: #DCFCE7; color: #166534; }
.badge-yellow { background: #FEF9C3; color: #854D0E; }
.badge-red    { background: #FEE2E2; color: #991B1B; }
.badge-gray   { background: #F3F4F6; color: #6B7280; }
.badge-blue   { background: #DBEAFE; color: #1D4ED8; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-green  { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-red    { background: var(--danger); }
.dot-gray   { background: #D1D5DB; }
.dot-blue   { background: var(--info); }

/* ── Flash messages ──────────────────────────────────────────────────── */
.flashes { margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; }
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-radius: var(--radius); font-size: .875rem;
  border-left: 3px solid;
}
.flash-success { background: #DCFCE7; color: #166534; border-color: var(--success); }
.flash-error   { background: #FEE2E2; color: #991B1B; border-color: var(--danger); }
.flash-info    { background: #DBEAFE; color: #1D4ED8; border-color: var(--info); }
.flash-close { margin-left: auto; background: none; border: none;
               font-size: 1.1rem; cursor: pointer; opacity: .5; padding: 0 4px; }
.flash-close:hover { opacity: 1; }

/* ── Map ─────────────────────────────────────────────────────────────── */
.map-container { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }

/* ── Media grids ──────────────────────────────────────────────────────── */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.img-card { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); cursor: pointer; transition: transform var(--transition), box-shadow var(--transition); }
.img-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.media-del-btn { position: absolute; top: 5px; right: 5px; background: rgba(0,0,0,.55); border: none; color: #fff; border-radius: 50%; width: 22px; height: 22px; font-size: 1rem; line-height: 1; cursor: pointer; display: none; align-items: center; justify-content: center; }
.img-card:hover .media-del-btn { display: flex; }
.media-del-btn:hover { background: var(--danger); }
.img-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--surface-2); }
.img-card-meta { padding: 7px 10px; font-size: .72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.det-badge { position: absolute; top: 6px; left: 6px; background: var(--brand); color: #fff; font-size: .68rem; font-weight: 700; padding: 2px 6px; border-radius: 10px; pointer-events: none; line-height: 1.4; }

.audio-list { display: flex; flex-direction: column; gap: 8px; }
.audio-row { background: var(--surface-2); border: 1px solid var(--border-light); border-radius: var(--radius); padding: 11px 14px; display: flex; align-items: center; gap: 14px; }
.audio-row .audio-meta { flex: 1; min-width: 0; }
.audio-row .audio-name { font-size: .82rem; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.audio-row .audio-info { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }
.audio-row audio { flex-shrink: 0; width: 240px; height: 30px; }

/* ── Lightbox ─────────────────────────────────────────────────────────── */
.lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 200; align-items: center; justify-content: center; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 4px; }
.lb-close { position: absolute; top: 16px; right: 20px; background: none; border: none; color: #fff; font-size: 1.8rem; cursor: pointer; opacity: .7; }
.lb-close:hover { opacity: 1; }

/* ── Tabs ────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn { background: none; border: none; padding: 10px 18px; font-size: .875rem; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all var(--transition); }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Empty state ──────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-faint); }
.empty svg { width: 40px; height: 40px; margin: 0 auto 12px; opacity: .4; }
.empty p { font-size: .9rem; }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 150; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 440px; box-shadow: var(--shadow-md); }
.modal-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Config section ──────────────────────────────────────────────────── */
.config-section { margin-bottom: 28px; }
.config-section-title { display: flex; align-items: center; gap: 7px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border-light); }
.cfg-icon { width: 13px; height: 13px; flex-shrink: 0; opacity: .7; }
.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.config-bools { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px; }
/* ── Sliders ─────────────────────────────────────────────────────────── */
.form-range { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; background: var(--border); border-radius: 2px; outline: none; cursor: pointer; margin: 6px 0 2px; }
.form-range::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--brand); cursor: pointer; border: 2px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.18); transition: transform .1s; }
.form-range::-webkit-slider-thumb:hover { transform: scale(1.2); }
.form-range::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--brand); cursor: pointer; border: 2px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.slider-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.slider-val { font-size: .85rem; font-weight: 700; color: var(--brand); min-width: 22px; text-align: right; }
.slider-ends { display: flex; justify-content: space-between; }
.slider-ends span { font-size: .68rem; color: var(--text-faint); }
.slider-ends.three { position: relative; }
.slider-ends.three span:nth-child(2) { position: absolute; left: 50%; transform: translateX(-50%); }

/* ── Warn banner ─────────────────────────────────────────────────────── */
.warn-banner { display: flex; align-items: center; gap: 10px; background: #FFFBEB; border: 1px solid #FDE68A; border-radius: var(--radius); padding: 10px 14px; font-size: .85rem; color: #92400E; margin-bottom: 20px; }

/* ── Misc ────────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 1.25rem; font-weight: 700; }
.page-subtitle { font-size: .85rem; color: var(--text-muted); margin-top: 2px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.meta-row { display: flex; gap: 20px; flex-wrap: wrap; }
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-key { font-size: .72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.meta-val { font-size: .875rem; font-weight: 500; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-bg); color: var(--brand-dark); border-radius: 20px; padding: 2px 10px; font-size: .78rem; font-weight: 500; }

/* Login page */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { width: 360px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .brand-name { font-size: 1.1rem; font-weight: 800; color: var(--brand); letter-spacing: .05em; text-transform: uppercase; }
.login-logo .brand-sub { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ── Camera preset bar ───────────────────────────────────────────────── */
.preset-bar { display: flex; gap: 5px; flex-wrap: wrap; }
.preset-bar .btn { font-size: .72rem; padding: 3px 10px; }

/* ── Log ──────────────────────────────────────────────────────────────── */
.log-box { font-family: ui-monospace, monospace; font-size: .76rem; background: #1A2B1C; color: #A8C5AB; border-radius: var(--radius); padding: 14px 16px; max-height: 320px; overflow-y: auto; }
.log-line { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.04); white-space: pre-wrap; word-break: break-all; }
.log-line.l-image { color: #7CB9E8; }
.log-line.l-audio { color: #B39DDB; }
.log-line.l-config { color: #A5D6A7; }
.log-line.l-new    { color: #FFD54F; }
