/* ============================================================
 * Twenty Sync — design tokens + app shell
 * Based on the Brayden design system handoff.
 * ============================================================ */

:root,
[data-theme="light"] {
  --primary: #5954f9;
  --primary-deep: #4843db;
  --primary-darker: #3934bc;
  --accent-lilac: #9a86f5;
  --on-primary: #ffffff;
  --ink: #0f1020;
  --on-ink: #ffffff;
  --text-muted: #5c5e78;
  --text-tertiary: #888aa0;
  --canvas: #ffffff;
  --canvas-soft: #f2f2f7;
  --canvas-elevated: #ffffff;
  --hairline: #e5e5ec;
  --border-strong: #cfcfda;
  --success: #46ca8d;
  --success-deep: #1f8857;
  --success-soft: #e8f7ef;
  --info: #07cfcc;
  --info-deep: #006b69;
  --info-soft: #e0f8f7;
  --warning: #e6a800;
  --warning-deep: #8a6500;
  --warning-soft: #fbf3dc;
  --danger: #fd0044;
  --danger-deep: #b00031;
  --danger-soft: #ffe6ec;

  --shadow-1: 0 6px 18px rgba(15, 16, 32, 0.06), 0 1px 3px rgba(15, 16, 32, 0.04);
  --shadow-2: 0 18px 40px rgba(15, 16, 32, 0.10), 0 4px 12px rgba(15, 16, 32, 0.05);
  --focus-ring: 0 0 0 3px rgba(89, 84, 249, 0.30);

  --r-xs: 8px;
  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-full: 999px;

  color-scheme: light;
}

[data-theme="dark"] {
  --ink: #ffffff;
  --on-ink: #0e0e14;
  --text-muted: #9b9da8;
  --text-tertiary: #6e7080;
  --canvas: #0e0e14;
  --canvas-soft: #181822;
  --canvas-elevated: #22222e;
  --hairline: #23232e;
  --border-strong: #3a3a48;
  --success-deep: #7fdbac;
  --success-soft: rgba(70, 202, 141, 0.10);
  --info-deep: #5ee5e3;
  --info-soft: rgba(7, 207, 204, 0.10);
  --warning-deep: #f4c44a;
  --warning-soft: rgba(230, 168, 0, 0.10);
  --danger-deep: #ff6688;
  --danger-soft: rgba(253, 0, 68, 0.12);

  --shadow-1: 0 6px 18px rgba(0, 0, 0, 0.50), 0 1px 3px rgba(0, 0, 0, 0.40);
  --shadow-2: 0 18px 40px rgba(0, 0, 0, 0.65), 0 4px 12px rgba(0, 0, 0, 0.50);
  --focus-ring: 0 0 0 3px rgba(89, 84, 249, 0.40);

  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body { min-height: 100vh; }

::selection { background: rgba(89, 84, 249, 0.25); }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }

button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
input, textarea, select { color: var(--ink); background: transparent; }
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--canvas); }

/* ---------- typography ---------- */
.t-display-lg { font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 700; font-size: 30px; line-height: 1.20; letter-spacing: -0.3px; }
.t-display-md { font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 700; font-size: 22px; line-height: 1.25; }
.t-heading    { font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 700; font-size: 18px; line-height: 1.4; }
.t-label-strong { font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 700; font-size: 15px; line-height: 1.4; }
.t-body-strong { font-family: "Inter", sans-serif; font-weight: 700; font-size: 15px; line-height: 1.5; }
.t-body-sm { font-family: "Inter", sans-serif; font-weight: 400; font-size: 13px; line-height: 1.5; }
.t-mono { font-family: "IBM Plex Mono", "JetBrains Mono", ui-monospace, monospace; font-weight: 400; font-size: 12px; line-height: 1.55; }
.t-mono-strong { font-family: "IBM Plex Mono", "JetBrains Mono", ui-monospace, monospace; font-weight: 700; font-size: 12px; line-height: 1.55; }
.t-eyebrow { font-family: "IBM Plex Mono", "JetBrains Mono", ui-monospace, monospace; font-weight: 700; font-size: 11px; line-height: 1.4; letter-spacing: 0.44px; text-transform: uppercase; }
.t-micro { font-family: "IBM Plex Mono", "JetBrains Mono", ui-monospace, monospace; font-weight: 700; font-size: 10px; line-height: 1.55; letter-spacing: 1.4px; text-transform: uppercase; }
.muted { color: var(--text-muted); }
.tertiary { color: var(--text-tertiary); }

h1, h2, h3 { margin: 0; color: var(--ink); letter-spacing: -0.01em; }

.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; }
hr.rule { border: 0; border-top: 1px solid var(--hairline); margin: 0; }

/* ---------- buttons ---------- */
button.btn, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--r-full);
  padding: 9px 18px;
  font-family: "Inter", sans-serif;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  white-space: nowrap;
  user-select: none;
  transition: transform 80ms ease, box-shadow 120ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary-deep); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-darker); }
.btn-secondary { background: var(--canvas); color: var(--ink); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--canvas-soft); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--canvas-soft); }
.btn-danger { background: var(--danger); color: var(--on-primary); }
.btn-danger:hover { background: var(--danger-deep); }
.btn-util {
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--r-full);
  background: var(--canvas);
  color: var(--text-muted);
  border: 1px solid var(--hairline);
}
.btn-util:hover { color: var(--ink); background: var(--canvas-soft); }
.btn-util.is-active { color: var(--ink); background: var(--canvas-soft); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

/* ---------- form primitives ---------- */
.input, .select, .textarea {
  width: 100%;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.select { padding-right: 32px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.textarea { resize: vertical; min-height: 80px; font-family: "IBM Plex Mono", monospace; font-size: 13px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: var(--focus-ring); outline: none; }
.input.is-error, .textarea.is-error { border-color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label {
  font-family: "Inter", sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
}
.field-hint { color: var(--text-muted); font-size: 13px; }
.field-error { color: var(--danger-deep); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .field-grid { grid-template-columns: 1fr; } }

/* ---------- pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--r-full);
  border: 1px solid var(--hairline);
  background: var(--canvas);
  color: var(--text-muted);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  line-height: 1.4;
  white-space: nowrap;
}
.pill-soft { background: var(--canvas-soft); font-size: 11px; letter-spacing: 0.44px; padding: 4px 10px; }
.pill-success { color: var(--success-deep); }
.pill-warning { color: var(--warning-deep); }
.pill-danger  { color: var(--danger-deep); }
.pill-info    { color: var(--info-deep); }
.pill-primary { color: var(--primary); }

.ok-text   { color: var(--success-deep); font-weight: 700; }
.warn-text { color: var(--warning-deep); font-weight: 700; }
.err-text  { color: var(--danger-deep);  font-weight: 700; }

/* ---------- status dots ---------- */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-tertiary);
  flex-shrink: 0;
}
.dot-success { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot-warning { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.dot-danger  { background: var(--danger);  box-shadow: 0 0 0 3px var(--danger-soft); }
.dot-info    { background: var(--info);    box-shadow: 0 0 0 3px var(--info-soft); }
.dot-primary { background: var(--primary); box-shadow: 0 0 0 3px rgba(89,84,249,0.18); }
@keyframes ts-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(89, 84, 249, 0.45); }
  100% { box-shadow: 0 0 0 10px rgba(89, 84, 249, 0); }
}
.dot-pulse { animation: ts-pulse 1.6s ease-out infinite; }

/* ---------- icons ---------- */
.svg-icon { width: 16px; height: 16px; flex-shrink: 0; }
.svg-icon-sm { width: 14px; height: 14px; flex-shrink: 0; }
.svg-icon-lg { width: 20px; height: 20px; flex-shrink: 0; }

/* ---------- app shell ---------- */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* TOP NAV */
.topnav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--hairline);
  background: var(--canvas);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topnav .brand {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; padding: 0; cursor: pointer;
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--primary-deep);
  color: var(--on-primary);
  display: grid; place-items: center;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.5px;
}
/* Brand tile rendering an image (the Brayden icon) instead of initials —
   no tile background or corner clipping, the icon renders as-is. */
.brand-mark-img { background: transparent; border-radius: 0; }
.brand-mark-img img { width: 100%; height: 100%; display: block; }
.brand-wm {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.4px;
  color: var(--ink);
  text-transform: uppercase;
}
.brand-wm .sub {
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 6px;
  text-transform: none;
  letter-spacing: 0;
  font-family: "Inter", sans-serif;
  font-size: 13px;
}
.topnav-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.kbd {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 3px 7px;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  background: var(--canvas);
}

/* THEME TOGGLE */
.theme-toggle {
  display: inline-flex;
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--r-full);
  padding: 3px;
  gap: 2px;
}
.theme-toggle button {
  width: 28px; height: 26px;
  border: 0;
  background: transparent;
  border-radius: var(--r-full);
  color: var(--text-muted);
  display: grid; place-items: center;
  padding: 0;
}
.theme-toggle button.is-active {
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15,16,32,0.08);
}
.logout-form { margin: 0; }

/* BODY GRID — sidebar + content */
.body {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 0;
}

/* Mobile menu button (hidden on desktop) */
.mobile-menu-btn {
  display: none;
  width: 38px; height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--canvas);
  color: var(--ink);
  padding: 0;
  flex-shrink: 0;
}
.mobile-menu-btn:hover { background: var(--canvas-soft); }
.mobile-menu-btn:active { background: var(--canvas-soft); }

/* Sidebar close button (only shown when drawer is open) */
.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--canvas);
  color: var(--text-muted);
  padding: 0;
  z-index: 2;
}
.sidebar-close-btn:hover { color: var(--ink); background: var(--canvas-soft); }

/* Sidebar drawer backdrop (mobile only) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 16, 32, 0.45);
  z-index: 45;
  animation: ts-fade 140ms ease;
}
[data-theme="dark"] .sidebar-backdrop { background: rgba(0, 0, 0, 0.60); }

@media (max-width: 900px) {
  .body { grid-template-columns: minmax(0, 1fr); }
  .mobile-menu-btn { display: inline-flex; }
  /* Full mobile drawer overrides live at the bottom of this file
     so they win over the base .sidebar rule defined below. */
}

/* SIDEBAR */
.sidebar {
  border-right: 1px solid var(--hairline);
  background: var(--canvas);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
}
.sb-section { display: flex; flex-direction: column; gap: 4px; }
.sb-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 4px;
}
.sb-section-head .label {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-xs);
  cursor: pointer;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.3;
  position: relative;
  border: 1px solid transparent;
}
.sb-row:hover { background: var(--canvas-soft); }
.sb-row.is-active {
  background: var(--canvas-soft);
  border-color: var(--hairline);
}
.sb-row.is-active::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 16px;
  background: var(--primary);
  border-radius: 2px;
}
.sb-row .body-block { flex: 1; min-width: 0; }
.sb-row .name {
  font-family: "Inter", sans-serif;
  font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-row .meta {
  color: var(--text-tertiary);
  font-size: 11px;
  font-family: "IBM Plex Mono", monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sb-row .icon-tile {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: grid; place-items: center;
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  color: var(--text-muted);
  flex-shrink: 0;
}
.sb-row.is-active .icon-tile { background: var(--canvas); }

.sb-search { position: relative; }
.sb-search input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--canvas);
  font-size: 13px;
}
.sb-search .lens {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  display: flex;
}
.sb-search .kbd-hint {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
}

/* Inline "new account" button in a sidebar section header. */
.sb-add {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; padding: 0;
  border: none; border-radius: 6px;
  background: transparent; color: var(--text-muted);
  cursor: pointer;
}
.sb-add:hover { background: var(--canvas-soft); color: var(--ink); }
.sb-add .svg-icon { width: 12px; height: 12px; }

.sb-footer {
  margin-top: auto;
  padding: 8px 10px;
  border-top: 1px solid var(--hairline);
  color: var(--text-tertiary);
}

/* CONTENT */
.content {
  padding: 28px 32px 80px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}
@media (max-width: 700px) {
  .content { padding: 20px 18px 60px; }
}

/* PAGE HEADER */
.page-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-head .title-block { flex: 1 1 320px; min-width: 0; }
.page-head h1 {
  margin: 0 0 6px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: -0.3px;
}
.page-head .subtitle {
  color: var(--text-muted);
  font-size: 14px;
}
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.eyebrow {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* TABS */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 24px;
  overflow-x: auto;
}
.tabs .tab {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  border: 0;
  background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tabs .tab:hover { color: var(--ink); }
.tabs .tab.is-active { color: var(--ink); border-bottom-color: var(--primary); }
.tabs .tab .count {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 1.4px;
  background: var(--canvas-soft);
  border-radius: 999px;
  padding: 1px 6px;
  color: var(--text-muted);
}

/* KPI grid */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 900px) { .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpi-row { grid-template-columns: 1fr; } }
.kpi {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 18px 20px;
}
.kpi .num {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -0.3px;
  line-height: 1.1;
  margin-bottom: 4px;
}
.kpi .delta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.44px;
  color: var(--text-muted);
}
.kpi .delta.up { color: var(--success-deep); }
.kpi .delta.down { color: var(--danger-deep); }

/* connection diagram */
.diagram {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-1);
}
.diagram-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}
@media (max-width: 760px) {
  .diagram-row { grid-template-columns: 1fr; }
  .diagram-row .diagram-line { height: 32px; }
  .diagram-row .diagram-line svg {
    transform: rotate(90deg);
    width: 60px !important;
    height: 16px;
  }
}
.diagram-node {
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--canvas-soft);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.diagram-node.is-center {
  background: var(--canvas);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(89,84,249,0.10);
}
.diagram-node .role {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.diagram-node .label {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.diagram-line {
  position: relative;
  height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.diagram-line svg { width: 80px; height: 16px; }
.diagram-line .lbl { font-family: "IBM Plex Mono", monospace; color: var(--text-tertiary); margin-top: 4px; font-size: 11px; }

/* section card */
.section-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow-1);
  margin-bottom: 20px;
}
.section-card .section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.section-card h3 {
  margin: 0 0 4px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0;
}
.section-card .desc { color: var(--text-muted); font-size: 14px; max-width: 56ch; }

/* toggle */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.toggle .track {
  width: 36px; height: 22px;
  background: var(--hairline);
  border-radius: 999px;
  position: relative;
  transition: background 120ms ease;
  flex-shrink: 0;
}
.toggle .thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: var(--canvas);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 140ms ease;
}
.toggle.is-on .track { background: var(--primary-deep); }
.toggle.is-on .thumb { transform: translateX(14px); }

/* checkbox */
.checkbox {
  width: 18px; height: 18px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--canvas);
  display: inline-grid; place-items: center;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
}
.checkbox.is-on { background: var(--primary-deep); border-color: var(--primary-deep); }
.checkbox.is-on::after {
  content: "";
  width: 10px; height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}

/* segmented control */
.seg-control {
  display: inline-flex;
  background: var(--canvas-soft);
  border-radius: var(--r-full);
  padding: 3px;
  border: 1px solid var(--hairline);
  gap: 2px;
}
.seg-control button {
  padding: 6px 12px;
  border: 0;
  background: transparent;
  border-radius: var(--r-full);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.seg-control button.is-active {
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15,16,32,0.06);
}

/* mapping/filter rows */
.map-row {
  display: grid;
  grid-template-columns: 180px 110px 1fr 28px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
}
.map-row:last-child { border-bottom: 0; }
.map-row.is-header {
  padding-bottom: 6px;
}
.icon-btn {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  display: grid; place-items: center;
  padding: 0;
}
.icon-btn:hover { background: var(--canvas-soft); color: var(--ink); }

.filter-row {
  display: grid;
  grid-template-columns: 1fr 140px 1fr 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.filter-connector {
  font-family: "IBM Plex Mono", "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  padding: 2px 0 6px 4px;
}
.filter-conjunction {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.filter-conjunction .select {
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  min-width: 120px;
}
.filter-conjunction[hidden] { display: none; }
@media (max-width: 700px) {
  .filter-row { grid-template-columns: 1fr 1fr; }
  .filter-row .filter-value { grid-column: 1 / -1; }
  .filter-row .icon-btn { justify-self: end; }
  .map-row { grid-template-columns: 1fr; gap: 6px; }
  .map-row.is-header { display: none; }
}

/* lists chip picker */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--hairline);
  background: var(--canvas);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}
.chip.is-on {
  background: rgba(89, 84, 249, 0.10);
  color: var(--primary);
  border-color: var(--primary);
}
.chip .count {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
}
.chip.is-on .count { color: var(--primary); }

/* credential rows */
.cred-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  margin-bottom: 8px;
}
.cred-row .label {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.cred-row .value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}
.cred-row .actions { display: flex; gap: 4px; }

/* run log */
.runlog { display: flex; flex-direction: column; }
.runlog .run {
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--hairline);
}
.runlog .run:last-child { border-bottom: 0; }
.runlog .when { color: var(--text-muted); font-size: 13px; font-family: "IBM Plex Mono", monospace; }
.runlog .stats {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.runlog .stats .ok { color: var(--success-deep); }
.runlog .stats .err { color: var(--danger-deep); }
.runlog .stats .warn { color: var(--warning-deep); }

/* modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 16, 32, 0.40);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 20px;
  animation: ts-fade 140ms ease;
}
[data-theme="dark"] .modal-backdrop { background: rgba(0, 0, 0, 0.60); }
@keyframes ts-fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: 22px;
  max-width: 460px;
  width: 100%;
  animation: ts-toast-in 180ms ease;
}
.modal .modal-foot {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px;
}

/* alerts */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 12px 16px;
}
.alert-success { color: var(--success-deep); }
.alert-info    { color: var(--info-deep); }
.alert-warning { color: var(--warning-deep); }
.alert-danger  { color: var(--danger-deep); }

/* empty state */
.empty {
  background: var(--canvas-soft);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  padding: 60px 24px;
  text-align: center;
}
.empty h2 {
  margin: 12px 0 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 22px;
  font-weight: 700;
}
.empty p { color: var(--text-muted); max-width: 38ch; margin: 0 auto 18px; }

/* code chip */
.codechip {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--ink);
}

/* spinner */
@keyframes ts-spin { to { transform: rotate(360deg); } }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  animation: ts-spin 0.7s linear infinite;
  display: inline-block;
}

/* toast stack */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: 12px 14px;
  min-width: 280px;
  max-width: 360px;
  animation: ts-toast-in 200ms ease;
}
.toast.is-leaving { animation: ts-toast-out 180ms ease forwards; }
@keyframes ts-toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes ts-toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(6px); }
}
.toast .toast-title { font-weight: 700; font-size: 14px; }
.toast .toast-desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.toast .toast-close { background: transparent; border: 0; color: var(--text-muted); padding: 0; align-self: flex-start; cursor: pointer; }

/* progress (in-editor sync progress) */
.progress {
  margin-bottom: 20px;
  padding: 14px 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--canvas-soft);
  display: grid;
  gap: 10px;
}
.progress.done {
  border-color: color-mix(in srgb, var(--success-deep) 35%, transparent);
  background: var(--success-soft);
}
.progress.err {
  border-color: color-mix(in srgb, var(--danger-deep) 35%, transparent);
  background: var(--danger-soft);
}
.progress-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
}
.progress-title { font-weight: 700; font-size: 13px; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.progress-counts { display: flex; gap: 6px; flex-wrap: wrap; }
.progress-bar {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border-strong) 60%, transparent);
  overflow: hidden;
}
.progress-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--primary);
  border-radius: 999px;
  transition: width 240ms ease;
}
.progress.done .progress-bar-fill { background: var(--success); }
.progress.err  .progress-bar-fill { background: var(--danger); }
.progress-bar.indeterminate .progress-bar-fill {
  width: 35% !important;
  animation: indet 1.4s ease-in-out infinite;
}
@keyframes indet {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}
.progress-meta {
  display: flex; gap: 10px; font-size: 12px; color: var(--text-muted);
  flex-wrap: wrap; align-items: center;
}
.progress-throttle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px;
  color: var(--warning-deep); background: var(--warning-soft);
  border: 1px solid color-mix(in srgb, var(--warning-deep) 35%, transparent);
}

/* sidebar account-row progress */
.sb-row .sb-progress {
  margin-top: 4px;
  height: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border-strong) 60%, transparent);
  overflow: hidden;
  position: relative;
}
.sb-row .sb-progress-fill {
  position: absolute; inset: 0 auto 0 0;
  background: var(--primary);
  border-radius: 999px;
  transition: width 240ms ease;
}
.sb-row .sb-progress.indeterminate .sb-progress-fill {
  width: 35% !important;
  animation: indet 1.4s ease-in-out infinite;
}

/* footer */
.footer {
  border-top: 1px solid var(--hairline);
  padding: 16px 0 0;
  margin-top: 40px;
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.44px;
  text-transform: uppercase;
  font-weight: 700;
  flex-wrap: wrap;
  gap: 8px;
}

/* list-filter grid (legacy hook kept) */
.list-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 12px;
  max-height: 240px;
  overflow-y: auto;
  padding: 6px 4px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--canvas);
}
.list-filter-item {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; cursor: pointer;
  padding: 4px 6px;
}
.list-filter-item input[type="checkbox"] { accent-color: var(--primary); }

/* legacy `.hint` used by builders */
.hint { color: var(--text-muted); font-size: 13px; }
.hint.err { color: var(--danger-deep); }

/* mapping builder sub-layouts */
.builder { display: grid; gap: 10px; }
.builder-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.builder-head-end { justify-content: flex-end; }
.raw-toggle { font-size: 12px; color: var(--text-muted); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.builder-raw {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px;
  min-height: 200px;
  width: 100%;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 10px 12px;
  color: var(--ink);
  resize: vertical;
}
.filter-raw { min-height: 80px; }

.builder-section { display: grid; gap: 8px; padding-top: 6px; }
.builder-section + .builder-section {
  border-top: 1px dashed var(--hairline);
  padding-top: 14px;
  margin-top: 6px;
}
.builder-section-title {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--text-muted);
}
.builder-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px;
  align-items: start;
}
.builder-row-sub { grid-template-columns: 140px 1fr; }
.builder-row-label {
  display: grid; gap: 2px;
  padding-top: 8px;
}
.builder-slots { display: grid; gap: 6px; }
.builder-slot {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 6px;
  align-items: center;
}
.builder-slot select, .builder-slot input { font-size: 13px; }
.builder-slot-url {
  grid-template-columns: 110px 1fr 160px auto;
}
@media (max-width: 700px) {
  .builder-slot-url {
    grid-template-columns: 90px 1fr;
  }
  .builder-slot-url .slot-label,
  .builder-slot-url .icon-btn {
    grid-column: 2 / span 1;
  }
}
.btn-add {
  justify-self: start;
  font-size: 13px;
  padding: 6px 10px;
}
.btn-remove {
  font-size: 13px;
  padding: 4px 8px;
  color: var(--danger-deep);
  background: transparent;
  border: 0;
}
.builder-address {
  display: grid; gap: 8px;
  padding: 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--canvas-soft);
}
.builder-address-head {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
}
.builder-address-head .inline {
  display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px;
}
.builder-address-head .addr-type {
  width: 120px; padding: 6px 10px; font-size: 12.5px;
  background: var(--canvas); border: 1px solid var(--hairline); border-radius: var(--r-md);
  color: var(--ink);
}
@media (max-width: 700px) {
  .builder-row, .builder-row-sub { grid-template-columns: 1fr; }
  .builder-slot { grid-template-columns: 90px 1fr auto; }
}

/* ===========================================================
 * Login page
 * =========================================================== */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at top, rgba(89, 84, 249, 0.12), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(154, 134, 245, 0.10), transparent 60%),
    var(--canvas);
  padding: 24px;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-2);
  display: grid;
  gap: 18px;
}
.auth-card .brand {
  display: flex; align-items: center; gap: 12px; margin-bottom: 4px;
}
.auth-card .brand-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 16px; font-weight: 700; margin: 0;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.auth-card .brand-sub { font-size: 12.5px; color: var(--text-muted); margin: 2px 0 0; }
.auth-form { display: grid; gap: 14px; }
.auth-form .field { display: grid; gap: 6px; margin: 0; }
.auth-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin: 4px 0 0;
  line-height: 1.5;
  text-align: center;
}
.btn-block { width: 100%; justify-content: center; padding: 12px 14px; }
.btn-oidc { text-decoration: none; display: inline-flex; align-items: center; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-tertiary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border, color-mix(in srgb, currentColor 18%, transparent));
}
.alert-err { color: var(--danger-deep); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger-deep) 35%, transparent); }

/* ===========================================================
 * Mobile polish
 * =========================================================== */
@media (max-width: 900px) {
  /* Sidebar becomes a fixed off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: min(320px, 86vw);
    max-height: 100vh;
    z-index: 50;
    padding: 56px 14px 20px;
    transform: translateX(-100%);
    transition: transform 220ms ease;
    box-shadow: var(--shadow-2);
    border-right: 1px solid var(--hairline);
    display: flex;
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop:not([hidden]) { display: block; }
  .sidebar-close-btn { display: inline-flex; }

  /* Lock background scroll while drawer is open */
  body.has-drawer-open { overflow: hidden; }

  .topnav {
    padding: 10px 14px;
    gap: 10px;
  }
  .topnav-right { gap: 6px; }
  .topnav-right .kbd,
  .sb-search .kbd-hint { display: none; }
  .brand-wm { font-size: 13px; }
  .brand-wm .sub { display: none; }

  /* Bigger tap targets in theme toggle */
  .theme-toggle { padding: 2px; }
  .theme-toggle button { width: 34px; height: 30px; }

  /* Sign out button → tighter on mobile */
  .btn-util { padding: 8px 12px; min-height: 36px; }

  /* Page heading scales down */
  .page-head h1 { font-size: 24px; }
  .t-display-lg { font-size: 24px; }

  /* Modal hugs the viewport */
  .modal-backdrop { padding: 12px; }
  .modal { padding: 18px; }

  /* Bigger icon-button tap targets (mapping/builder remove buttons) */
  .icon-btn { width: 36px; height: 36px; }
}

@media (max-width: 560px) {
  .topnav { padding: 10px 12px; gap: 8px; }
  /* Hide the brand wordmark at very narrow widths — keep the TS mark */
  .topnav .brand-wm { display: none; }
  .theme-toggle button { width: 30px; height: 28px; }
  .content { padding: 16px 14px 56px; }
  .page-head { gap: 10px; margin-bottom: 18px; }
  .page-head h1 { font-size: 22px; }
  .page-head .subtitle { font-size: 13px; }

  /* Toasts span the bottom of the viewport, not a fixed corner */
  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
  .toast { min-width: 0; max-width: none; }

  /* Footer stacks cleanly */
  .footer { font-size: 10px; }

  /* Section/diagram cards tighter */
  .section-card { padding: 18px 16px; }
  .diagram { padding: 16px; }
  .kpi { padding: 16px; }
  .kpi .num { font-size: 26px; }
}

/* Prevent iOS Safari auto-zoom on input focus (needs ≥ 16px font-size) */
@media (max-width: 700px) {
  .input,
  .select,
  .textarea,
  .sb-search input,
  .auth-form input,
  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="number"],
  input[type="url"],
  input[type="search"] {
    font-size: 16px;
  }
}

/* Touch device polish — kill the grey tap flash */
@media (hover: none) {
  button,
  a,
  .sb-row,
  .chip,
  .tab { -webkit-tap-highlight-color: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* Findymail usage breakdown */
.usage-card {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 12px 14px;
  background: var(--canvas-soft);
}
.usage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.usage-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 12px;
}
.usage-stat { min-width: 80px; }
.usage-num { font-size: 20px; font-weight: 650; color: var(--ink); line-height: 1.1; }
.usage-lbl { font-size: 12px; color: var(--text-muted); }
.usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.usage-subhead {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}
.usage-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.usage-table th, .usage-table td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--border-strong) 50%, transparent);
}
.usage-table th { color: var(--text-muted); font-weight: 600; }
.usage-table td.num, .usage-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.usage-table tbody tr:last-child td { border-bottom: none; }

/* Deduplicate / merge */
.btn-sm { padding: 5px 10px; font-size: 12px; }
.link { color: var(--primary); text-decoration: none; }
.link:hover { text-decoration: underline; }
.dedup-member:hover { background: var(--canvas-soft); }
