/* ImmoData UI — palette per the validated reference dataviz palette.
   Roles are defined once as custom properties; dark mode swaps values. */

:root {
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11, 11, 11, 0.10);
  --series-1:    #2a78d6;   /* blue  — market */
  --series-1-lo: #86b6ef;   /* blue 250 — min line */
  --series-2:    #1baf7a;   /* aqua  — rent  */
  --series-2-lo: #55c39a;
  --good:        #006300;
  --good-chip:   #0ca30c;
  --warning:     #fab219;
  --critical:    #d03b3b;
  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --shadow:      0 1px 3px rgba(11, 11, 11, 0.07), 0 6px 18px rgba(11, 11, 11, 0.05);
}

:root[data-theme="dark"] {
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --baseline:    #383835;
  --border:      rgba(255, 255, 255, 0.10);
  --series-1:    #3987e5;
  --series-1-lo: #1c5cab;
  --series-2:    #199e70;
  --series-2-lo: #0e5f43;
  --good:        #0ca30c;
  --good-chip:   #0ca30c;
  --accent:      #3987e5;
  --shadow:      0 1px 3px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

#app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}

.hidden { display: none !important; }
.muted  { color: var(--muted); font-weight: 400; }

/* ------------------------------------------------------------- sidebar -- */

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.brand-mark { font-size: 26px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub  { font-size: 11px; color: var(--muted); }
.brand .icon-btn { margin-left: auto; }

.sidebar-section {
  padding: 14px 16px 6px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-section:first-of-type { flex: 1 1 55%; }
.sidebar-jobs { flex: 1 1 45%; border-top: 1px solid var(--border); }

.sidebar-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.city-list {
  overflow-y: auto;
  margin-top: 10px;
  min-height: 0;
}

.city-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.city-item:hover  { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.city-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.city-item .city-name { font-weight: 600; }
.city-item .city-sub  { font-size: 11.5px; color: var(--muted); }

.jobs-list { overflow-y: auto; min-height: 0; }

.job-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--surface);
}
.job-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.job-name { font-weight: 600; font-size: 12.5px; }
.job-msg  {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--grid);
  margin-top: 7px;
  overflow: hidden;
}
.job-progress > div {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s;
}
.job-progress.indeterminate > div {
  width: 30% !important;
  animation: slide 1.2s ease-in-out infinite alternate;
}
@keyframes slide { from { margin-left: 0; } to { margin-left: 70%; } }

.chip {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 99px;
  white-space: nowrap;
}
.chip.queued    { background: var(--grid); color: var(--ink-2); }
.chip.running   { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.chip.done      { background: color-mix(in srgb, var(--good-chip) 18%, transparent); color: var(--good); }
.chip.error     { background: color-mix(in srgb, var(--critical) 15%, transparent); color: var(--critical); }
.chip.cancelled { background: var(--grid); color: var(--muted); }

.badge {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 99px;
  font-size: 10px;
  padding: 1px 7px;
}

.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
}

/* ---------------------------------------------------------------- main -- */

.main {
  overflow-y: auto;
  padding: 22px 26px 40px;
  min-width: 0;
}

.welcome {
  max-width: 480px;
  margin: 18vh auto;
  text-align: center;
  color: var(--ink-2);
}
.welcome h1 { color: var(--ink); }

.city-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}
.city-header h1 {
  margin: 0 0 2px;
  font-size: 24px;
  letter-spacing: 0.01em;
}
.city-actions { display: flex; gap: 8px; }

/* ------------------------------------------------------------ controls -- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  min-width: 160px;
  flex: 1 1 160px;
  max-width: 300px;
}

.input, select.input {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
.input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); }

/* --------------------------------------------------------------- tiles -- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.tile-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  display: flex;
  flex-direction: column;
}
.tile-unit { font-size: 10.5px; font-weight: 400; color: var(--muted); }
.tile-value {
  font-size: 27px;
  font-weight: 700;
  margin-top: 6px;
}
.tile-delta { font-size: 12px; margin-top: 2px; }
.tile-delta.up   { color: var(--good); }
.tile-delta.down { color: var(--critical); }

/* --------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  min-width: 0;
}
.card-title {
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 6px;
}

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 1100px) { .charts { grid-template-columns: 1fr; } }

.chart      { width: 100%; height: 320px; }
.chart-tall { height: 380px; }

/* --------------------------------------------------------------- table -- */

.table-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.data-table th, .data-table td {
  text-align: right;
  padding: 7px 12px;
  border-bottom: 1px solid var(--grid);
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th {
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ------------------------------------------------------------- buttons -- */

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
.btn:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }

.icon-btn {
  font: inherit;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
  color: var(--ink-2);
}
.icon-btn:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.icon-btn.danger:hover {
  background: color-mix(in srgb, var(--critical) 12%, transparent);
  border-color: var(--critical);
}
.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 11.5px;
  padding: 0;
}

/* --------------------------------------------------------------- modal -- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: min(460px, 92vw);
  padding: 22px;
  max-height: 88vh;
  overflow-y: auto;
}
.modal h2 { margin: 0 0 6px; }
.modal .control { margin-top: 12px; max-width: none; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.callout {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  padding: 10px 12px;
  font-size: 12.5px;
  margin-top: 12px;
}
.callout.warning {
  border-left-color: var(--warning);
  background: color-mix(in srgb, var(--warning) 8%, var(--surface));
}

.empty-note { color: var(--muted); font-size: 12px; padding: 6px 2px; }

/* --------------------------------------------------------------- toast -- */

.toasts {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--ink);
  color: var(--page);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: pop 0.18s ease-out;
  max-width: 380px;
}
.toast.error { background: var(--critical); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------ narrow -- */

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-section:first-of-type { flex-basis: auto; }
  .city-list { max-height: 240px; }
  .jobs-list { max-height: 200px; }
}
