:root {
  --primary:   #1a6b3c;
  --primary-light: #2e9a5a;
  --primary-dark:  #124d2b;
  --accent:    #3b82f6;
  --danger:    #dc2626;
  --warning:   #d97706;
  --success:   #16a34a;
  --info:      #0891b2;
  --bg:        #f0f7f3;
  --surface:   #ffffff;
  --border:    #d1e7da;
  --text:      #1a2e22;
  --text-muted:#5a7a66;
  --sidebar-w: 220px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary-dark);
  color: #e8f5ee;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.sidebar-brand h1 {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}

.sidebar-brand .subtitle {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.55);
  margin-top: 2px;
}

.sidebar nav { flex: 1; padding: 0.75rem 0; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.sidebar nav a .icon { font-size: 1rem; width: 1.2rem; text-align: center; }

.sidebar-user {
  padding: 0.85rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
}

.sidebar-user strong { display: block; color: #fff; margin-bottom: 2px; }

.sidebar-user a {
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  font-size: 0.78rem;
}
.sidebar-user a:hover { color: #fff; }

/* ── Main content ── */
.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.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h2 { font-size: 1.1rem; font-weight: 600; color: var(--text); }
.topbar .topbar-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 1px; }

.content { padding: 1.5rem; flex: 1; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.card-header {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f7fbf9;
}

.card-header h3 { font-size: 0.95rem; font-weight: 600; }
.card-body { padding: 1.1rem; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

/* ── Stat tiles ── */
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.stat-tile .tile-icon {
  font-size: 1.6rem;
  width: 2.4rem;
  text-align: center;
}

.stat-tile .tile-label { font-size: 0.75rem; color: var(--text-muted); }
.stat-tile .tile-value { font-size: 1.25rem; font-weight: 700; color: var(--primary); }

/* ── Badges / status ── */
.badge {
  display: inline-block;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-active    { background: #dcfce7; color: #15803d; }
.badge-scheduled { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: #f1f5f9; color: #64748b; }
.badge-cancelled { background: #fee2e2; color: #b91c1c; }
.badge-gate      { background: #fef9c3; color: #854d0e; }
.badge-junction  { background: #e0f2fe; color: #075985; }
.badge-admin     { background: #fae8ff; color: #7e22ce; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: #f7fbf9;
  border-bottom: 2px solid var(--border);
  padding: 0.6rem 0.85rem;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f7fbf9; }

.tr-active { background: #f0fdf4 !important; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, filter 0.15s;
}
.btn:hover { filter: brightness(0.92); }

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-secondary { background: #e5f0ea; color: var(--primary-dark); }
.btn-danger    { background: var(--danger);   color: #fff; }
.btn-sm        { padding: 0.28rem 0.6rem; font-size: 0.78rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 0.3rem; color: var(--text-muted); }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=datetime-local],
select, textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(46,154,90,0.15);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-hint { font-size: 0.77rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ── Alerts ── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.alert-success  { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.alert-danger   { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-warning  { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info     { background: #f0f9ff; border: 1px solid #bae6fd; color: #075985; }

/* ── Login page ── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.login-card .logo { text-align: center; margin-bottom: 1.5rem; }
.login-card .logo h1 { font-size: 1.3rem; color: var(--primary-dark); }
.login-card .logo p  { font-size: 0.8rem; color: var(--text-muted); }

/* ── Map embed ── */
.map-container {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.map-container iframe {
  width: 100%;
  height: 420px;
  border: none;
  display: block;
}
.map-placeholder {
  height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f7fbf9;
  color: var(--text-muted);
  gap: 0.5rem;
  font-size: 0.9rem;
}

/* ── Utilities ── */
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.flex  { display: flex; }
.gap-1 { gap: 0.5rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted  { color: var(--text-muted); font-size: 0.85rem; }
.text-right  { text-align: right; }
.nowrap { white-space: nowrap; }

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 480px;
  padding: 1.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  position: relative;
}
.modal h3 { margin-bottom: 1rem; font-size: 1rem; }
.modal-close {
  position: absolute; top: 0.75rem; right: 0.75rem;
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; color: var(--text-muted);
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.25s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
