:root {
  --bg: #0a0c0f;
  --bg-2: #0d1014;
  --sidebar: #0c0f13;
  --panel: #13161c;
  --panel-2: #191e26;
  --panel-3: #20262f;
  --border: #242a33;
  --border-strong: #313945;
  --text: #eef1f6;
  --muted: #939cab;
  --faint: #626c7a;
  --accent: #f4f6fa;            /* near-white primary accent */
  --accent-ink: #0a0c0f;        /* text on the accent */
  --accent-dim: rgba(255,255,255,.06);
  --brand: #7c93ff;             /* indigo brand accent (links, focus, markers) */
  --brand-soft: rgba(124,147,255,.14);
  --blue: #7c93ff;
  --pos: #5fd3a3;               /* refined mint for profit/positive */
  --pos-soft: rgba(95,211,163,.14);
  --red: #f1737a;
  --red-soft: rgba(241,115,122,.14);
  --amber: #fbbf24;
  --ring: 0 0 0 3px rgba(124,147,255,.30);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.22);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Custom scrollbars (dark) */
* { scrollbar-width: thin; scrollbar-color: #2b323d transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #2b323d; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #3a4350; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }
::selection { background: rgba(124,147,255,.30); }

.app { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--sidebar);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 18px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 1.02rem; font-weight: 700; padding: 4px 8px 16px; letter-spacing: -.2px; }
/* green tint for the brand mark */
.brand-ic { width: 22px; height: 22px; object-fit: contain; filter: brightness(0) invert(1); }
/* white icons for nav + create menu (black source art inverted to white) */
.nav-item .ic, .create-menu .ic { width: 18px; height: 18px; object-fit: contain; filter: brightness(0) invert(1); opacity: .68; transition: opacity .12s; }
.nav-item:hover .ic { opacity: .95; }
.nav-item.active .ic { opacity: 1; filter: brightness(0) invert(1); }
.create-menu .ic { opacity: .9; }

.create-wrap { position: relative; margin-bottom: 18px; }
.create-btn {
  width: 100%; background: var(--accent); color: var(--accent-ink); border: none; border-radius: 9px;
  padding: 11px 14px; font-size: .92rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px; transition: filter .15s;
}
.create-btn:hover { filter: brightness(1.06); }
.create-btn:active { transform: translateY(1px); }
.create-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.create-btn .caret { font-size: .7rem; opacity: .8; }
.create-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
}
.create-menu.open { display: block; }
.create-menu button {
  width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: 9px 10px; border-radius: 7px; font-size: .88rem; cursor: pointer; display: flex; gap: 9px; align-items: center;
}
.create-menu button:hover { background: var(--panel); }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: none; border: none; color: var(--muted); padding: 9px 11px; border-radius: 8px;
  font-size: .9rem; cursor: pointer; transition: all .12s;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: #fff; font-weight: 600; box-shadow: inset 2px 0 0 var(--brand), 0 1px 2px rgba(0,0,0,.3); }
.nav-item.active .ic { opacity: 1; }

.sidebar-foot { margin-top: auto; color: var(--faint); font-size: .74rem; padding: 12px 8px 2px; text-decoration: none; transition: color .15s; }
.sidebar-foot:hover { color: var(--text); text-decoration: underline; }

/* ── Main ────────────────────────────────────────────────────────────────── */
.main { flex: 1; min-width: 0; padding: 26px 30px 50px; }
.view[hidden] { display: none; }

.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.5px; }
.page-head .sub { color: var(--muted); margin-top: 3px; font-size: .9rem; }
.detail-head { display: flex; align-items: center; gap: 14px; }
.detail-head h1 { font-size: 1.3rem; }
.detail-head .spacer { flex: 1; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 22px; }
.cards-3 { grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); }
.cards-1 { grid-template-columns: minmax(220px, 280px); }
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.018), rgba(255,255,255,0)), var(--panel);
  border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--border-strong); }
.card .label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .7px; font-weight: 600; }
.card .value { font-size: 1.75rem; font-weight: 750; margin-top: 8px; letter-spacing: -.6px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.card .hint { color: var(--faint); font-size: .76rem; margin-top: 5px; }

/* ── Panels & tables ─────────────────────────────────────────────────────── */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; margin-bottom: 16px; overflow-x: auto; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 1rem; font-weight: 650; letter-spacing: -.2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: .86rem; white-space: nowrap; }
.tbl th { color: var(--faint); font-weight: 600; font-size: .7rem; text-transform: uppercase; letter-spacing: .6px; padding-top: 6px; padding-bottom: 9px; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: var(--panel-2); }
.empty { text-align: center; color: var(--faint); padding: 26px !important; font-size: .86rem; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Badges & tags ───────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: .72rem; font-weight: 600; letter-spacing: .2px; }
.b-open { background: var(--pos-soft); color: var(--pos); }
.b-closed { background: rgba(147,156,171,.14); color: var(--muted); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .68rem; font-weight: 600; letter-spacing: .2px; }
.tag-vendor { background: var(--brand-soft); color: var(--brand); }
.tag-contractor { background: rgba(251,191,36,.15); color: var(--amber); }
.i-pending { background: rgba(251,191,36,.15); color: var(--amber); }
.i-scheduled { background: var(--brand-soft); color: var(--brand); }
.i-passed { background: var(--pos-soft); color: var(--pos); }
.i-failed { background: var(--red-soft); color: var(--red); }

.pos { color: var(--pos); }
.neg { color: var(--red); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; font-size: .85rem; font-weight: 500; cursor: pointer;
  transition: all .13s; white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 5px 11px; font-size: .8rem; }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: transparent; }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.accent { color: var(--brand); border-color: var(--brand-soft); background: transparent; }
.btn.accent:hover { background: var(--brand-soft); border-color: var(--brand); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab { background: none; border: none; color: var(--muted); padding: 9px 16px; cursor: pointer; font-size: .88rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: #fff; border-bottom-color: var(--brand); font-weight: 650; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Forms / modals ──────────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(5,7,10,.62); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.overlay.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border-strong); border-radius: 16px; padding: 24px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 30px 80px rgba(0,0,0,.65); }
.modal.wide { max-width: 660px; }
.modal h2 { font-size: 1.15rem; margin-bottom: 18px; font-weight: 700; }
.fg { margin-bottom: 13px; flex: 1; }
.fg label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.fg input, .fg select, .fg textarea {
  width: 100%; padding: 9px 11px; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .88rem; font-family: inherit; transition: border-color .12s, box-shadow .12s;
}
.fg input::placeholder, .fg textarea::placeholder { color: var(--faint); }
.fg input:hover, .fg select:hover, .fg textarea:hover { border-color: var(--border-strong); }
.fg input:focus, .fg select:focus, .fg textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.fg textarea { resize: vertical; }
.row { display: flex; gap: 12px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

#project-notes { width: 100%; padding: 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-family: inherit; font-size: .9rem; resize: vertical; transition: border-color .12s, box-shadow .12s; }
#project-notes:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }

.pay-summary { display: flex; gap: 22px; padding: 4px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 12px; font-size: .9rem; }
.pay-form { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }

.muted { color: var(--muted); font-size: .82rem; }

/* ── Map ─────────────────────────────────────────────────────────────────── */
.map-panel { padding-bottom: 18px; }
#map {
  height: 380px; width: 100%; border-radius: 10px; overflow: hidden;
  background: #0e1116; border: 1px solid var(--border); z-index: 0;
}
.map-fallback { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--faint); font-size: .9rem; }
/* Leaflet dark overrides */
.leaflet-container { background: #0e1116; font-family: inherit; }
.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--panel-2); color: var(--text); border-color: var(--border);
}
.leaflet-bar a:hover { background: #20262f; }
.leaflet-control-attribution {
  background: rgba(11,13,16,.7) !important; color: var(--faint) !important;
}
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.leaflet-popup-content { margin: 12px 14px; font-size: .85rem; }
.leaflet-popup-close-button { color: var(--muted) !important; }
.map-pop strong { font-size: .92rem; }
.map-pop .mp-sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.map-pop .mp-row { display: flex; justify-content: space-between; gap: 18px; margin-top: 6px; }
.map-pop .mp-row span { color: var(--muted); }
.map-pop .mp-open { display: inline-block; margin-top: 10px; color: var(--blue); text-decoration: none; font-weight: 600; }
.map-pop .mp-open:hover { text-decoration: underline; }

@media (max-width: 620px) { #map { height: 280px; } }

/* ── Mobile top bar + drawer ─────────────────────────────────────────────── */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 80;
    background: var(--sidebar); border-bottom: 1px solid var(--border);
    padding: 10px 14px;
  }
  .hamburger {
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    width: 40px; height: 38px; border-radius: 8px; font-size: 1.15rem; line-height: 1; cursor: pointer;
  }
  .hamburger:hover { background: #20262f; }
  .mtb-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1rem; }
  .mtb-brand .brand-ic { width: 20px; height: 20px; }

  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 264px;
    transform: translateX(-100%); transition: transform .22s ease; z-index: 100;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 50px rgba(0,0,0,.65); }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90; }

  .main { padding: 16px 14px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ── Phones ──────────────────────────────────────────────────────────────── */
@media (max-width: 620px) {
  .main { padding: 14px 10px 36px; }
  .page-head h1 { font-size: 1.35rem; }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .cards-1, .cards-3 { grid-template-columns: 1fr; }
  .card .value { font-size: 1.4rem; }
  .row { flex-direction: column; gap: 0; }
  .detail-head { flex-wrap: wrap; gap: 8px; }
  .detail-head h1 { order: 3; width: 100%; font-size: 1.15rem; }
  .detail-head .spacer { display: none; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; }
  .tab { white-space: nowrap; }
  .modal { padding: 18px; }
  .pay-summary { gap: 12px; flex-wrap: wrap; }
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
}
