/* ── Reset & Variables ────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3345;
  --text: #e4e6ef;
  --text2: #9499b3;
  --accent: #6c5ce7;
  --accent2: #a29bfe;
  --success: #00b894;
  --danger: #ff6b6b;
  --warning: #ffc048;
  --info: #74b9ff;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.35);
  --cell-open: #1e2233;
  --cell-wall: #4a4e69;
  --cell-drone: #6c5ce7;
  --cell-source: #00b894;
  --cell-dest: #ff6b6b;
  --cell-path: #ffc048;
  --cell-visited: #2d3250;
  --cell-charger: #74b9ff;
}

[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f5f6fa;
  --border: #dfe1e8;
  --text: #2d3436;
  --text2: #636e72;
  --shadow: 0 2px 12px rgba(0,0,0,.1);
  --cell-open: #f8f9fa;
  --cell-wall: #636e72;
  --cell-visited: #dfe6e9;
}

html { font-size: 15px; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .8rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.5rem; font-weight: 700; color: var(--accent2); }
.subtitle { color: var(--text2); font-size: .82rem; margin-left: .6rem; }
.header-right { display: flex; align-items: center; gap: .8rem; }
.badge {
  background: var(--accent);
  color: #fff;
  padding: .2rem .7rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.1rem;
  padding: .3rem .5rem;
  border-radius: 6px;
  cursor: pointer;
}

/* ── Main Layout ─────────────────────────────────── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}
@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
}

/* ── Panels & Cards ──────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.panel-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; margin-bottom: .8rem; }
.panel-header h2 { font-size: 1.15rem; }
.map-controls { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.map-controls input[type="number"] { width: 48px; }

.card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem;
  margin-bottom: .8rem;
}
.card:last-child { margin-bottom: 0; }
.card h3 { font-size: .95rem; margin-bottom: .6rem; color: var(--accent2); }

/* ── Map Toolbar ─────────────────────────────────── */
.map-toolbar {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .6rem;
  flex-wrap: wrap;
}
.tool-label { font-size: .8rem; color: var(--text2); font-weight: 600; }
.tool-btn {
  padding: .3rem .6rem;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: .78rem;
  transition: all .15s;
}
.tool-btn:hover { border-color: var(--accent); }
.tool-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tool-hint { font-size: .75rem; color: var(--text2); margin-left: auto; }

/* ── Canvas ──────────────────────────────────────── */
.canvas-wrapper {
  background: var(--bg);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  justify-content: center;
  overflow: auto;
}
#map-canvas { cursor: crosshair; border-radius: 4px; }

/* ── Legend ───────────────────────────────────────── */
.map-legend {
  display: flex;
  gap: .8rem;
  flex-wrap: wrap;
  margin-top: .6rem;
  font-size: .75rem;
  color: var(--text2);
}
.legend-box {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 3px;
}
.legend-box.wall   { background: var(--cell-wall); }
.legend-box.open   { background: var(--cell-open); border: 1px solid var(--border); }
.legend-box.drone  { background: var(--cell-drone); }
.legend-box.source { background: var(--cell-source); }
.legend-box.dest   { background: var(--cell-dest); }
.legend-box.path   { background: var(--cell-path); }
.legend-box.visited{ background: var(--cell-visited); }
.legend-box.charger{ background: var(--cell-charger); }

/* ── Buttons ─────────────────────────────────────── */
button {
  padding: .35rem .7rem;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: .8rem;
  transition: all .15s;
}
button:hover { border-color: var(--accent); background: var(--surface); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent2); }
.btn-demo {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
  font-weight: 700;
  font-size: .85rem;
  padding: .45rem 1rem;
  animation: pulse-demo 2s infinite;
}
.btn-demo:hover { background: #00a884; border-color: #00a884; }
@keyframes pulse-demo {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,184,148,.5); }
  50% { box-shadow: 0 0 0 6px rgba(0,184,148,0); }
}
.btn-secondary { margin-top: .5rem; }

/* ── Inputs & Selects ────────────────────────────── */
input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .3rem .5rem;
  border-radius: 6px;
  font-size: .82rem;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); }
label { font-size: .82rem; color: var(--text2); display: flex; align-items: center; gap: .3rem; }

/* ── Fleet ───────────────────────────────────────── */
#fleet-list { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .5rem; }
.fleet-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem .6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .82rem;
}
.fleet-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.fleet-card .drone-icon { font-size: 1.1rem; margin-right: .5rem; }
.fleet-card .drone-name { font-weight: 600; }
.fleet-card .battery-bar {
  width: 60px;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  margin: 0 .5rem;
}
.fleet-card .battery-fill { height: 100%; border-radius: 4px; transition: width .3s; }
.fleet-card .battery-text { font-size: .75rem; color: var(--text2); min-width: 36px; text-align: right; }
.fleet-card .btn-remove { background: none; border: none; color: var(--danger); font-size: .9rem; padding: 0 .3rem; }
.fleet-add { display: flex; gap: .3rem; flex-wrap: wrap; }
.fleet-add input { flex: 1; min-width: 80px; }

/* ── Task Queue ──────────────────────────────────── */
.task-form { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .5rem; }
.task-form input, .task-form select { flex: 1; min-width: 70px; }
#task-list { display: flex; flex-direction: column; gap: .3rem; max-height: 180px; overflow-y: auto; }
.task-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .35rem .5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8rem;
}
.task-card .priority-dot {
  width: 8px; height: 8px; border-radius: 50%; margin-right: .4rem; flex-shrink: 0;
}
.priority-1 { background: var(--text2); }
.priority-2 { background: var(--info); }
.priority-3 { background: var(--warning); }
.priority-4 { background: var(--danger); }
.task-card .task-info { flex: 1; }
.task-card .btn-remove-task { background: none; border: none; color: var(--danger); cursor: pointer; }

/* ── Sim Controls ────────────────────────────────── */
.sim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: center;
}

/* ── Stats Grid ──────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
}
.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem;
  text-align: center;
}
.stat-value { display: block; font-size: 1.3rem; font-weight: 700; color: var(--accent2); }
.stat-label { font-size: .7rem; color: var(--text2); }

/* ── Log Table ───────────────────────────────────── */
.log-wrapper { max-height: 200px; overflow-y: auto; }
#log-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
#log-table th, #log-table td {
  padding: .3rem .4rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
#log-table th { color: var(--text2); font-weight: 600; position: sticky; top: 0; background: var(--surface2); }
.status-ok { color: var(--success); font-weight: 600; }
.status-fail { color: var(--danger); font-weight: 600; }

/* ── Footer ──────────────────────────────────────── */
footer {
  text-align: center;
  padding: .6rem;
  font-size: .75rem;
  color: var(--text2);
  border-top: 1px solid var(--border);
}

/* ── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }
