/* ==========================================================================
   Jobber <-> GHL integration console.

   The palette and the card treatment are carried over from the single inline
   <style> block this replaces, so the app looks like itself. What is new is
   that it is a stylesheet: the shell moved to a sidebar, the values became
   custom properties, and the one-off rules that had accumulated for a single
   page are now components the five pages share.
   ========================================================================== */

:root {
  /* Brand */
  --ink: #1c1c46;
  --ink-soft: #2b2b5e;
  --ink-muted: #6a6a85;

  /* Surfaces */
  --canvas: #eef1f4;
  --surface: #ffffff;
  --surface-sunken: #fafbfc;
  --border: #e3e6ea;
  --border-soft: #eef0f3;

  /* States */
  --success: #1c7c33;
  --success-bg: #dff5e1;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --danger: #b3261e;
  --danger-bg: #fde3e3;
  --danger-border: #f0c2bf;
  --accent: #3b5bdb;

  /* Scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lift: 0 8px 24px rgba(28, 28, 70, 0.14);

  --sidebar-width: 232px;
  --font: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--canvas);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
}

a { color: var(--accent); }

h1 { font-size: 22px; margin: 0 0 var(--space-2); }
h2 { font-size: 17px; margin: 0 0 var(--space-3); }
h3 { font-size: 14px; margin: 0 0 var(--space-2); }

code, .mono, pre { font-family: var(--mono); }

/* --------------------------------------------------------------------------
   Shell: fixed sidebar, scrolling content.
   -------------------------------------------------------------------------- */

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.sidebar .brand span { display: block; font-weight: 400; font-size: 11px; opacity: 0.6; margin-top: 2px; }

.sidebar nav { padding: var(--space-3) 0; flex: 1; }
.sidebar nav a {
  display: block;
  padding: 9px var(--space-5);
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.sidebar nav a.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border-left-color: #fff;
}
.sidebar nav .group {
  padding: var(--space-4) var(--space-5) var(--space-1);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.4);
}

.sidebar .who {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}
.sidebar .who strong { color: #fff; display: block; }
.sidebar .who form { margin: var(--space-2) 0 0; }
.sidebar .who button {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.sidebar .who button:hover { background: rgba(255, 255, 255, 0.12); }

.content { flex: 1; min-width: 0; padding: var(--space-6) var(--space-6) var(--space-6); }
.content > header { margin-bottom: var(--space-5); }
.content > header .lede { color: var(--ink-muted); max-width: 78ch; margin: 0; }

.crumb { font-size: 12px; color: var(--ink-muted); margin-bottom: var(--space-2); }
.crumb a { color: var(--ink-muted); }

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.card > h2 { margin-top: 0; }
.card .card-lede { color: var(--ink-muted); font-size: 13px; margin: -4px 0 var(--space-4); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2, .card.flush > .card-lede { padding: 0 var(--space-5); }
.card.flush > h2 { padding-top: var(--space-5); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--space-5); }
.grid-2 > .card { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */

.table-scroll { overflow-x: auto; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  white-space: nowrap;
}
table.grid td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: var(--surface-sunken); }
table.grid.rows-plain tbody tr:hover { background: none; }

.acct { font-weight: 700; }
.mono { font-size: 11px; color: var(--ink-muted); word-break: break-all; }
.small { font-size: 11px; }
.muted { color: var(--ink-muted); }
.nowrap { white-space: nowrap; }
.spacer { height: var(--space-2); }
.hint { font-size: 12px; color: var(--ink-muted); margin-top: var(--space-1); }
.hint a { color: var(--accent); }

/* --------------------------------------------------------------------------
   Badges, chips, status dots
   -------------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.connected, .badge.on, .badge.success { background: var(--success-bg); color: var(--success); }
.badge.not-connected, .badge.failed { background: var(--danger-bg); color: var(--danger); }
.badge.warn, .badge.partial { background: var(--warn-bg); color: var(--warn); }
.badge.off, .badge.neutral, .badge.queued, .badge.running { background: #edeff2; color: #5b6270; }

.chip {
  display: inline-block;
  background: #f2f4f7;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  white-space: nowrap;
}
.chip em { color: var(--ink-muted); font-style: normal; }
.counts { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-2); margin: var(--space-3) 0; }

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: var(--space-1);
  flex-shrink: 0;
}
.dot.success { background: var(--success); }
.dot.partial { background: #d99400; }
.dot.failed { background: var(--danger); }
.dot.idle, .dot.queued, .dot.running { background: #c8ccd4; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background-color: var(--ink);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:hover { background-color: var(--ink-soft); }
.btn.small { padding: 5px 11px; font-size: 12px; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: #c8ccd4; }
.btn.ghost:hover { background: var(--surface-sunken); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger-border); }
.btn.danger:hover { background: var(--danger-bg); }
.btn[disabled] { background-color: #e9ebee; color: #9aa0a8; border-color: #e0e3e7; cursor: not-allowed; }
.btn[disabled]:hover { background-color: #e9ebee; }

.rowbtns { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-2); margin-top: var(--space-2); align-items: center; }
.rowbtns form { margin: 0; }

.actions-bar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.actions-bar form { margin: 0; }

/* The sync-toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 24px; flex-shrink: 0; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; cursor: pointer; background-color: #ccc; transition: 0.2s; border-radius: 24px; }
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: 0.2s;
  border-radius: 50%;
}
input:checked + .slider { background-color: var(--ink); }
input:checked + .slider:before { transform: translateX(22px); }
input:disabled + .slider { opacity: 0.5; cursor: not-allowed; }

/* A smaller variant for an inline per-sync toggle (e.g. sync direction),
   where the full-size switch would dwarf the button next to it. */
.switch.small { width: 34px; height: 18px; }
.switch.small .slider:before { height: 12px; width: 12px; left: 3px; bottom: 3px; }
.switch.small input:checked + .slider:before { transform: translateX(16px); }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.field { margin-bottom: var(--space-5); }
.field > label { display: block; font-weight: 600; font-size: 13px; margin-bottom: var(--space-1); }
.field .helptext { display: block; font-size: 12px; color: var(--ink-muted); margin-top: var(--space-1); max-width: 76ch; }
.field .errorlist { list-style: none; margin: var(--space-1) 0 0; padding: 0; color: var(--danger); font-size: 12px; font-weight: 600; }

input.input, select.input, textarea.input, input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  max-width: 520px;
  padding: 8px 10px;
  border: 1px solid #c8ccd4;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
}
input.input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(59, 91, 219, 0.35);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea.code { font-family: var(--mono); font-size: 12px; max-width: none; min-height: 240px; }
.field.invalid input.input { border-color: var(--danger); }

fieldset.group { border: none; padding: 0; margin: 0 0 var(--space-6); }
fieldset.group > legend {
  padding: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
  width: 100%;
  padding-bottom: var(--space-2);
}

.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.filters .field { margin-bottom: 0; }
.filters select, .filters input.input { max-width: 240px; min-width: 150px; }

/* --------------------------------------------------------------------------
   Messages, callouts
   -------------------------------------------------------------------------- */

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
  font-size: 13px;
}
.flash.success { background: var(--success-bg); color: var(--success); }
.flash.warning { background: var(--warn-bg); color: var(--warn); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash.info { background: #e7edfb; color: #23408e; }

.fatal {
  background: #fdf1f0;
  border-left: 3px solid var(--danger);
  color: #8c1d18;
  padding: var(--space-2) var(--space-3);
  font-size: 12px;
  margin: var(--space-2) 0;
  white-space: pre-wrap;
}
.note {
  background: var(--surface-sunken);
  border-left: 3px solid var(--border);
  padding: var(--space-2) var(--space-3);
  font-size: 12px;
  color: var(--ink-muted);
  margin: var(--space-3) 0;
}
.note.warn { background: var(--warn-bg); border-left-color: #d99400; color: var(--warn); }

.empty { padding: var(--space-6); text-align: center; color: var(--ink-muted); }
.empty p { margin: 0 0 var(--space-4); }

/* --------------------------------------------------------------------------
   Disclosure, key/value lists, code output
   -------------------------------------------------------------------------- */

details.disclose { margin-top: var(--space-2); }
details.disclose > summary { cursor: pointer; font-size: 12px; color: var(--ink-muted); }
details.disclose > summary:hover { color: var(--ink); }
details.disclose ul { margin: var(--space-2) 0 0; padding-left: 18px; }

dl.kv { margin: 0; display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: var(--space-2) var(--space-4); font-size: 13px; }
dl.kv dt { color: var(--ink-muted); }
dl.kv dd { margin: 0; word-break: break-word; }

pre.out {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 460px;
  overflow: auto;
  background: var(--surface-sunken);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
}
pre.out.short { max-height: 220px; }
pre.out.failed { background: #fdf1f0; border-color: var(--danger-border); }

/* Rejection bodies are long and must not stretch the table -- scroll them. */
table.errors td pre { margin: 0; }
table.errors { margin-top: var(--space-3); }

.stat-row { display: flex; flex-wrap: wrap; gap: var(--space-5); }
.stat { min-width: 110px; }
.stat .n { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); }

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */

.pager { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-4); font-size: 13px; }
.pager .spread { flex: 1; }

/* --------------------------------------------------------------------------
   Sync button list, shared by the dashboard and a location page
   -------------------------------------------------------------------------- */

.syncrow { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); margin: 0 0 var(--space-2); }
.syncbtn { display: flex; align-items: center; gap: var(--space-2); margin: 0; }
.syncbtn .hint { margin: 0; }
.syncbtn > .btn { min-width: 168px; }

/* A row's own reverse-direction counterpart (e.g. Design Consultation's
   "GHL -> Jobber" button) nests visually under it instead of reading as its
   own unrelated sync: indented, in the lighter `.ghost` button style so the
   two directions are told apart at a glance, and drawn close against the row
   above it -- which in turn shrinks its own bottom margin via :has() below,
   so the pair reads as one group and the normal gap only reappears after it. */
.syncrow:has(+ .syncrow--reverse) { margin-bottom: 2px; }
.syncrow--reverse { margin-left: 28px; margin-top: 0; margin-bottom: var(--space-3); }
.syncrow--reverse .connector { display: inline-block; }
.syncrow--reverse .connector::before { content: "\21b3"; margin-right: var(--space-1); opacity: 0.55; }

.direction-toggle { display: flex; align-items: center; gap: var(--space-1); margin: 0; }
.direction-toggle .hint { margin: 0; }

.runline { margin-bottom: var(--space-1); display: flex; align-items: center; gap: var(--space-1); }
.runline .lbl { font-weight: 600; }

/* --------------------------------------------------------------------------
   Login
   -------------------------------------------------------------------------- */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-5); }
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  padding: var(--space-6);
  width: 100%;
  max-width: 380px;
}
.login-card h1 { font-size: 19px; }
.login-card .lede { color: var(--ink-muted); font-size: 13px; margin: 0 0 var(--space-5); }
.login-card input.input { max-width: none; }
.login-card .btn { width: 100%; margin-top: var(--space-2); }

/* --------------------------------------------------------------------------
   Narrow screens: the sidebar becomes a strip along the top.
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { display: flex; flex-wrap: wrap; padding: 0 var(--space-3) var(--space-3); }
  .sidebar nav a { border-left: none; border-bottom: 3px solid transparent; padding: 8px var(--space-3); }
  .sidebar nav a.active { border-left-color: transparent; border-bottom-color: #fff; }
  .sidebar nav .group { display: none; }
  .content { padding: var(--space-4); }
}

@media print {
  .sidebar, .actions-bar, .rowbtns, .pager { display: none; }
  .card { box-shadow: none; border: 1px solid var(--border); }
}
