/* ============================================================
   IGWS2 Platform — Main Stylesheet
   Aesthetic: Refined industrial — dark sidebar, slate surfaces,
   cyan accent. Inspired by maritime/satellite operations consoles.
   Font: DM Sans (body) + DM Mono (data/code)
   ============================================================ */



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

:root {
  /* Palette */
  --bg-base:       #0d1117;
  --bg-panel:      #161b22;
  --bg-card:       #1c2128;
  --bg-input:      #21262d;
  --bg-hover:      #262c36;

  --border:        rgba(240,246,252,.12);
  --border-strong: rgba(240,246,252,.22);

  --text-primary:  #e6edf3;
  --text-secondary:#8b949e;
  --text-muted:    #484f58;

  --accent:        #00d4c8;       /* cyan */
  --accent-dim:    rgba(0,212,200,.12);
  --accent-border: rgba(0,212,200,.3);

  --green:         #3fb950;
  --yellow:        #d29922;
  --red:           #f85149;
  --blue:          #58a6ff;
  --orange:        #e3b341;

  --sidebar-w:     240px;
  --topbar-h:      56px;
  --radius:        8px;
  --radius-sm:     5px;
  --shadow:        0 4px 24px rgba(0,0,0,.45);
  --transition:    .18s cubic-bezier(.4,0,.2,1);
}

html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ──────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  grid-row: 1 / -1;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-logo {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo .logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo .logo-icon svg { width: 16px; height: 16px; fill: #000; }
.sidebar-logo .logo-text { font-weight: 600; font-size: 15px; letter-spacing: .02em; }
.sidebar-logo .logo-ver  { font-size: 10px; color: var(--text-muted); margin-left: auto; font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}
.nav-section { margin-bottom: 20px; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  transition: color var(--transition), background var(--transition);
  position: relative;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; transition: opacity var(--transition); }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
}
.nav-item.active svg { opacity: 1; }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  padding: 1px 6px;
  border-radius: 20px;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.sidebar-user .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: 10px; color: var(--text-muted); text-transform: capitalize; }
.sidebar-user .logout-btn {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color var(--transition);
}
.sidebar-user .logout-btn:hover { color: var(--red); }

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
}
.topbar-title { font-size: 15px; font-weight: 500; }
.topbar-breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.topbar-breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.topbar-breadcrumb a:hover { color: var(--accent); }
.topbar-breadcrumb .sep { color: var(--text-muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  overflow-y: auto;
  padding: 24px;
  background: var(--bg-base);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-title { font-size: 14px; font-weight: 500; }
.card-body { padding: 18px; }

/* ── Stat cards ───────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--border-strong); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}
.stat-card.cyan::before  { background: var(--accent); }
.stat-card.green::before { background: var(--green); }
.stat-card.yellow::before{ background: var(--yellow); }
.stat-card.red::before   { background: var(--red); }
.stat-card.blue::before  { background: var(--blue); }

.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 600; font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; line-height: 1; }
.stat-sub   { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  background: var(--bg-panel);
  padding: 8px 12px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
}
thead th:hover { color: var(--text-primary); }
thead th.sorted-asc::after  { content: ' ↑'; color: var(--accent); }
thead th.sorted-desc::after { content: ' ↓'; color: var(--accent); }
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child { border-bottom: none; }
td { padding: 9px 12px; vertical-align: middle; }
td.mono { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 11.5px; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 500;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  white-space: nowrap;
}
.badge-green  { background: rgba(63,185,80,.12); color: var(--green);  border: 1px solid rgba(63,185,80,.3); }
.badge-red    { background: rgba(248,81,73,.12);  color: var(--red);    border: 1px solid rgba(248,81,73,.3); }
.badge-yellow { background: rgba(210,153,34,.12); color: var(--orange); border: 1px solid rgba(210,153,34,.3); }
.badge-blue   { background: rgba(88,166,255,.12); color: var(--blue);   border: 1px solid rgba(88,166,255,.3); }
.badge-cyan   { background: var(--accent-dim);    color: var(--accent);  border: 1px solid var(--accent-border); }
.badge-gray   { background: rgba(139,148,158,.1); color: var(--text-secondary); border: 1px solid var(--border); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-primary  { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover { background: #00bfb4; border-color: #00bfb4; }
.btn-danger   { background: rgba(248,81,73,.15); color: var(--red); border-color: rgba(248,81,73,.3); }
.btn-danger:hover { background: rgba(248,81,73,.25); }
.btn-ghost    { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-strong); }
.btn-sm       { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  transition: border-color var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.form-control::placeholder { color: var(--text-muted); }
select.form-control option { background: var(--bg-card); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-mono { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Toolbar/Filters ──────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.toolbar .spacer { flex: 1; }
.search-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12.5px;
  padding: 6px 10px 6px 32px;
  width: 220px;
  outline: none;
  transition: border-color var(--transition), width var(--transition);
}
.search-input:focus { border-color: var(--accent); width: 280px; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-muted); pointer-events: none; }

/* ── Pagination ───────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 4px; padding: 12px 18px; border-top: 1px solid var(--border); }
.page-btn { display: flex; align-items: center; justify-content: center; width: 30px; height: 28px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: transparent; color: var(--text-secondary); cursor: pointer; font-size: 12px; font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; transition: all var(--transition); }
.page-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.page-btn.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent-border); }
.page-info { margin-left: auto; font-size: 11px; color: var(--text-muted); font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 90%; max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(12px) scale(.98);
  transition: transform var(--transition);
}
.modal-backdrop.open .modal { transform: none; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-title  { font-size: 15px; font-weight: 500; flex: 1; }
.modal-close  { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: var(--radius-sm); transition: color var(--transition); }
.modal-close:hover { color: var(--text-primary); }
.modal-body   { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Map ──────────────────────────────────────────────────── */
#map { height: 400px; width: 100%; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.leaflet-container { background: #0d1117; font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; }
.leaflet-popup-content-wrapper { background: var(--bg-card); border: 1px solid var(--border-strong); box-shadow: var(--shadow); border-radius: var(--radius) !important; }
.leaflet-popup-content { color: var(--text-primary); font-family: 'DM Sans', sans-serif; font-size: 12px; }
.leaflet-popup-tip { background: var(--bg-card); }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
}
.alert svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: rgba(63,185,80,.1); color: var(--green); border-color: rgba(63,185,80,.3); }
.alert-danger   { background: rgba(248,81,73,.1);  color: var(--red);   border-color: rgba(248,81,73,.3); }
.alert-warning  { background: rgba(210,153,34,.1); color: var(--orange);border-color: rgba(210,153,34,.3); }
.alert-info     { background: var(--accent-dim);   color: var(--accent); border-color: var(--accent-border); }

/* ── Toast notifications ──────────────────────────────────── */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
  animation: slideIn .2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Pulse dot ────────────────────────────────────────────── */
.pulse-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  position: relative;
}
.pulse-dot.online  { background: var(--green); }
.pulse-dot.offline { background: var(--text-muted); }
.pulse-dot.online::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: var(--green);
  opacity: .3;
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(1); opacity: .3; } 100% { transform: scale(2.5); opacity: 0; } }

/* ── Column picker ────────────────────────────────────────── */
.col-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.col-tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 11.5px;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.col-tag:hover { border-color: var(--accent-border); color: var(--accent); }
.col-tag.active { background: var(--accent-dim); border-color: var(--accent-border); color: var(--accent); }
.col-tag .drag-handle { cursor: grab; opacity: .5; }

/* ── Misc ─────────────────────────────────────────────────── */
.text-mono { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; }
.text-muted { color: var(--text-secondary); }
.text-small { font-size: 11.5px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; align-items: center; gap: 8px; }
.gap-4 { gap: 4px; }
.ml-auto { margin-left: auto; }
.mt-16 { margin-top: 16px; }
.mt-8  { margin-top: 8px; }
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-muted); gap: 10px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px; color: var(--text-muted); }
.empty-state svg { width: 36px; height: 36px; margin: 0 auto 12px; display: block; opacity: .3; }

/* ── Scrollbars ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .layout { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .search-input { width: 100%; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
