/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-warning: #d97706;
  --color-success: #16a34a;
  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-400: #9ca3af;
  --color-gray-600: #4b5563;
  --color-gray-800: #1f2937;
  --color-white: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,.15);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.18);
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body { font-family: var(--font); color: var(--color-gray-800); background: var(--color-gray-50); }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-card {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo { margin-bottom: .75rem; }
.login-logo img { width: 80px; height: 80px; object-fit: contain; }
.login-card h1 { font-size: 1.25rem; color: var(--color-gray-800); margin-bottom: 1.75rem; font-weight: 600; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 1rem; text-align: left; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; color: var(--color-gray-600); margin-bottom: .375rem; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .625rem .875rem;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius);
  font-size: .9375rem;
  font-family: var(--font);
  transition: border-color .15s, box-shadow .15s;
  background: var(--color-white);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .625rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: .9375rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); color: var(--color-white); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-dark); }

.btn-success { background: var(--color-success); color: var(--color-white); }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger { background: var(--color-danger); color: var(--color-white); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-secondary { background: var(--color-gray-100); color: var(--color-gray-800); border: 1px solid var(--color-gray-200); }
.btn-secondary:hover:not(:disabled) { background: var(--color-gray-200); }

.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: .375rem .75rem; font-size: .8125rem; }

/* ===== ALERTS ===== */
.error-msg { color: var(--color-danger); font-size: .875rem; margin-bottom: .75rem; padding: .5rem .75rem; background: #fef2f2; border-radius: var(--radius); border: 1px solid #fecaca; }
.success-msg { color: var(--color-success); font-size: .875rem; margin-bottom: .75rem; padding: .5rem .75rem; background: #f0fdf4; border-radius: var(--radius); border: 1px solid #bbf7d0; }
.hidden { display: none !important; }

/* ===== MAP PAGE ===== */
.map-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .625rem 1rem;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-gray-200);
  box-shadow: var(--shadow-sm);
  z-index: 1000;
  flex-shrink: 0;
}
.topbar-logo { display: flex; align-items: center; }
.topbar-logo img { width: 36px; height: 36px; object-fit: contain; }
.topbar-title { font-weight: 600; font-size: 1rem; color: var(--color-gray-800); }
.topbar-user { margin-left: auto; font-size: .875rem; color: var(--color-gray-600); }
.topbar-actions { display: flex; gap: .5rem; }

.map-container { display: flex; flex: 1; overflow: hidden; }

#map { flex: 1; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 340px;
  background: var(--color-white);
  border-left: 1px solid var(--color-gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .25s;
  flex-shrink: 0;
}
.sidebar.collapsed { width: 0; }

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--color-gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.sidebar-header h2 { font-size: 1rem; font-weight: 600; }
.sidebar-close { background: none; border: none; cursor: pointer; font-size: 1.25rem; color: var(--color-gray-400); padding: .25rem; border-radius: 4px; }
.sidebar-close:hover { color: var(--color-gray-800); background: var(--color-gray-100); }

.sidebar-body { padding: 1rem; overflow-y: auto; flex: 1; }

.station-info-name { font-size: 1.125rem; font-weight: 600; margin-bottom: .25rem; }
.station-info-address { font-size: .875rem; color: var(--color-gray-600); margin-bottom: 1rem; }

.status-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.status-active { background: #dcfce7; color: #15803d; }
.status-closed { background: var(--color-gray-100); color: var(--color-gray-600); }

/* Fuel table */
.fuel-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.fuel-table th { text-align: left; padding: .5rem .75rem; background: var(--color-gray-50); color: var(--color-gray-600); font-weight: 500; border-bottom: 1px solid var(--color-gray-200); }
.fuel-table td { padding: .5rem .75rem; border-bottom: 1px solid var(--color-gray-100); }
.fuel-table tr:last-child td { border-bottom: none; }

.fuel-bar-wrap { background: var(--color-gray-100); border-radius: 999px; height: 6px; width: 80px; overflow: hidden; display: inline-block; vertical-align: middle; margin-left: .5rem; }
.fuel-bar { height: 100%; border-radius: 999px; transition: width .3s; }
.fuel-bar.ok { background: var(--color-success); }
.fuel-bar.low { background: var(--color-warning); }
.fuel-bar.critical { background: var(--color-danger); }

/* ===== STATION PAGE ===== */
.station-page { min-height: 100vh; background: var(--color-gray-50); }

.station-header {
  background: var(--color-white);
  border-bottom: 1px solid var(--color-gray-200);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}
.station-header h1 { font-size: 1.125rem; font-weight: 600; }
.back-link { color: var(--color-primary); text-decoration: none; font-size: .875rem; display: flex; align-items: center; gap: .25rem; }
.back-link:hover { text-decoration: underline; }

.station-content { max-width: 900px; margin: 0 auto; padding: 1.5rem; display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 700px) { .station-content { grid-template-columns: 1fr; } }

.card { background: var(--color-white); border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow-sm); border: 1px solid var(--color-gray-200); }
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: var(--color-gray-800); }

#miniMap { height: 220px; border-radius: var(--radius); overflow: hidden; margin-bottom: .75rem; border: 1px solid var(--color-gray-200); }

.coords-display { font-size: .8125rem; color: var(--color-gray-600); margin-bottom: .75rem; }

/* Fuel editor */
.fuel-editor-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.fuel-editor-row input { padding: .4rem .6rem; border: 1px solid var(--color-gray-200); border-radius: var(--radius); font-size: .875rem; }
.fuel-editor-row input:focus { outline: none; border-color: var(--color-primary); }
.fuel-editor-header { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: .5rem; font-size: .75rem; font-weight: 500; color: var(--color-gray-600); margin-bottom: .375rem; }

.add-fuel-btn { margin-top: .5rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--color-gray-800);
  color: var(--color-white);
  padding: .75rem 1.25rem;
  border-radius: var(--radius);
  font-size: .875rem;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { background: var(--color-success); }
.toast.toast-error { background: var(--color-danger); }

/* Marker legend */
.map-legend {
  position: absolute;
  bottom: 2rem;
  left: 1rem;
  background: var(--color-white);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  box-shadow: var(--shadow-md);
  z-index: 500;
  font-size: .8125rem;
}
.legend-item { display: flex; align-items: center; gap: .5rem; margin-bottom: .375rem; }
.legend-item:last-child { margin-bottom: 0; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.dot-ok { background: #16a34a; }
.dot-low { background: #d97706; }
.dot-critical { background: #dc2626; }
.dot-closed { background: #9ca3af; }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== PAGE CONTAINER (my-stations, station-detail, admin-stations) ===== */
.page-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.375rem; font-weight: 700; }

/* ===== STATIONS GRID (my-stations) ===== */
.stations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.station-card {
  background: var(--color-white);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  transition: box-shadow .15s;
}
.station-card:hover { box-shadow: var(--shadow-md); }
.station-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
}
.station-card-name { font-weight: 600; font-size: 1rem; }
.station-card-address { font-size: .875rem; color: var(--color-gray-600); }
.station-card-footer { margin-top: auto; }

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: .25rem;
  border-bottom: 2px solid var(--color-gray-200);
  margin-bottom: 1.5rem;
}
.tab-btn {
  padding: .625rem 1.25rem;
  border: none;
  background: none;
  font-size: .9375rem;
  font-family: var(--font);
  font-weight: 500;
  color: var(--color-gray-600);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: color .15s, border-color .15s, background .15s;
}
.tab-btn:hover { color: var(--color-primary); background: var(--color-gray-50); }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== FORM SECTIONS (station-detail info tab) ===== */
.form-section {
  background: var(--color-white);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.form-section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--color-gray-100);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .75rem 1rem;
}
.form-grid-compact {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.form-group-wide { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}
.save-status { font-size: .875rem; }
.save-ok { color: var(--color-success); }
.save-error { color: var(--color-danger); }

/* ===== FUEL SECTIONS (station-detail fuel tab) ===== */
.fuel-section {
  background: var(--color-white);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.fuel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.25rem;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--color-gray-100);
  background: var(--color-gray-50);
}
.fuel-section-header:hover { background: var(--color-gray-100); }
.fuel-section-header h3 { font-size: .9375rem; font-weight: 600; }
.toggle-icon { font-size: .75rem; color: var(--color-gray-400); }
.fuel-section-body { padding: 1rem 1.25rem; }
.section-toolbar { margin-bottom: .75rem; }

/* ===== INLINE FORM ===== */
.inline-form {
  background: var(--color-gray-50);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.inline-form h4 { font-size: .9375rem; font-weight: 600; margin-bottom: .75rem; }

/* ===== DATA TABLE ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table th {
  text-align: left;
  padding: .5rem .75rem;
  background: var(--color-gray-50);
  color: var(--color-gray-600);
  font-weight: 500;
  border-bottom: 1px solid var(--color-gray-200);
  white-space: nowrap;
}
.data-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--color-gray-100);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--color-gray-50); }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-ok { background: #dcfce7; color: #15803d; }
.badge-low { background: #fef3c7; color: #92400e; }
.badge-critical { background: #fee2e2; color: #b91c1c; }
.badge-pending { background: #fef9c3; color: #92400e; }
.badge-error { background: #fee2e2; color: #b91c1c; }

/* Fuel status badges (sidebar map) */
.fuel-status-badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  vertical-align: middle;
}
.fuel-status-ok       { background: #dcfce7; color: #15803d; }
.fuel-status-low      { background: #fef3c7; color: #92400e; }
.fuel-status-critical { background: #fee2e2; color: #b91c1c; }

/* ===== BUTTON SIZES ===== */
.btn-xs { padding: .2rem .5rem; font-size: .75rem; }

/* ===== TEXT HELPERS ===== */
.text-muted { color: var(--color-gray-400); font-size: .875rem; }
.text-error { color: var(--color-danger); font-size: .875rem; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}
.modal-box {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  max-width: 380px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.modal-box p { font-size: 1rem; margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: .75rem; justify-content: center; }

/* ===== ADMIN STATIONS TABLE ===== */
.admin-table-wrap { overflow-x: auto; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  background: var(--color-white);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-gray-200);
}
.admin-table th {
  text-align: left;
  padding: .625rem 1rem;
  background: var(--color-gray-50);
  color: var(--color-gray-600);
  font-weight: 600;
  border-bottom: 1px solid var(--color-gray-200);
  white-space: nowrap;
}
.admin-table td {
  padding: .625rem 1rem;
  border-bottom: 1px solid var(--color-gray-100);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--color-gray-50); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .page-container { padding: 1rem .75rem; }
  .form-grid { grid-template-columns: 1fr; }
  .stations-grid { grid-template-columns: 1fr; }
  .topbar-title { display: none; }
}
