:root {
      color-scheme: dark;
      /* Calm Linear-grade surface hierarchy */
      --bg-app: #0f1116;
      --bg-rail: #12151c;
      --bg-canvas: #171a22;
      --bg-stage: #12151d;
      --stage-dot: rgba(255, 255, 255, 0.055);
      --bg-control: #1e222d;
      --bg-control-hover: #262b38;
      --bg-elevated: #202532;
      --cad-paper: #f3f5f9;

      /* Text hierarchy (zero halation) */
      --fg: #eceef4;
      --fg-secondary: #c2c7d4;
      --muted: #858c9e;

      /* Hairline borders */
      --line: rgba(255, 255, 255, 0.075);
      --line-strong: rgba(255, 255, 255, 0.14);
      --line-focus: #4f8ff7;

      /* ONE unified active selection language across the entire app */
      --active-bg: rgba(79, 143, 247, 0.16);
      --active-bg-hover: rgba(79, 143, 247, 0.24);
      --active-fg: #e8f1ff;
      --active-border: rgba(79, 143, 247, 0.48);

      /* Semantic accents */
      --brand: #d86a3b;
      --green: #2d9d5b;
      --green-hover: #34b067;
      --green-bg: rgba(45, 157, 91, 0.14);
      --green-fg: #7ee2a8;
      --amber: #df8b2f;
      --amber-bg: rgba(223, 139, 47, 0.14);
      --amber-fg: #f7c27e;
      --red: #dc584a;
      --red-bg: rgba(220, 88, 74, 0.14);
      --red-fg: #fca5a5;
      --blue: #5294ff;
      --blue-bg: rgba(82, 148, 255, 0.13);
      --ai-bg: rgba(129, 140, 248, 0.13);
      --ai-border: rgba(129, 140, 248, 0.42);
      --ai-fg: #c7d2fe;

      /* Distinct 4-step typographic scale */
      --fs-h1: 20.5px;
      --fs-sec: 14.5px;
      --fs-base: 13.5px;
      --fs-sm: 12px;

      --radius: 8px;
      --radius-sm: 6px;
      --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.48), 0 2px 6px rgba(0, 0, 0, 0.28);
      --shadow-modal: 0 24px 64px rgba(0, 0, 0, 0.6);
      --left-w: 292px;
      --right-w: 324px;
      --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    }

    :root[data-theme="light"] {
      color-scheme: light;
      --bg-app: #ebedf2;
      --bg-rail: #f3f5f8;
      --bg-canvas: #ffffff;
      --bg-stage: #eef1f6;
      --stage-dot: rgba(15, 23, 42, 0.075);
      --bg-control: #f4f6fa;
      --bg-control-hover: #e9ecf3;
      --bg-elevated: #ffffff;
      --cad-paper: #ffffff;

      --fg: #14171f;
      --fg-secondary: #373c4a;
      --muted: #666d7e;

      --line: rgba(15, 23, 42, 0.085);
      --line-strong: rgba(15, 23, 42, 0.17);
      --line-focus: #2563eb;

      --active-bg: rgba(37, 99, 235, 0.10);
      --active-bg-hover: rgba(37, 99, 235, 0.16);
      --active-fg: #1d4ed8;
      --active-border: rgba(37, 99, 235, 0.38);

      --brand: #c65323;
      --green: #1c7d43;
      --green-hover: #176938;
      --green-bg: rgba(28, 125, 67, 0.10);
      --green-fg: #166534;
      --amber: #b45d09;
      --amber-bg: rgba(180, 93, 9, 0.10);
      --amber-fg: #9a3412;
      --red: #c2392b;
      --red-bg: rgba(194, 57, 43, 0.10);
      --red-fg: #991b1b;
      --blue: #2563eb;
      --blue-bg: rgba(37, 99, 235, 0.10);
      --ai-bg: rgba(79, 70, 229, 0.08);
      --ai-border: rgba(79, 70, 229, 0.35);
      --ai-fg: #4338ca;

      --shadow-pop: 0 10px 28px rgba(15, 23, 42, 0.13), 0 2px 6px rgba(15, 23, 42, 0.06);
      --shadow-modal: 0 24px 60px rgba(15, 23, 42, 0.22);
    }

    * { box-sizing: border-box; }
    html, body {
      margin: 0;
      padding: 0;
      height: 100%;
      overflow: hidden;
      background: var(--bg-app);
      color: var(--fg);
      font-family: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
      font-size: var(--fs-base);
      line-height: 1.45;
      -webkit-font-smoothing: antialiased;
      font-variant-numeric: tabular-nums;
    }
    button, input, select, textarea { font: inherit; color: inherit; }
    a { color: var(--blue); text-decoration: none; }
    a:hover { text-decoration: underline; }
    button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, [tabindex]:focus-visible {
      outline: 2px solid var(--line-focus);
      outline-offset: 1px;
    }

    /* Fallback native select safety: custom chevron 10px from right border, NEVER flush! */
    select {
      appearance: none;
      -webkit-appearance: none;
      padding-right: 30px !important;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23858c9e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 10px center;
    }

    .svg-ico {
      display: inline-block;
      vertical-align: -0.16em;
      flex-shrink: 0;
    }

    /* Top App Shell Bar (42px) */
    .app-shell {
      display: flex;
      flex-direction: column;
      height: 100vh;
      width: 100vw;
    }
    .topbar {
      height: 42px;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 14px;
      background: var(--bg-rail);
      border-bottom: 1px solid var(--line);
      gap: 10px;
      z-index: 30;
    }
    .brand {
      display: flex;
      align-items: center;
      gap: 8px;
      font-weight: 600;
      font-size: var(--fs-base);
      white-space: nowrap;
    }
    .brand-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: var(--brand);
    }
    .ver-pill {
      font-size: var(--fs-sm);
      font-weight: 500;
      color: var(--muted);
      padding: 1px 6px;
      border-radius: 4px;
      border: 1px solid var(--line);
    }

    .role-nav {
      display: flex;
      align-items: center;
      gap: 3px;
      background: var(--bg-control);
      padding: 2px;
      border-radius: 7px;
      border: 1px solid var(--line);
    }
    .nav-tab {
      border: 1px solid transparent;
      background: transparent;
      color: var(--muted);
      padding: 3px 10px;
      border-radius: 5px;
      font-size: var(--fs-sm);
      font-weight: 500;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      white-space: nowrap;
      transition: background-color 140ms var(--ease-out), color 140ms var(--ease-out), border-color 140ms var(--ease-out);
    }
    .nav-tab:hover { color: var(--fg); }
    .nav-tab.active {
      background: var(--active-bg);
      color: var(--active-fg);
      border-color: var(--active-border);
      font-weight: 600;
    }
    .nav-tab.active:hover { background: var(--active-bg-hover); color: var(--active-fg); }

    /* Unified Button System (Zero .btn.active:hover specificity bug!) */
    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      padding: 5px 11px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--line-strong);
      background: var(--bg-control);
      color: var(--fg);
      font-size: var(--fs-base);
      font-weight: 500;
      cursor: pointer;
      white-space: nowrap;
      transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out), color 140ms var(--ease-out);
    }
    .btn:hover:not(:disabled) {
      background: var(--bg-control-hover);
      border-color: var(--line-strong);
    }
    .btn:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
    .btn.active,
    .btn.active:hover:not(:disabled) {
      background: var(--active-bg);
      color: var(--active-fg);
      border-color: var(--active-border);
      font-weight: 600;
    }
    .btn.active:hover:not(:disabled) {
      background: var(--active-bg-hover);
    }
    .btn-sm {
      padding: 4px 8px;
      font-size: var(--fs-sm);
      border-radius: 5px;
    }
    .btn-ghost {
      background: transparent;
      border-color: transparent;
      color: var(--fg-secondary);
    }
    .btn-ghost:hover:not(:disabled) {
      background: var(--bg-control);
      border-color: var(--line);
      color: var(--fg);
    }
    /* ONE Primary CTA style on screen */
    .btn-primary,
    .btn-primary:hover:not(:disabled) {
      background: var(--green);
      color: #ffffff;
      border-color: var(--green);
      font-weight: 600;
    }
    .btn-primary:hover:not(:disabled) {
      background: var(--green-hover);
      border-color: var(--green-hover);
    }
    .btn-danger {
      background: var(--red-bg);
      color: var(--red-fg);
      border-color: color-mix(in srgb, var(--red) 40%, transparent);
    }
    .btn-danger:hover:not(:disabled) {
      background: color-mix(in srgb, var(--red) 22%, transparent);
    }

    /* Simulation Popover (Zero vertical shift of workspace!) */
    .sim-popover {
      position: fixed;
      top: 46px;
      right: 14px;
      z-index: 95;
      width: 320px;
      padding: 10px 12px;
      border-radius: var(--radius);
      background: var(--bg-elevated);
      border: 1px solid var(--line-strong);
      box-shadow: var(--shadow-pop);
      display: flex;
      flex-direction: column;
      gap: 6px;
      font-size: var(--fs-sm);
      animation: popIn 140ms var(--ease-out);
    }

    /* 3-Pane Workstation Grid */
    .workspace {
      flex: 1;
      min-height: 0;
      display: grid;
      grid-template-columns: var(--left-w) 5px minmax(0, 1fr) 5px var(--right-w);
    }
    .workspace.right-collapsed {
      grid-template-columns: var(--left-w) 5px minmax(0, 1fr);
    }
    .pane-splitter {
      cursor: col-resize;
      position: relative;
      z-index: 15;
      user-select: none;
      background: transparent;
    }
    .pane-splitter::after {
      content: "";
      position: absolute;
      top: 0;
      bottom: 0;
      left: 2px;
      width: 1px;
      background: var(--line);
      transition: background-color 140ms var(--ease-out), width 140ms var(--ease-out);
    }
    .pane-splitter:hover::after, .pane-splitter.dragging::after {
      width: 3px;
      left: 1px;
      background: var(--line-focus);
    }

    /* 1. LEFT QUEUE RAIL (Linear-style calm rows, ZERO card-in-card boxes!) */
    .rail-left {
      background: var(--bg-rail);
      display: flex;
      flex-direction: column;
      min-height: 0;
      min-width: 0;
    }
    .rail-hdr {
      padding: 10px 12px 8px;
      display: flex;
      flex-direction: column;
      gap: 8px;
      border-bottom: 1px solid var(--line);
    }
    .rail-hdr-top {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }
    .search-box {
      position: relative;
      display: flex;
      align-items: center;
    }
    .search-box input {
      width: 100%;
      padding: 5px 26px 5px 28px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--line);
      background: var(--bg-control);
      font-size: var(--fs-sm);
      color: var(--fg);
    }
    .search-box input::placeholder { color: var(--muted); }
    .search-ico {
      position: absolute;
      left: 8px;
      color: var(--muted);
      pointer-events: none;
    }
    .search-clear {
      position: absolute;
      right: 5px;
      border: none;
      background: transparent;
      color: var(--muted);
      cursor: pointer;
      padding: 2px 4px;
      font-size: 12px;
    }

    .queue-scroll {
      flex: 1;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
    }
    .q-row {
      width: 100%;
      text-align: left;
      border: none;
      border-bottom: 1px solid var(--line);
      background: transparent;
      padding: 10px 12px;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      gap: 4px;
      position: relative;
      transition: background-color 120ms var(--ease-out);
    }
    .q-row:hover {
      background: color-mix(in srgb, var(--fg) 4%, transparent);
    }
    .q-row.selected {
      background: var(--active-bg);
    }
    .q-row.selected::before {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      width: 3px;
      background: var(--line-focus);
    }
    .q-row-top {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
      min-width: 0;
    }
    .q-row-title {
      font-weight: 600;
      font-size: var(--fs-base);
      color: var(--fg);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      display: flex;
      align-items: center;
      gap: 6px;
      min-width: 0;
    }
    .q-row-verb {
      font-size: var(--fs-sm);
      color: var(--fg-secondary);
      line-height: 1.35;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
    .q-row-meta {
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: var(--fs-sm);
      color: var(--muted);
      white-space: nowrap;
      overflow: hidden;
    }

    /* Calm Semantic Badges */
    .badge {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 1px 6px;
      border-radius: 4px;
      font-size: var(--fs-sm);
      font-weight: 500;
      white-space: nowrap;
      flex-shrink: 0;
    }
    .badge-urgent {
      background: var(--red-bg);
      color: var(--red-fg);
      border: 1px solid color-mix(in srgb, var(--red) 32%, transparent);
    }
    .badge-amber {
      background: var(--amber-bg);
      color: var(--amber-fg);
      border: 1px solid color-mix(in srgb, var(--amber) 32%, transparent);
    }
    .badge-green {
      background: var(--green-bg);
      color: var(--green-fg);
      border: 1px solid color-mix(in srgb, var(--green) 32%, transparent);
    }
    .badge-neutral {
      background: var(--bg-control);
      color: var(--fg-secondary);
      border: 1px solid var(--line);
    }
    .badge-ai {
      background: var(--ai-bg);
      color: var(--ai-fg);
      border: 1px solid var(--ai-border);
    }

    /* 2. CENTER DEAL SHEET (Single clean sheet, generous header air, zero nested boxes!) */
    .center-pane {
      background: var(--bg-canvas);
      display: flex;
      flex-direction: column;
      min-width: 0;
      min-height: 0;
      position: relative;
    }
    .center-scroll {
      flex: 1;
      overflow-y: auto;
      min-height: 0;
      display: flex;
      flex-direction: column;
    }

    /* Airy Deal Header (Pavel's 20.5px JK anchor + vertical breathing room!) */
    .deal-hdr {
      padding: 18px 22px 14px;
      border-bottom: 1px solid var(--line);
      display: flex;
      flex-direction: column;
      gap: 9px;
      flex-shrink: 0;
    }
    .deal-hdr-row1 {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 14px;
    }
    .deal-title-group {
      display: flex;
      align-items: baseline;
      flex-wrap: wrap;
      gap: 6px 10px;
      min-width: 0;
    }
    .deal-h1 {
      margin: 0;
      font-size: var(--fs-h1);
      font-weight: 600;
      letter-spacing: -0.02em;
      line-height: 1.25;
      color: var(--fg);
    }
    .deal-addr {
      font-size: 15px;
      font-weight: 400;
      color: var(--fg-secondary);
      line-height: 1.3;
    }
    .deal-hdr-links {
      display: flex;
      align-items: center;
      gap: 6px;
      flex-shrink: 0;
    }
    .deal-hdr-row2 {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      flex-wrap: wrap;
    }
    .client-meta {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
      font-size: var(--fs-base);
      color: var(--fg-secondary);
    }
    .context-chips {
      display: flex;
      align-items: center;
      gap: 6px;
      flex-wrap: wrap;
    }
    .ctx-chip {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      padding: 4px 9px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--line-strong);
      background: var(--bg-control);
      color: var(--fg);
      font-size: var(--fs-sm);
      font-weight: 500;
      cursor: pointer;
      text-decoration: none;
      transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out);
    }
    .ctx-chip:hover {
      background: var(--bg-control-hover);
      text-decoration: none;
    }
    .ctx-chip.active {
      background: var(--active-bg);
      color: var(--active-fg);
      border-color: var(--active-border);
      font-weight: 600;
    }

    /* Task-First Banner (ONLY on approve_daim / defect / timeout so invoice is visible on Screen 1!) */
    .task-leader-card {
      margin: 12px 22px 0;
      padding: 11px 14px;
      border-radius: var(--radius);
      background: var(--amber-bg);
      border: 1px solid color-mix(in srgb, var(--amber) 36%, transparent);
      display: flex;
      flex-direction: column;
      gap: 6px;
    }
    .task-leader-card.danger {
      background: var(--red-bg);
      border-color: color-mix(in srgb, var(--red) 40%, transparent);
    }

    /* Linear-style Underline Room Tabs (Zero boxy pills!) */
    .rooms-tabbar {
      padding: 0 22px;
      border-bottom: 1px solid var(--line);
      display: flex;
      align-items: center;
      gap: 16px;
      overflow-x: auto;
      flex-shrink: 0;
      min-height: 40px;
    }
    .room-tab {
      position: relative;
      border: none;
      background: transparent;
      padding: 9px 2px;
      font-size: var(--fs-base);
      font-weight: 500;
      color: var(--muted);
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      white-space: nowrap;
      transition: color 140ms var(--ease-out);
    }
    .room-tab:hover { color: var(--fg); }
    .room-tab.active {
      color: var(--fg);
      font-weight: 600;
    }
    .room-tab.active::after {
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      bottom: -1px;
      height: 2px;
      border-radius: 2px;
      background: var(--line-focus);
    }
    .room-dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--green);
    }
    .room-dot.muted { background: var(--muted); opacity: 0.5; }

    /* Main 2-Column Room Workbench */
    .workbench {
      flex: 1;
      padding: 14px 22px 18px;
      display: grid;
      grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
      gap: 20px;
      align-items: stretch;
    }
    @media (max-width: 1060px) {
      .workbench { grid-template-columns: 1fr; }
    }

    /* CleanShot X / Excalidraw Stage Box (Theme-aware dot-grid, ZERO #0c0e13 black hole in light theme!) */
    .stage-box {
      border: 1px solid var(--line-strong);
      border-radius: var(--radius);
      background: var(--bg-stage);
      display: flex;
      flex-direction: column;
      min-height: 360px;
      overflow: visible;
      position: relative;
    }
    .stage-toolbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 4px;
      padding: 6px 8px;
      background: var(--bg-control);
      border-bottom: 1px solid var(--line);
      border-radius: var(--radius) var(--radius) 0 0;
      flex-wrap: wrap;
    }
    .tool-group {
      display: flex;
      align-items: center;
      gap: 3px;
      flex-wrap: wrap;
    }
    .tool-pill {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 4px 6.5px;
      border-radius: 5px;
      border: 1px solid transparent;
      background: transparent;
      color: var(--fg-secondary);
      font-size: var(--fs-sm);
      font-weight: 500;
      cursor: pointer;
      white-space: nowrap;
      transition: background-color 120ms var(--ease-out), color 120ms var(--ease-out);
    }
    .tool-pill:hover {
      background: var(--bg-control-hover);
      color: var(--fg);
    }
    .tool-pill.active {
      background: var(--active-bg);
      color: var(--active-fg);
      border-color: var(--active-border);
      font-weight: 600;
    }
    .stage-viewport {
      flex: 1;
      min-height: 290px;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 10px;
      background-color: var(--bg-stage);
      background-image: radial-gradient(var(--stage-dot) 1px, transparent 1px);
      background-size: 14px 14px;
      user-select: none;
      overflow: hidden;
    }
    .photo-fit-wrap {
      position: relative;
      display: inline-block;
      line-height: 0;
      max-width: 100%;
      max-height: clamp(290px, calc(100vh - 300px), 440px);
    }
    .photo-fit-wrap img {
      max-width: 100%;
      max-height: clamp(290px, calc(100vh - 300px), 440px);
      width: auto;
      height: auto;
      display: block;
      border-radius: 5px;
      box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
      user-select: none;
      -webkit-user-drag: none;
    }
    .photo-svg-layer {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      overflow: visible;
      touch-action: none;
    }
    .stage-footer {
      padding: 6px 8px;
      background: var(--bg-control);
      border-top: 1px solid var(--line);
      border-radius: 0 0 var(--radius) var(--radius);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
    }
    .thumb-btn {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      padding: 2px 7px 2px 3px;
      border-radius: 5px;
      border: 1px solid var(--line);
      background: var(--bg-canvas);
      color: var(--fg-secondary);
      font-size: var(--fs-sm);
      cursor: pointer;
    }
    .thumb-btn img {
      width: 22px;
      height: 22px;
      object-fit: cover;
      border-radius: 3px;
    }
    .thumb-btn.active {
      background: var(--active-bg);
      color: var(--active-fg);
      border-color: var(--active-border);
      font-weight: 600;
    }

    /* Miro-style Anchored Pin Popover on Canvas! */
    .miro-pin-popover {
      position: absolute;
      z-index: 25;
      width: 248px;
      padding: 9px 10px;
      border-radius: 8px;
      background: var(--bg-elevated);
      border: 1px solid var(--line-strong);
      box-shadow: var(--shadow-pop);
      display: flex;
      flex-direction: column;
      gap: 7px;
      animation: popIn 140ms var(--ease-out);
    }
    @keyframes popIn {
      from { opacity: 0; transform: translateY(4px) scale(0.98); }
      to   { opacity: 1; transform: translateY(0) scale(1); }
    }

    /* Right Form Column inside Workbench (Clean property list, ZERO card-in-card!) */
    .prop-panel {
      display: flex;
      flex-direction: column;
      gap: 10px;
      min-width: 0;
    }
    .prop-hdr {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding-bottom: 8px;
      border-bottom: 1px solid var(--line);
      flex-wrap: wrap;
    }
    .seg-group {
      display: inline-flex;
      align-items: center;
      padding: 2px;
      border-radius: 6px;
      background: var(--bg-control);
      border: 1px solid var(--line);
      gap: 2px;
    }
    .seg-btn {
      border: 1px solid transparent;
      background: transparent;
      color: var(--muted);
      font-size: var(--fs-sm);
      font-weight: 500;
      padding: 3px 8px;
      border-radius: 4px;
      cursor: pointer;
      white-space: nowrap;
      transition: background-color 120ms var(--ease-out), color 120ms var(--ease-out);
    }
    .seg-btn:hover { color: var(--fg); }
    .seg-btn.active {
      background: var(--active-bg);
      color: var(--active-fg);
      border-color: var(--active-border);
      font-weight: 600;
    }

    .field-label {
      display: flex;
      flex-direction: column;
      gap: 4px;
      font-size: var(--fs-sm);
      color: var(--muted);
      font-weight: 500;
      min-width: 0;
    }
    .label-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
    }
    .input-wrap {
      position: relative;
      display: flex;
      align-items: center;
    }
    .field-input {
      width: 100%;
      min-width: 0;
      padding: 6px 28px 6px 10px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--line);
      background: var(--bg-control);
      color: var(--fg);
      font-size: var(--fs-base);
      transition: border-color 120ms var(--ease-out), background-color 120ms var(--ease-out);
    }
    .field-input:hover { border-color: var(--line-strong); }
    .field-input:focus { background: var(--bg-canvas); border-color: var(--line-focus); }
    .field-input.ai-filled {
      border-color: var(--ai-border);
      background: var(--ai-bg);
    }
    .field-input.invalid {
      border-color: var(--red);
      background: var(--red-bg);
    }
    .inline-mic-btn {
      position: absolute;
      right: 5px;
      border: none;
      background: transparent;
      color: var(--muted);
      padding: 3px;
      border-radius: 4px;
      cursor: pointer;
      opacity: 0;
      transition: opacity 120ms var(--ease-out), color 120ms var(--ease-out);
    }
    .input-wrap:hover .inline-mic-btn,
    .input-wrap:focus-within .inline-mic-btn,
    .inline-mic-btn:focus-visible {
      opacity: 1;
    }
    .inline-mic-btn:hover { color: var(--blue); }

    /* Non-blocking Inline Live Voice Bar (Keeps photo visible while dictating!) */
    .live-voice-bar {
      padding: 9px 11px;
      border-radius: var(--radius);
      background: var(--ai-bg);
      border: 1px solid var(--ai-border);
      display: flex;
      flex-direction: column;
      gap: 6px;
      animation: popIn 150ms var(--ease-out);
    }
    .rec-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: var(--red);
      display: inline-block;
      animation: pulseDot 1.1s infinite ease-in-out;
    }
    @keyframes pulseDot {
      0%, 100% { opacity: 1; transform: scale(1); }
      50% { opacity: 0.4; transform: scale(0.85); }
    }

    /* Custom Styled Popover Select (.cselect — replaces giant OS native select!) */
    .cselect {
      position: relative;
      width: 100%;
      min-width: 0;
    }
    .cselect-btn {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 6px 10px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--line);
      background: var(--bg-control);
      color: var(--fg);
      font-size: var(--fs-base);
      text-align: left;
      cursor: pointer;
      transition: border-color 120ms var(--ease-out), background-color 120ms var(--ease-out);
    }
    .cselect-btn:hover { border-color: var(--line-strong); }
    .cselect-btn[aria-expanded="true"] {
      border-color: var(--line-focus);
      background: var(--bg-canvas);
    }
    .cselect-label {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      min-width: 0;
    }
    .cselect-chev {
      color: var(--muted);
      flex-shrink: 0;
      transition: transform 150ms var(--ease-out);
    }
    .cselect-btn[aria-expanded="true"] .cselect-chev {
      transform: rotate(180deg);
      color: var(--fg);
    }
    .cselect-menu {
      position: absolute;
      top: calc(100% + 4px);
      left: 0;
      right: 0;
      min-width: 210px;
      max-height: 270px;
      overflow-y: auto;
      padding: 4px;
      border-radius: var(--radius);
      background: var(--bg-elevated);
      border: 1px solid var(--line-strong);
      box-shadow: var(--shadow-pop);
      z-index: 90;
      transform-origin: top center;
      animation: popIn 150ms var(--ease-out);
    }
    .cselect-opt {
      width: 100%;
      border: none;
      background: transparent;
      color: var(--fg);
      font-size: var(--fs-base);
      padding: 6px 8px;
      border-radius: 5px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      text-align: left;
    }
    .cselect-opt:hover, .cselect-opt.focused {
      background: var(--bg-control-hover);
    }
    .cselect-opt.selected {
      background: var(--active-bg);
      color: var(--active-fg);
      font-weight: 600;
    }

    /* Subtle Hover/Focus Tooltip (?) */
    .help-tip {
      position: relative;
      display: inline-flex;
      align-items: center;
      color: var(--muted);
      cursor: help;
      border: none;
      background: transparent;
      padding: 0 2px;
      font-size: 11.5px;
    }
    .help-tip:hover, .help-tip:focus-visible { color: var(--fg); }
    .help-tip::after {
      content: attr(data-tip);
      position: absolute;
      bottom: calc(100% + 6px);
      left: 50%;
      transform: translateX(-50%);
      width: max-content;
      max-width: 250px;
      padding: 6px 9px;
      border-radius: 6px;
      background: var(--bg-elevated);
      color: var(--fg);
      border: 1px solid var(--line-strong);
      box-shadow: var(--shadow-pop);
      font-size: var(--fs-sm);
      font-weight: 400;
      line-height: 1.35;
      white-space: normal;
      pointer-events: none;
      opacity: 0;
      transition: opacity 110ms var(--ease-out);
      z-index: 95;
    }
    .help-tip:hover::after, .help-tip:focus-visible::after {
      opacity: 1;
    }

    /* Sticky Bottom Action Bar (48px, 1 Primary CTA on right, calm secondary on left) */
    .sticky-action-bar {
      height: 50px;
      flex-shrink: 0;
      padding: 0 22px;
      background: var(--bg-canvas);
      border-top: 1px solid var(--line);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      z-index: 20;
    }

    /* 3. RIGHT CONTEXT INSPECTOR ([Досье (3)] · [Визит] · [Фон] — ZERO shift of center canvas!) */
    .rail-right {
      background: var(--bg-rail);
      display: flex;
      flex-direction: column;
      min-height: 0;
      min-width: 0;
    }
    .insp-tabs {
      padding: 8px 10px;
      border-bottom: 1px solid var(--line);
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 3px;
      background: var(--bg-rail);
    }
    .insp-scroll {
      flex: 1;
      overflow-y: auto;
      padding: 12px;
      display: flex;
      flex-direction: column;
      gap: 12px;
    }
    .jk-photo-card {
      width: 100%;
      text-align: left;
      padding: 0;
      border-radius: 7px;
      overflow: hidden;
      border: 1px solid var(--line);
      background: var(--bg-control);
      cursor: pointer;
      transition: border-color 130ms var(--ease-out);
    }
    .jk-photo-card:hover { border-color: var(--line-focus); }
    .jk-photo-card img {
      width: 100%;
      height: 118px;
      object-fit: cover;
      display: block;
    }

    /* Pavel's Compact Full-Width Background Feed Rows (Zero 70px empty left gutter!) */
    .feed-row {
      width: 100%;
      text-align: left;
      border: none;
      border-bottom: 1px solid var(--line);
      background: transparent;
      padding: 9px 2px;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      gap: 3px;
    }
    .feed-row:hover { opacity: 0.92; }
    .feed-row-top {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      font-size: var(--fs-sm);
      color: var(--muted);
    }
    .feed-row-id {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      font-weight: 600;
      color: var(--fg-secondary);
    }
    .feed-row-title {
      font-size: var(--fs-base);
      font-weight: 600;
      color: var(--fg);
      line-height: 1.35;
    }
    .feed-row-desc {
      font-size: var(--fs-sm);
      color: var(--muted);
      line-height: 1.38;
    }

    /* Grid-4 & Grid-2 helpers */
    .grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
    .grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .grid-2 > .btn { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

    /* Modal Backdrop & Dialogs */
    .modal-backdrop {
      position: fixed;
      inset: 0;
      z-index: 120;
      background: rgba(9, 11, 16, 0.66);
      backdrop-filter: blur(3px);
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 20px;
      animation: fadeBg 140ms var(--ease-out);
    }
    @keyframes fadeBg { from { opacity: 0; } to { opacity: 1; } }
    .modal-card {
      width: 100%;
      max-width: 540px;
      border-radius: 10px;
      background: var(--bg-elevated);
      border: 1px solid var(--line-strong);
      box-shadow: var(--shadow-modal);
      padding: 18px 20px;
      animation: popIn 150ms var(--ease-out);
    }
    .modal-card.xl {
      max-width: 1120px;
      height: min(88vh, 840px);
      display: flex;
      flex-direction: column;
      padding: 14px 16px;
    }

    /* Toast with aria-live (Anchored bottom-left away from ⤢ Крупно and primary CTA!) */
    .toast-bar {
      position: fixed;
      bottom: 14px;
      left: 14px;
      max-width: 440px;
      z-index: 130;
      padding: 8px 14px;
      border-radius: 8px;
      background: var(--bg-elevated);
      color: var(--fg);
      border: 1px solid var(--line-strong);
      box-shadow: var(--shadow-pop);
      display: flex;
      align-items: center;
      gap: 10px;
      font-size: var(--fs-base);
      animation: popIn 150ms var(--ease-out);
    }

    /* Mobile / Role Preview Frames (Master & Yuri Ledov) */
    .other-role-scroll {
      flex: 1;
      overflow-y: auto;
      padding: 22px;
      background: var(--bg-app);
    }
    .mobile-wrap {
      max-width: 920px;
      margin: 0 auto;
      display: grid;
      grid-template-columns: 390px minmax(0, 1fr);
      gap: 24px;
      align-items: start;
    }
    .phone-frame {
      background: #161922;
      color: #eef0f6;
      border: 1px solid #2e3446;
      border-radius: 18px;
      padding: 14px;
      box-shadow: var(--shadow-modal);
    }
    .lark-card {
      border-radius: 10px;
      overflow: hidden;
      border: 1px solid #2d3446;
      background: #1d212c;
    }
    .lark-hdr {
      padding: 9px 12px;
      font-weight: 600;
      font-size: var(--fs-base);
    }
    .lark-hdr.blue { background: #1e3a6d; color: #dbeafe; }
    .lark-hdr.amber { background: #5c3b11; color: #fef3c7; }
    .lark-hdr.green { background: #174e2d; color: #dcfce7; }
    .lark-hdr.red { background: #5f1e1e; color: #fee2e2; }
    .lark-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
    .lark-btn {
      width: 100%;
      padding: 8px 12px;
      border-radius: 7px;
      border: 1px solid #3c445c;
      background: #262c3a;
      color: #f1f5f9;
      font-weight: 600;
      cursor: pointer;
    }
    .lark-btn.green { background: #2d9d5b; border-color: #2d9d5b; color: #fff; }
    .lark-btn.red { background: rgba(220,88,74,0.18); border-color: rgba(220,88,74,0.5); color: #fca5a5; }

    @media (prefers-reduced-motion: reduce) {
      *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
      }
    }
