:root {
  --bg: #f1f5f9;         /* app background */
  --panel: #ffffff;      /* sidebar / panels */
  --panel-2: #f8fafc;    /* cards */
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;     /* primary buttons / links */
  --accent-2: #16a34a;   /* success / leads */
  --orange: #ea580c;     /* map circle accent */
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#app { display: flex; height: 100vh; }

#sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--panel);
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--border);
}

#sidebar h1 { font-size: 20px; margin: 0 0 4px; }
#sidebar h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 0 0 10px; }

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

label { display: block; font-size: 13px; margin-bottom: 12px; color: var(--muted); }
label:last-child { margin-bottom: 0; }

input, select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
input[type=range] { padding: 0; accent-color: var(--orange); }

.row { display: flex; gap: 8px; }
.row input { width: 100%; }

button, .btn-link {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  display: block;
  text-decoration: none;
}
button:hover, .btn-link:hover { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
button.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: var(--panel-2); }
button.small, .small { width: auto; padding: 6px 10px; font-size: 12px; }
#newProjectBtn { flex: 0 0 auto; }

.hint { font-size: 12px; color: var(--muted); margin: 6px 0; }
.badge { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--border); color: var(--text); }
.badge.on { background: #dcfce7; color: #166534; }
.badge.off { background: #fee2e2; color: #991b1b; }

main { flex: 1; position: relative; display: flex; flex-direction: column; }
#map { flex: 1; background: #e5e7eb; }

#results {
  height: 42%;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
#results.hidden { display: none; }

.results-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.results-actions { display: flex; align-items: center; gap: 10px; }
.btn-link { width: auto; padding: 6px 12px; font-size: 13px; background: var(--accent-2); color: #fff; }
.chk { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-size: 13px; }
.chk input { width: auto; margin: 0; }

.table-wrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel-2); z-index: 1; }
td.wrap { white-space: normal; max-width: 240px; }
tr:hover td { background: var(--panel-2); }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th.sortable.sorted { color: var(--accent); }
th.sortable::after { content: attr(data-arrow); font-size: 10px; margin-left: 4px; }

.cat-filter { width: auto; margin-top: 0; padding: 6px 10px; font-size: 13px; max-width: 190px; }

/* Projects */
.project {
  padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  margin: 8px 0 0; cursor: pointer; background: #fff;
}
.project:hover { border-color: var(--accent); }
.project.active { border-color: var(--accent); background: #eff6ff; }

tr.filtered-out td { opacity: 0.5; font-style: italic; }
#placePinBtn.active-mode { background: var(--orange); color: #fff; border-color: var(--orange); }
.project .pname, #activeBanner .pname { font-weight: 600; font-size: 14px; }
.project .pmeta, #activeBanner .pmeta { font-size: 11px; color: var(--muted); margin-top: 3px; }
#activeBanner .pmeta { margin-bottom: 10px; }
#activeBanner .pname b, .project .pmeta b { color: var(--accent-2); }
#activeBanner .row { gap: 6px; }

/* Searches (jobs) */
.job {
  padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 8px; cursor: pointer; background: #fff;
}
.job:hover { border-color: var(--accent); }
.jhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.jname { font-weight: 600; font-size: 13px; }
.jmeta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.jbtns { display: flex; gap: 4px; flex: 0 0 auto; margin-left: auto; }
.rescan, .jlog, .jstop, .jresume, .jdel { background: #fff; color: var(--accent); border: 1px solid var(--border); padding: 4px 8px; }
.jdel { color: #dc2626; }
.jdel:hover:not(:disabled) { background: #dc2626; color: #fff; }
.rescan:hover:not(:disabled) { background: var(--accent); color: #fff; }
.jlog:hover { background: var(--panel-2); }
.jstop { color: var(--orange); }
.jstop:hover { background: var(--orange); color: #fff; }
.jresume { color: var(--accent-2); }
.jresume:hover { background: var(--accent-2); color: #fff; }

/* Search log overlay */
#logOverlay {
  position: absolute; top: 12px; right: 12px; width: min(520px, calc(100% - 24px));
  max-height: 60%; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(15,23,42,0.18);
  display: flex; flex-direction: column; z-index: 1000;
}
#logOverlay.hidden { display: none; }
.log-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.log-head .small { width: auto; }
#logBody { overflow: auto; padding: 8px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.logline { padding: 3px 0; border-bottom: 1px solid var(--panel-2); white-space: pre-wrap; word-break: break-word; }
.logts { color: var(--muted); margin-right: 6px; }
.lvl-error { color: #b91c1c; }
.lvl-warning { color: #b45309; }
.lvl-info { color: var(--text); }
.progress { height: 6px; background: var(--border); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }

.status-pill { font-size: 10px; padding: 1px 6px; border-radius: 10px; text-transform: uppercase; }
.status-running { background: #dbeafe; color: #1e40af; }
.status-done { background: #dcfce7; color: #166534; }
.status-error { background: #fee2e2; color: #991b1b; }
.status-pending { background: var(--border); color: var(--muted); }
.status-stopped { background: #fef3c7; color: #92400e; }
.status-stopping { background: #ffedd5; color: #9a3412; }

.yes { color: var(--accent-2); }
.no { color: #dc2626; font-weight: 600; }
a.ext { color: var(--accent); }

/* Mobile drawer controls (hidden on desktop) */
#menuToggle {
  display: none;
  position: fixed; bottom: 16px; left: 16px; z-index: 1600;
  width: auto; padding: 12px 18px; border-radius: 24px;
  background: var(--accent); color: #fff; font-weight: 600;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.3);
}
#drawerBackdrop { display: none; }

@media (max-width: 760px) {
  /* Map is the full-screen canvas; controls & results are bottom sheets. */
  #app { display: block; height: 100vh; height: 100dvh; }
  main { height: 100vh; height: 100dvh; }
  #map { height: 100%; }

  #menuToggle { display: block; }

  #drawerBackdrop {
    display: block; position: fixed; inset: 0; z-index: 1400;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.28s ease;
  }
  body.drawer-open #drawerBackdrop { opacity: 1; pointer-events: auto; }

  #sidebar {
    position: fixed; left: 0; right: 0; bottom: 0;
    width: 100%; min-width: 0; height: 85vh; height: 85dvh;
    border-right: none; border-radius: 18px 18px 0 0;
    padding-top: 24px; z-index: 1500;
    box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.28);
    transform: translateY(100%); transition: transform 0.28s ease;
  }
  body.drawer-open #sidebar { transform: translateY(0); }
  /* grab handle */
  #sidebar::before {
    content: ""; position: absolute; top: 9px; left: 50%; transform: translateX(-50%);
    width: 44px; height: 5px; border-radius: 3px; background: var(--border);
  }

  #results {
    position: fixed; left: 0; right: 0; bottom: 0; height: 70vh; height: 70dvh;
    z-index: 1300; border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.28);
  }

  /* Touch targets & no iOS zoom on focus */
  input, select, textarea { font-size: 16px; }
  button, .btn-link { min-height: 44px; }
  .small { min-height: 38px; }
  .jbtns { gap: 6px; }
  .rescan, .jlog, .jstop, .jresume, .jdel { min-height: 40px; min-width: 40px; padding: 8px 10px; }
  #newProjectBtn { min-width: 48px; }
  .chk { min-height: 40px; }
  .results-actions { flex-wrap: wrap; gap: 8px 12px; }
  .cat-filter { max-width: none; flex: 1 1 100%; min-height: 40px; }

  /* Results as cards instead of a wide horizontal-scroll table */
  #bizTable thead { display: none; }
  #bizTable, #bizTable tbody, #bizTable tr, #bizTable td { display: block; width: 100%; }
  #bizTable tr {
    border: 1px solid var(--border); border-radius: 12px;
    margin-bottom: 10px; padding: 10px 14px; background: #fff;
  }
  #bizTable tr:hover td { background: transparent; }
  #bizTable td {
    border: none; padding: 3px 0; white-space: normal; max-width: none;
    display: flex; gap: 10px; align-items: baseline;
  }
  #bizTable td.empty { display: none; }
  #bizTable td::before {
    content: attr(data-label); font-weight: 600; color: var(--muted);
    flex: 0 0 84px; font-size: 12px;
  }
  #bizTable td[data-label="Nume"] {
    font-weight: 700; font-size: 16px; margin-bottom: 4px;
    padding-bottom: 6px; border-bottom: 1px solid var(--panel-2);
  }
  #bizTable td[data-label="Nume"]::before { display: none; }
  #bizTable tr.filtered-out { opacity: 0.6; }
  #bizTable tr.filtered-out td { opacity: 1; }
}
