/* ==========================================================
   Coconut Polygon Verifier — Tamil Nadu 2020
   ========================================================== */

:root {
  --bg: #f5f4ee;
  --surface: #fdfcf7;
  --surface-2: #fff;
  --border: #d6d2c4;
  --divider: #ebe8df;
  --text: #2b2b1e;
  --text-muted: #6d6b5e;
  --text-faint: #a8a698;
  --primary: #2d7a3a;
  --primary-hover: #236b2e;
  --primary-light: #e8f3ea;
  --danger: #c0392b;
  --danger-light: #fce8e6;
  --warning: #b3752b;
  --warning-light: #fef5e7;
  --modify: #f39c12;
  --modify-light: #fef5e7;
  --yes: #27ae60;
  --no: #e74c3c;
  --pending: #c8c5bc;
  --font: 'DM Sans', system-ui, sans-serif;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(50,45,30,.08);
  --shadow-lg: 0 8px 28px rgba(50,45,30,.14);
  --sidebar-w: 340px;
  --blue: #2980b9;
  --blue-light: #eaf4fb;
  --blue-border: #1a6fa0;
  --edit-orange: #e67e22;
  --edit-orange-light: #fef5e7;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}
.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--divider);
}
.logo-row { display: flex; align-items: center; gap: 10px; color: var(--primary); }
.logo-title { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.logo-sub { font-size: 12px; color: var(--text-muted); }

.sidebar-section { padding: 14px 18px; border-bottom: 1px solid var(--divider); }
.field-label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: 8px;
}

.select-input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface-2);
  font: inherit; font-size: 14px; color: var(--text);
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236d6b5e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.select-input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.district-info {
  margin-top: 10px; padding: 10px 12px;
  background: var(--primary-light); border-radius: var(--radius);
  font-size: 13px; color: var(--primary);
}
.hidden { display: none !important; }

/* Progress */
.progress-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.progress-count { font-size: 13px; font-weight: 600; color: var(--primary); }
.progress-bar {
  height: 6px; background: var(--divider); border-radius: 3px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--primary);
  border-radius: 3px; transition: width .3s ease;
}
.progress-stats {
  display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--text-muted);
}
.stat { display: flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-yes { background: var(--yes); }
.dot-no { background: var(--no); }
.dot-skip { background: var(--pending); }

/* Polygon List */
.polygon-list-section { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.list-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; flex-wrap: wrap; gap: 6px;
}
.filter-btns { display: flex; gap: 4px; }
.filter-btn {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 20px;
  background: none; font: inherit; font-size: 11px; font-weight: 500;
  color: var(--text-muted); cursor: pointer; transition: all .15s;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.polygon-list {
  flex: 1; overflow-y: auto; margin: 0 -18px; padding: 0 18px;
}
.poly-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius);
  cursor: pointer; transition: all .15s ease;
  border: 1px solid transparent; margin-bottom: 3px;
}
.poly-item:hover { background: var(--primary-light); }
.poly-item.active { border-color: var(--primary); background: var(--primary-light); }
.poly-item.verified-yes { border-left: 3px solid var(--yes); }
.poly-item.verified-no { border-left: 3px solid var(--no); }
.poly-num {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--divider); display: grid; place-items: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.poly-item.verified-yes .poly-num { background: var(--yes); color: #fff; }
.poly-item.verified-no .poly-num { background: var(--no); color: #fff; }
.poly-meta { font-size: 12px; color: var(--text-muted); }
.poly-status { font-size: 11px; font-weight: 600; margin-left: auto; white-space: nowrap; }
.poly-status.s-yes { color: var(--yes); }
.poly-status.s-no { color: var(--no); }
.poly-status.s-pending { color: var(--pending); }

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 18px; border-top: 1px solid var(--divider);
  display: flex; flex-direction: column; gap: 8px;
}

/* --- Buttons --- */
.btn {
  padding: 9px 16px; border: none; border-radius: var(--radius);
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-yes { background: var(--yes); color: #fff; flex: 1; font-weight: 600; }
.btn-yes:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-no { background: var(--no); color: #fff; flex: 1; font-weight: 600; }
.btn-no:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-modify { background: #f39c12; color: #fff; flex: 1; font-weight: 600; }
.btn-modify:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-skip { background: var(--divider); color: var(--text-muted); flex: 1; }
.btn-skip:hover { background: var(--border); }
.btn-sm { padding: 6px 14px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }
.btn-sm:hover { border-color: var(--primary); color: var(--primary); }

/* --- Map --- */
.map-container {
  flex: 1; position: relative; height: 100vh;
}
#map { width: 100%; height: 100%; z-index: 1; }

/* Polygon labels on map */
.polygon-label {
  background: rgba(255,255,255,.92); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; font-size: 11px; font-weight: 700;
  color: var(--text); white-space: nowrap; text-align: center;
  font-family: var(--font);
}
.polygon-label-yes { background: rgba(39,174,96,.88); color: #fff; border-color: #1e8449; }
.polygon-label-no { background: rgba(231,76,60,.88); color: #fff; border-color: #c0392b; }

/* Verify Panel */
.verify-panel {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 1000; background: var(--surface); border: 1px solid var(--divider);
  border-radius: 14px; padding: 18px 22px; box-shadow: var(--shadow-lg);
  min-width: 420px; max-width: 480px;
  backdrop-filter: blur(8px);
}
.verify-header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.verify-header h3 { font-size: 15px; font-weight: 700; }
.verify-area { font-size: 12px; color: var(--text-muted); }
.close-btn {
  margin-left: auto; width: 28px; height: 28px; border: none;
  background: var(--divider); border-radius: 50%; font-size: 18px;
  cursor: pointer; display: grid; place-items: center; color: var(--text-muted);
}
.close-btn:hover { background: var(--danger-light); color: var(--danger); }
.verify-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

/* Toggle */
.verify-toggle-row { margin-bottom: 14px; }
.toggle-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.toggle-label input { display: none; }
.toggle-switch {
  width: 38px; height: 22px; background: var(--pending);
  border-radius: 11px; position: relative; transition: background .2s;
}
.toggle-switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  transition: transform .2s;
}
.toggle-label input:checked + .toggle-switch { background: var(--primary); }
.toggle-label input:checked + .toggle-switch::after { transform: translateX(16px); }

.verify-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.verify-actions-secondary { margin-bottom: 10px; }
.btn { transition: all .15s ease; }
.verify-nav { display: flex; justify-content: space-between; }

/* Loading */
.loading-overlay {
  position: absolute; inset: 0; z-index: 2000;
  background: rgba(245,244,238,.85); display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; font-size: 14px; color: var(--text-muted);
}
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--divider);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.leaflet-tooltip { font-family: var(--font); font-size: 12px; }

/* --- User Modal --- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(43,43,30,.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--surface); border-radius: 12px;
  padding: 32px 28px; width: 380px; max-width: 90vw;
  box-shadow: 0 12px 40px rgba(0,0,0,.18); text-align: center;
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.modal-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 18px; }
.modal-input {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); font: inherit; font-size: 15px;
  color: var(--text); background: var(--surface-2); margin-bottom: 14px;
  text-align: center;
}
.modal-input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.modal-btn { width: 100%; padding: 12px; font-size: 15px; }

/* --- Sync Indicator --- */
.user-sync-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; font-size: 12px; color: var(--text-muted);
}
.current-user { font-size: 12px; }
.sync-indicator { display: flex; align-items: center; gap: 5px; font-size: 11px; }
.sync-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--pending); display: inline-block;
}
.sync-dot.sync-ok { background: var(--yes); }
.sync-dot.sync-loading { background: var(--warning); animation: pulse .8s infinite; }
.sync-dot.sync-saving { background: var(--warning); animation: pulse .5s infinite; }
.sync-dot.sync-error { background: var(--no); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.field-row { display: flex; justify-content: space-between; align-items: center; }
.refresh-btn { padding: 4px 10px !important; font-size: 11px !important; }

.verified-by {
  font-size: 12px; color: var(--primary); font-weight: 500;
  margin-bottom: 8px; padding: 4px 8px;
  background: var(--primary-light); border-radius: 4px;
  display: inline-block;
}
.verified-by.hidden { display: none; }
.poly-verifier { font-size: 10px; color: var(--text-faint); margin-top: 1px; }

/* --- Visual Guide --- */
.guide-fab {
  position: absolute; top: 12px; right: 60px; z-index: 800;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface);
  font: inherit; font-size: 12px; font-weight: 600;
  color: var(--text-muted); cursor: pointer;
  box-shadow: var(--shadow); transition: all .15s;
}
.guide-fab:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-light); }

.guide-panel {
  position: absolute; top: 50px; right: 12px; z-index: 900;
  width: 520px; max-height: calc(100vh - 80px);
  background: var(--surface); border: 1px solid var(--divider);
  border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.15);
  display: flex; flex-direction: column; overflow: hidden;
}
.guide-panel.hidden { display: none; }
.guide-header {
  padding: 16px 18px 12px; border-bottom: 1px solid var(--divider);
  position: relative;
}
.guide-header h3 { font-size: 15px; font-weight: 700; margin: 0; }
.guide-subtitle { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }
.guide-header .close-btn { position: absolute; top: 12px; right: 14px; }
.guide-scroll { flex: 1; overflow-y: auto; padding: 14px 18px 18px; }
.guide-section { margin-bottom: 18px; }
.guide-section-label {
  font-size: 13px; font-weight: 700; padding: 5px 12px;
  border-radius: 6px; display: inline-block; margin-bottom: 10px;
}
.guide-label-yes { background: #e8f3ea; color: var(--yes); }
.guide-label-no { background: #fce8e6; color: var(--no); }
.guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.guide-card { border-radius: 8px; overflow: hidden; border: 2px solid transparent; }
.guide-card img { width: 100%; height: 140px; object-fit: cover; display: block; }
.guide-card-yes { border-color: var(--yes); }
.guide-card-no { border-color: var(--no); }
.guide-cap { display: block; font-size: 10px; color: var(--text-muted); padding: 5px 8px; line-height: 1.3; background: var(--bg); }
.guide-tip { font-size: 10px; line-height: 1.4; padding: 8px 10px; border-radius: 6px; margin-top: 8px; }
.guide-tip-yes { background: #e8f3ea; color: var(--yes); }
.guide-tip-no { background: #fce8e6; color: var(--no); }

.export-divider { height: 1px; background: var(--divider); margin: 4px 0; }
.btn-export-all {
  background: #1a5276; color: #fff; padding: 9px 16px;
  border: none; border-radius: var(--radius); font: inherit;
  font-size: 13px; font-weight: 600; cursor: pointer; text-align: center;
  transition: background .15s;
}
.btn-export-all:hover { background: #154360; }
.btn-export-all:disabled { opacity: .5; cursor: wait; }
.btn-export-all-geo {
  background: none; border: 1px solid #1a5276; color: #1a5276;
  padding: 9px 16px; border-radius: var(--radius); font: inherit;
  font-size: 13px; font-weight: 600; cursor: pointer; text-align: center;
  transition: all .15s;
}
.btn-export-all-geo:hover { background: #eaf2f8; }
.btn-export-all-geo:disabled { opacity: .5; cursor: wait; }

/* ============================================================
   DRAWN POLYGONS — Improved Card UI
   ============================================================ */
.drawn-polygons-section { border-bottom: 1px solid var(--divider); }

.drawn-polygon-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 2px 4px;
}

.drawn-empty { font-size: 12px; color: var(--text-faint); padding: 6px 0; }

.drawn-polygon-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 9px 11px;
  border-radius: var(--radius);
  border: 1px solid rgba(41,128,185,.25);
  border-left: 3px solid var(--blue);
  background: var(--blue-light);
  transition: background .12s, border-color .12s;
}
.drawn-polygon-item:hover { background: #d4eaf7; }

/* Editing state — orange highlight */
.drawn-polygon-item.dp-editing {
  border-left-color: var(--edit-orange);
  background: var(--edit-orange-light);
  border-color: rgba(230,126,34,.35);
}
.drawn-polygon-item.dp-editing:hover { background: #fde8c8; }

/* Card header row */
.dp-header {
  display: flex;
  align-items: center;
  gap: 7px;
}
.dp-id-badge {
  background: var(--blue);
  color: #fff;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  flex-shrink: 0;
}
.dp-editing .dp-id-badge { background: var(--edit-orange); }

.dp-area {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(0,0,0,.05);
  border-radius: 4px;
  padding: 2px 7px;
  font-variant-numeric: tabular-nums;
}

/* Note text */
.dp-note-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Meta row */
.dp-meta-row {
  font-size: 11px;
  color: var(--text-muted);
}

/* Action buttons row */
.dp-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.dp-btn {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.8);
  cursor: pointer;
  color: var(--text-muted);
  font-family: var(--font);
  font-weight: 500;
  transition: all .12s;
  line-height: 1.4;
}
.dp-btn:hover { background: #fff; color: var(--text); border-color: var(--blue); }

.dp-btn-edit:hover, .dp-btn-active {
  color: var(--edit-orange) !important;
  border-color: var(--edit-orange) !important;
  background: var(--edit-orange-light) !important;
}

.dp-btn-delete:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-light);
}

/* ---- Edit Mode Bar (inside sidebar) ---- */
.edit-mode-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--edit-orange-light);
  border: 1px solid rgba(230,126,34,.35);
  border-radius: var(--radius);
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.edit-mode-label {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--edit-orange);
  min-width: 0;
}
.edit-mode-btns { display: flex; gap: 6px; }

.btn-edit-save {
  padding: 5px 12px;
  border-radius: 6px;
  border: none;
  background: var(--edit-orange);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}
.btn-edit-save:hover { background: #ca6f1e; }

.btn-edit-cancel {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .12s;
}
.btn-edit-cancel:hover { border-color: var(--danger); color: var(--danger); }

/* Blue drawn-polygon map labels */
.drawn-label {
  background: rgba(41,128,185,.85);
  color: #fff;
  border: 1px solid var(--blue-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  font-family: var(--font);
}
.drawn-label-editing {
  background: rgba(230,126,34,.9);
  border-color: #ca6f1e;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 100%; height: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--divider); }
  body { flex-direction: column; }
  .map-container { flex: 1; height: 60vh; }
  .verify-panel { min-width: 300px; max-width: 90vw; bottom: 12px; }
  .polygon-list-section { max-height: 20vh; }
  .guide-panel { width: calc(100vw - 24px); right: 12px; top: 12px; max-height: 70vh; }
  .guide-fab { top: auto; bottom: 80px; right: 12px; }
  .guide-card img { height: 100px; }
}
