:root {
  --bg: #0a0a0a;
  --surface: #0d1a0d;
  --surface2: #132613;
  --accent: #22c55e;
  --accent-hover: #4ade80;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --text: #e2e8e0;
  --muted: #7a9a7a;
  --border: #1a3a1a;
  --radius: 12px;
  --coord-border: #22c55e;
  --coord-bg: rgba(34, 197, 94, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* Navbar */
.navbar {
  display: flex;
  flex-direction: column;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 1100;
}
.nav-top-row {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  width: 100%;
  box-sizing: border-box;
}
.nav-logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.nav-center {
  display: flex;
  gap: 16px;
  align-items: center;
  flex: 1;
  justify-content: center;
}
.nav-danger-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
  justify-content: center;
  padding: 0 16px 8px;
}
/* Fire danger badge */
.fire-danger-badge {
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.2s;
}
.fire-danger-badge:hover { opacity: 0.8; }
.fd-extra { display: none; }
.fd-toggle-row {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 2px;
}
.fire-danger-toggle {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0 12px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}

.nav-links {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  flex-direction: column;
  padding: 16px 24px;
  gap: 12px;
  min-width: 200px;
  z-index: 1200;
  align-items: flex-end;
  text-align: right;
}
.nav-links.open { display: flex; }
.nav-show-mobile-only { display: none; }
.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 17px;
  font-weight: 500;
  transition: color 0.2s;
}
.nav-link:hover { color: var(--text); }
.nav-link.chat-unread,
.nav-link.fire-unread-confirmed {
  color: var(--danger);
  animation: chat-pulse 1.5s ease-in-out infinite;
}
.nav-link.fire-unread-suspicion {
  color: #f59e0b;
  animation: fire-orange-pulse 1.5s ease-in-out infinite;
}
@keyframes fire-orange-pulse {
  0%, 100% { color: #f59e0b; }
  50% { color: rgba(245,158,11,0.3); }
}
@keyframes chat-pulse {
  0%, 100% { color: var(--danger); }
  50% { color: rgba(239,68,68,0.3); }
}
.hamburger {
  display: block;
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
}

/* Container */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  text-align: center;
}
.alert-error { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.alert-success { background: rgba(34,197,94,0.15); color: var(--accent); border: 1px solid rgba(34,197,94,0.3); }

/* Buttons */
.btn {
  padding: 10px 22px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  line-height: 1;
  box-sizing: border-box;
  vertical-align: middle;
}
.btn-primary { background: var(--accent); color: #0a0a0a; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--accent); color: #0a0a0a; }
.btn-success:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-lg { padding: 16px 36px; font-size: 18px; border-radius: 14px; min-width: 200px; }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 8px; }
.btn-full { width: 100%; }

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}
.login-title {
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
}
.login-subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 28px;
}
.login-box form { display: flex; flex-direction: column; gap: 14px; }

/* Inputs */
.input {
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
.input:focus { border-color: var(--accent); }
select.input { appearance: none; cursor: pointer; }

/* Dashboard */
.dashboard-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
  gap: 16px;
  text-align: center;
}
.dashboard-header h1 { font-size: 28px; font-weight: 700; }

.coordinator-section { margin-bottom: 14px; }
.company-card.full-width { width: 100%; }

.companies-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.company-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.3s;
}
.company-card:hover { border-color: rgba(34,197,94,0.4); }
.company-card.coordinator {
  border-color: var(--coord-border);
  background: var(--coord-bg);
}
.company-card.coordinator:hover { border-color: var(--coord-border); }

.company-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.company-header h2 { font-size: 17px; font-weight: 600; }
.badge-coord {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--coord-border);
  background: rgba(34,197,94,0.12);
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

.duty-list, .patrol-list { padding: 8px 12px; min-height: 36px; text-align: center; }
.duty-person {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 5px 0;
  text-align: center;
}
.duty-person + .duty-person { border-top: 1px solid var(--border); }
.duty-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.duty-end-form { flex-shrink: 0; }
.duty-person strong { font-size: 15px; }
.duty-person small { color: var(--muted); font-size: 14px; }
.duty-person small a, .duty-person a { color: #fff; text-decoration: none; }
.no-duty { color: var(--muted); font-size: 14px; font-style: italic; text-align: center; margin: 0; }

/* Fire reports */
.fire-section { margin-bottom: 24px; }
.fire-report-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
}
.fire-report-box h3 { font-size: 16px; font-weight: 600; margin-bottom: 14px; text-align: center; }
.fire-form { display: flex; flex-direction: column; gap: 12px; }
.fire-fields { display: flex; gap: 12px; }
.fire-fields .input { flex: 1; }
.fire-buttons { display: flex; gap: 12px; justify-content: center; }
.btn-fire-suspicion {
  background: #f59e0b;
  color: #0a0a0a;
  padding: 12px 24px;
  font-size: 15px;
}
.btn-fire-suspicion:hover { background: #fbbf24; }
.btn-fire-confirmed {
  background: var(--danger);
  color: #fff;
  padding: 12px 24px;
  font-size: 15px;
}
.btn-fire-confirmed:hover { background: var(--danger-hover); }
.btn-fire-edit { background: var(--accent); color: #0a0a0a; }
.btn-fire-edit:hover { opacity: 0.85; }
.btn-fire-share { background: #3b82f6; color: #fff; }
.btn-fire-share:hover { background: #2563eb; }
.btn-fire-close { background: #000; color: var(--danger); border: 2px solid var(--danger); }
.btn-fire-close:hover { background: #1a0000; }

.fire-active { margin-top: 16px; }
.fire-active h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.fire-alert {
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
}
.fire-alert.fire-suspicion {
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.4);
}
.fire-alert.fire-confirmed {
  background: rgba(239,68,68,0.12);
  border: 2px solid var(--danger);
  animation: fire-pulse 1.5s infinite;
}
@keyframes fire-pulse {
  0%, 100% { border-color: var(--danger); }
  50% { border-color: rgba(239,68,68,0.3); }
}
.fire-alert { text-align: center; }
.fire-alert-header { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.fire-alert-header strong { font-size: 15px; }
.fire-alert.fire-confirmed .fire-alert-header strong { color: var(--danger); }
.fire-alert.fire-suspicion .fire-alert-header strong { color: #f59e0b; }
.fire-meta { font-size: 13px; color: var(--muted); }
.fire-location { display: flex; gap: 16px; font-size: 14px; flex-wrap: wrap; justify-content: center; align-items: baseline; }
.fire-actions { display: flex; gap: 6px; margin-top: 8px; justify-content: center; align-items: center; }
.fire-resolve-form { display: inline; }
.fire-edit-form { margin-top: 10px; }

@media (max-width: 768px) {
  .fire-fields { flex-direction: column; }
  .fire-buttons { flex-direction: column; }
  .fire-buttons .btn { width: 100%; }
  .fire-actions { flex-wrap: wrap; }
  .fire-actions .btn, .fire-actions form { flex-shrink: 0; }
}

/* Admin */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.admin-header h1 { font-size: 28px; font-weight: 700; }

.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
}
.table th, .table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th {
  background: var(--surface2);
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(34,197,94,0.04); }
.table.sortable th[data-col] { cursor: pointer; user-select: none; transition: color 0.2s; }
.table.sortable th[data-col]:hover { color: var(--accent); }
.sort-arrow { font-size: 11px; }
.actions { display: flex; gap: 8px; flex-wrap: nowrap; }
.table td { vertical-align: top; }

/* Form page */
.form-page { max-width: 500px; margin: 0 auto; }
.form-page h1 { font-size: 28px; font-weight: 700; margin-bottom: 24px; }
.user-form { display: flex; flex-direction: column; gap: 16px; }
.user-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
.form-actions { display: flex; gap: 12px; margin-top: 8px; }

/* Responsive */
@media (max-width: 768px) {
  .nav-hide-mobile { display: none !important; }
  .nav-show-mobile-only { display: block; }
  .nav-links { left: 0; right: 0; min-width: auto; border-radius: 0; border-bottom: 1px solid var(--border); }
  .nav-links .nav-link { font-size: 19px; }
  .nav-center { gap: 10px; }
  .nav-center .nav-link { font-size: 16px; }
  .companies-grid { grid-template-columns: 1fr; }
  .dashboard-header { flex-direction: column; align-items: stretch; text-align: center; }
  .btn-lg { width: 100%; }
  #historia-table th, #historia-table td { padding: 8px 6px; font-size: 12px; }
  #historia-table th:nth-child(2), #historia-table td:nth-child(2) { display: none; }
  .trail-modal-content { width: 95%; margin: 10px; }
  #fires-panel { grid-template-columns: 1fr !important; }
  #fire-danger-container { flex-direction: row; flex-wrap: wrap; justify-content: center; width: 100%; }
  .fire-danger-badge { text-align: center; }
  .input[name="coordinates"]::placeholder { font-size: 10px; }
}

/* Trail map modal */
.trail-modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.trail-modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 90%;
  max-width: 800px;
}
.trail-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.trail-modal-header h3 { font-size: 18px; font-weight: 600; }

/* Trail button */
.btn-trail {
  background: #3b82f6;
  color: #fff;
  font-size: 12px;
}
.btn-trail:hover { background: #60a5fa; }

/* LOT button */
.btn-lot {
  width: 240px;
  height: 240px;
  border: 6px solid #3b82f6;
  border-radius: 24px;
  background: transparent;
  color: #3b82f6;
  font-size: 64px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-lot:hover { background: rgba(59,130,246,0.1); }
.btn-lot.btn-lot-active {
  background: #3b82f6;
  color: #fff;
  animation: lot-border-pulse 1.5s infinite;
}
@keyframes lot-border-pulse {
  0%, 100% { border-color: #3b82f6; box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { border-color: #ef4444; box-shadow: 0 0 12px 4px rgba(239,68,68,0.3); }
}

/* GPS inactive warning */
.gps-inactive {
  display: inline-block;
  background: rgba(239,68,68,0.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  margin-left: 8px;
  animation: gps-blink 2s infinite;
}
@keyframes gps-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Chat */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  max-width: 800px;
  margin: 0 auto;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}
.chat-mine {
  align-self: flex-end;
  background: var(--accent);
  color: #0a0a0a;
  border-bottom-right-radius: 4px;
}
.chat-other {
  align-self: flex-start;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}
.chat-sender .chat-company {
  font-weight: 400;
  color: var(--muted);
  font-size: 11px;
}
.chat-mine .chat-time {
  text-align: right;
  font-size: 11px;
  opacity: 0.7;
  margin-top: 2px;
}
.chat-other .chat-time {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.chat-private {
  border: 1px dashed #a78bfa !important;
}
.chat-private.chat-mine {
  background: #7c3aed;
  color: #fff;
}
.chat-private-label {
  font-size: 11px;
  font-weight: 600;
  color: #c4b5fd;
  margin-bottom: 2px;
}
.chat-mine .chat-private-label {
  color: rgba(255,255,255,0.7);
}
.chat-receiver-wrap {
  position: relative;
  width: 180px;
  flex-shrink: 0;
}
.chat-receiver-select {
  width: 100%;
  min-height: 42px;
}
.chat-receiver-dropdown {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
  margin-bottom: 4px;
}
.chat-dd-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--foreground);
}
.chat-dd-item:hover {
  background: var(--accent);
}
.chat-input {
  display: flex;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-input textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 120px;
}
.chat-input .btn {
  height: 42px;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .chat-container { height: calc(100vh - 140px); }
  .chat-bubble { max-width: 85%; }
  .chat-input { flex-wrap: wrap; }
  .chat-receiver-wrap { width: 100%; }
}
