:root {
  --bg: #0b1220;
  --surface: #121b2e;
  --surface2: #18233a;
  --border: #243149;
  --text: #e8edf6;
  --text-dim: #93a1b8;
  --text-muted: #5d6c87;
  --cyan: #2dd4e8;
  --blue: #3b82f6;
  --green: #39d353;
  --red: #ff5c5c;
  --amber: #f0a500;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
#app { height: 100vh; width: 100vw; overflow: hidden; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
.mono { font-family: 'SFMono-Regular', Consolas, monospace; }

/* ---------- LOGIN ---------- */
#view-login {
  height: 100%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, #16233f 0%, #0b1220 70%);
  overflow-y: auto; padding: 20px;
}
.login-card {
  width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-badge {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; color: #06121f; flex-shrink: 0;
}
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: var(--text-dim); }
.login-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.login-desc { font-size: 12px; color: var(--text-dim); margin-bottom: 20px; }
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.form-input, .form-select, textarea.form-input {
  width: 100%; padding: 10px 12px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px;
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--cyan); }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; min-width: 0; }
.btn-primary {
  width: 100%; padding: 11px; border: none; border-radius: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #06121f;
  font-weight: 700; font-size: 13px; letter-spacing: .03em;
}
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.login-error {
  background: rgba(255,92,92,.1); border: 1px solid rgba(255,92,92,.3);
  color: var(--red); font-size: 12px; padding: 9px 12px; border-radius: 8px; margin-bottom: 14px;
}
.login-hint {
  margin-top: 16px; font-size: 11px; color: var(--text-muted); text-align: center; line-height: 1.6;
}

/* ---------- SHELL ---------- */
#view-shell { height: 100%; display: flex; }
.sidebar {
  width: 220px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: var(--text-dim); font-size: 13px; font-weight: 600; cursor: pointer; margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(45,212,232,.12); color: var(--cyan); }
.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--surface2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; color: var(--cyan);
  border: 1px solid var(--border); flex-shrink: 0;
}
.user-chip-name { font-size: 12px; font-weight: 700; }
.user-chip-role { font-size: 10px; color: var(--text-dim); }
.btn-sm {
  padding: 7px 12px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 12px; font-weight: 600;
}
.btn-sm:hover { border-color: var(--cyan); color: var(--cyan); }
.btn-sm.full { width: 100%; }
.btn-sm.danger:hover { border-color: var(--red); color: var(--red); }
.btn-sm.primary-outline { border-color: var(--cyan); color: var(--cyan); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-sub { font-size: 12px; color: var(--text-dim); }
.content { flex: 1; overflow-y: auto; padding: 20px; }

/* ---------- CARDS / GRID ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
}
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.stat-val { font-size: 26px; font-weight: 800; margin-top: 6px; }
.sc-cyan .stat-val { color: var(--cyan); }
.sc-green .stat-val { color: var(--green); }
.sc-red .stat-val { color: var(--red); }
.sc-amber .stat-val { color: var(--amber); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 16px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 13px; font-weight: 700; }
.card-body { padding: 16px 18px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- TABLE ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
  text-align: left; padding: 9px 14px; background: var(--surface2); color: var(--text-dim);
  font-weight: 700; text-transform: uppercase; font-size: 10.5px; letter-spacing: .03em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 10.5px; font-weight: 700; white-space: nowrap;
}
.badge.bg { background: rgba(57,211,83,.12); color: var(--green); }
.badge.br { background: rgba(255,92,92,.12); color: var(--red); }
.badge.bc { background: rgba(45,212,232,.12); color: var(--cyan); }
.badge.ba { background: rgba(240,165,0,.12); color: var(--amber); }
.badge.bx { background: rgba(93,108,135,.15); color: var(--text-muted); }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar .spacer { flex: 1; }

/* ---------- MAP ---------- */
.map-wrap { position: relative; height: calc(100vh - 140px); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.leaflet-map-el { width: 100%; height: 100%; background: var(--surface2); }
.map-legend {
  position: absolute; bottom: 14px; right: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 11px; z-index: 500;
}
.leg-item { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.leg-item:last-child { margin-bottom: 0; }
.leg-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5,9,18,.6); display: none;
  align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-title { font-size: 14px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 18px; }
.modal-body { padding: 18px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.section-label {
  font-size: 10.5px; font-weight: 700; color: var(--cyan); text-transform: uppercase; letter-spacing: .05em;
  padding-bottom: 6px; border-bottom: 1px solid var(--border); margin: 18px 0 12px;
}
.section-label:first-child { margin-top: 0; }

/* ---------- FIELD APP ---------- */
.field-topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 18px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.field-list { padding: 14px; }
.task-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.task-card:hover { border-color: var(--cyan); }
.task-card-title { font-weight: 700; font-size: 13.5px; margin-bottom: 4px; }
.task-card-meta { font-size: 11.5px; color: var(--text-dim); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.verify-header { padding: 16px 18px; border-bottom: 1px solid var(--border); }
.gps-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: var(--surface2);
  border-bottom: 1px solid var(--border); font-size: 12px;
}
.dist-badge { margin-left: auto; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.dist-badge.ok { background: rgba(57,211,83,.15); color: var(--green); }
.dist-badge.warn { background: rgba(240,165,0,.15); color: var(--amber); }
.dist-badge.bad { background: rgba(255,92,92,.15); color: var(--red); }
.dist-badge.unknown { background: rgba(93,108,135,.15); color: var(--text-muted); }

.status-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.status-btn {
  padding: 14px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface2);
  font-weight: 700; font-size: 12.5px; color: var(--text-dim);
}
.status-btn.sel-ok { border-color: var(--green); color: var(--green); background: rgba(57,211,83,.08); }
.status-btn.sel-fail { border-color: var(--red); color: var(--red); background: rgba(255,92,92,.08); }

.btn-submit {
  width: 100%; padding: 14px; border: none; border-radius: 10px; font-weight: 800; font-size: 13px;
  background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #06121f; letter-spacing: .03em;
}
.btn-submit:disabled { opacity: .4; }

.field-bnav {
  display: flex; border-top: 1px solid var(--border); background: var(--surface);
}
.field-bnav button {
  flex: 1; padding: 10px; background: none; border: none; color: var(--text-dim); font-size: 11px; font-weight: 700;
}
.field-bnav button.active { color: var(--cyan); }

.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; max-width: 90vw; }
.toast {
  padding: 11px 16px; border-radius: 9px; font-size: 12.5px; font-weight: 600; box-shadow: var(--shadow);
  background: var(--surface); border: 1px solid var(--border); color: var(--text); min-width: 220px;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }

.report-narrative { font-size: 12.5px; line-height: 1.8; color: var(--text-dim); }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- FOTO ---------- */
.photo-zone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center;
  cursor: pointer; background: var(--surface2); margin-bottom: 10px;
}
.photo-zone:hover { border-color: var(--cyan); }
.photo-zone-icon { font-size: 26px; margin-bottom: 6px; }
.photo-zone-text { font-size: 12px; color: var(--text-dim); }
.photo-preview { display: none; margin-bottom: 10px; }
.photo-preview.active { display: block; }
.photo-preview img { width: 100%; border-radius: 10px; border: 1px solid var(--border); display: block; }
.photo-preview-actions { display: flex; gap: 8px; margin-top: 8px; }
.thumb-link img {
  width: 48px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border);
}

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; top: 0; bottom: 0; z-index: 800; transition: left .2s; }
  .sidebar.open { left: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; gap: 0; }
}
