/*
 * pipeline.css — CRM v3 Pipeline & Deal Management
 * Combined from 3 Claude design prototypes (April 2026)
 * Fonts loaded from Google Fonts CDN in pipeline.html.
 */

/* === 1. BASE === */
  :root {
    --bg: #F3EEE5;
    --surface: #FBF8F1;
    --surface-2: #F0EADD;
    --line: #E2DDD3;
    --line-2: #D0C9BC;
    --fg: #131B2B;
    --fg-muted: #5C6478;
    --fg-subtle: #8B93A6;
    --accent: #1B2B4E;
    --accent-ink: #FBF8F1;
    --accent-2: #D94C3D;
    --amber: #C69A2C;
    --amber-l: #fdf3d6;
    --green: #0E7C66;
    --green-l: #DCEEE6;
    --red-l: #F8DDD8;
    --shadow-1: 0 1px 0 rgba(15,27,51,.04), 0 1px 2px rgba(15,27,51,.06);
    --shadow-2: 0 10px 32px rgba(15,27,51,.14), 0 2px 6px rgba(15,27,51,.06);
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;
    --pad: 8px;
    --pad-sm: 6px;
    --gap: 7px;
    --ctl-h: 28px;
    --font-sans: "Space Grotesk", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, monospace;
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--fg);
    font-size: 13px;
    line-height: 1.45;
    font-feature-settings: "ss01", "cv02", "cv11";
    -webkit-font-smoothing: antialiased;
  }
  button { font-family: inherit; font-size: inherit; color: inherit; }

  /* ───── Top bar ───── */
  .topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    position: sticky; top: 0; z-index: 20;
  }
  .brand {
    display: flex; align-items: baseline; gap: 8px;
    padding-right: 12px; border-right: 1px solid var(--line);
    margin-right: 4px;
  }
  .brand-mark {
    font-weight: 700; letter-spacing: -0.01em; font-size: 14px;
    color: var(--accent);
  }
  .brand-mark::before {
    content: ""; display: inline-block; width: 9px; height: 9px;
    background: var(--accent); margin-right: 7px; transform: translateY(0px);
    border-radius: 1px;
  }
  .brand-section { color: var(--fg-muted); font-size: 12px; letter-spacing: 0.02em; text-transform: uppercase; }

  .pipeline-toggle {
    display: inline-flex; padding: 2px; gap: 0;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: var(--radius-sm);
  }
  .pipeline-toggle button {
    padding: 5px 14px; border: 0; background: transparent;
    cursor: pointer; border-radius: 4px; font-weight: 500;
    color: var(--fg-muted); transition: all .12s;
  }
  .pipeline-toggle button.active {
    background: var(--accent); color: var(--accent-ink);
  }
  .pipeline-toggle button:not(.active):hover { color: var(--fg); }

  .topbar-spacer { flex: 1; }

  .topbar .btn {
    height: var(--ctl-h);
    display: inline-flex; align-items: center; gap: 6px;
    padding: 0 10px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm); cursor: pointer;
    color: var(--fg);
  }
  .topbar .btn:hover { border-color: var(--line-2); background: var(--surface-2); }
  .topbar .btn.primary {
    background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  }
  .topbar .btn.primary:hover { filter: brightness(1.1); }
  .topbar .btn svg { width: 13px; height: 13px; }

  .chip-owner {
    display: inline-flex; align-items: center; gap: 6px;
    height: var(--ctl-h); padding: 0 4px 0 10px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 999px; font-size: 12px;
  }
  .chip-owner .dot {
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--accent); color: var(--accent-ink);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 9px; font-weight: 600;
  }
  .chip-owner .x {
    width: 16px; height: 16px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--fg-subtle); cursor: pointer; margin-left: 2px;
  }
  .chip-owner .x:hover { color: var(--fg); background: var(--surface-2); }

  .sort-select {
    height: var(--ctl-h);
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm); padding: 0 22px 0 10px;
    font: inherit; color: var(--fg); cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M2 4l3 3 3-3' stroke='%235C6478' stroke-width='1.4' fill='none' stroke-linecap='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 8px center;
  }

  /* ───── Stage selector (mobile only) ───── */
  .stage-selector { display: none; }

  /* ───── Kanban ───── */
  .kanban-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 14px 18px 80px;
    height: calc(100vh - 49px);
  }
  .kanban {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 240px;
    gap: 10px;
    height: 100%;
    min-width: max-content;
  }
  .col {
    background: transparent;
    border-radius: var(--radius-lg);
    display: flex; flex-direction: column;
    min-height: 0;
    transition: background .15s;
    position: relative;
  }
  .col + .col::before {
    content: "";
    position: absolute;
    left: -5px;
    top: 14px;
    bottom: 14px;
    border-left: 1px dashed var(--line-2);
    pointer-events: none;
  }
  .col.drop-target {
    background: color-mix(in oklab, var(--accent) 6%, transparent);
    outline: 1.5px dashed color-mix(in oklab, var(--accent) 35%, transparent);
    outline-offset: -2px;
  }
  .col-header {
    padding: 10px 12px 10px;
    border-top: 2px solid var(--line-2);
    margin-bottom: 8px;
  }
  .col[data-stage-idx="0"] .col-header { border-top-color: var(--fg-subtle); }
  .col[data-stage-idx="1"] .col-header { border-top-color: #A88E5C; }
  .col[data-stage-idx="2"] .col-header { border-top-color: #8B7E59; }
  .col[data-stage-idx="3"] .col-header { border-top-color: var(--amber); }
  .col[data-stage-idx="4"] .col-header { border-top-color: #7A6B47; }
  .col[data-stage-idx="5"] .col-header { border-top-color: #4D6B5C; }
  .col[data-stage-idx="6"] .col-header { border-top-color: #2F5947; }
  .col[data-stage-idx="7"] .col-header { border-top-color: var(--green); }

  .col-title-row {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 8px;
  }
  .col-title {
    font-weight: 600; font-size: 13px; color: var(--fg);
    letter-spacing: -0.005em;
  }
  .col-count {
    font-family: var(--font-mono); font-size: 11px;
    color: var(--fg-muted); font-feature-settings: "tnum";
    white-space: nowrap;
  }
  .col-money {
    margin-top: 6px;
    display: flex; align-items: baseline; gap: 6px;
  }
  .col-money-label {
    font-size: 10px; color: var(--fg-subtle);
    letter-spacing: 0.04em; text-transform: uppercase;
  }
  .col-money-value {
    font-family: var(--font-mono); font-weight: 600; font-size: 14px;
    color: var(--fg); font-feature-settings: "tnum";
  }
  .col-forecast {
    margin-top: 2px;
    font-family: var(--font-mono); font-size: 11px;
    color: var(--fg-muted); font-feature-settings: "tnum";
  }
  .col-forecast .pct {
    color: var(--fg-subtle);
  }

  .col-body {
    flex: 1; min-height: 0;
    overflow-y: auto;
    padding: 0 4px 24px 0;
    display: flex; flex-direction: column; gap: 8px;
  }
  .col-body::-webkit-scrollbar { width: 6px; }
  .col-body::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

  /* ───── Card ───── */
  .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px 11px;
    cursor: grab;
    box-shadow: var(--shadow-1);
    transition: border-color .12s, transform .12s, box-shadow .12s;
    position: relative;
    display: flex; flex-direction: column; gap: 6px;
  }
  .card:hover { border-color: var(--line-2); }
  .card:active { cursor: grabbing; }
  .card.dragging {
    opacity: 0.5; transform: scale(1.02) rotate(-0.5deg);
    box-shadow: var(--shadow-2);
    border-color: var(--accent);
  }
  .card.shake { animation: shake .35s ease-in-out; }
  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
  }

  .card-priority {
    position: absolute; left: 0; top: 10px; bottom: 10px;
    width: 2px; border-radius: 2px;
  }
  .card[data-priority="kuum"] .card-priority { background: var(--accent-2); }
  .card[data-priority="soe"] .card-priority { background: var(--amber); }
  .card[data-priority="kulm"] .card-priority { background: transparent; }

  .card-title {
    font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
    color: var(--fg); line-height: 1.25;
    padding-right: 14px;
  }

  .card-commission-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 2px;
  }
  .card-commission {
    font-family: var(--font-mono); font-size: 18px; font-weight: 600;
    color: var(--fg); letter-spacing: -0.02em;
    font-feature-settings: "tnum";
  }
  .activity-dot {
    width: 9px; height: 9px; border-radius: 50%;
    flex: none;
    box-shadow: 0 0 0 2px var(--surface);
  }
  .activity-dot[data-state="overdue"] { background: var(--accent-2); }
  .activity-dot[data-state="today"]   { background: var(--amber); }
  .activity-dot[data-state="future"]  { background: var(--green); }
  .activity-dot[data-state="none"]    {
    background: transparent;
    border: 1.5px dashed var(--fg-subtle);
    box-shadow: none;
  }

  .card-price-row {
    font-family: var(--font-mono); font-size: 12px;
    color: var(--fg-muted); font-feature-settings: "tnum";
    margin-top: -1px;
  }
  .card-price-row .sep { color: var(--fg-subtle); margin: 0 4px; }

  .card-meta {
    margin-top: 4px;
    padding-top: 6px;
    display: flex; flex-direction: column; gap: 2px;
  }
  .card-contact, .card-next {
    font-size: 12px; color: var(--fg-muted);
    display: flex; align-items: center; gap: 6px;
    line-height: 1.35;
  }
  .card-next { color: var(--fg); }
  .card-next.overdue { color: var(--accent-2); }
  .card-next.today   { color: var(--amber); }
  .card-next.none    { color: var(--fg-subtle); font-style: italic; }
  .card-icon {
    width: 11px; height: 11px; flex: none; opacity: .65;
  }
  .card-source {
    margin-left: auto;
    font-size: 10px;
    color: var(--fg-subtle);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 1px 5px;
    background: var(--surface-2);
    border-radius: 3px;
  }
  .viewings {
    font-family: var(--font-mono);
    font-feature-settings: "tnum";
  }

  /* ───── WON / LOST drop zones ───── */
  .dropzones {
    position: fixed; left: 0; right: 0; bottom: 0;
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 0;
    height: 0;
    overflow: hidden;
    transition: height .18s ease-out;
    z-index: 30;
    pointer-events: none;
  }
  .dropzones.visible { height: 64px; pointer-events: auto; }
  .dz {
    display: flex; align-items: center; justify-content: center;
    gap: 10px;
    font-weight: 600;
    border-top: 2px solid;
    transition: filter .12s;
  }
  .dz-won {
    background: color-mix(in oklab, var(--green) 14%, var(--surface));
    color: var(--green);
    border-color: var(--green);
  }
  .dz-lost {
    background: color-mix(in oklab, var(--accent-2) 14%, var(--surface));
    color: var(--accent-2);
    border-color: var(--accent-2);
  }
  .dz.over { filter: brightness(0.92); }
  .dz svg { width: 16px; height: 16px; }

  /* ───── Mobile ───── */
  @media (max-width: 768px) {
    .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
    .topbar-spacer { display: none; }
    .topbar .btn span:not(.label-mobile) { display: none; }
    .chip-owner { font-size: 11px; }
    .pipeline-toggle button { padding: 5px 12px; }

    .kanban-wrap { display: none; }

    .stage-selector {
      display: block;
      padding: 12px 14px;
      background: var(--surface);
      border-bottom: 1px solid var(--line);
      position: sticky; top: 49px; z-index: 15;
    }
    .stage-selector select {
      width: 100%; height: 38px;
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 0 32px 0 12px;
      font: inherit; color: var(--fg);
      font-weight: 600;
      appearance: none;
      background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 5l3 3 3-3' stroke='%235C6478' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
      background-repeat: no-repeat;
      background-position: right 12px center;
    }
    .stage-selector .summary {
      margin-top: 8px;
      display: flex; gap: 14px;
      font-size: 11px; color: var(--fg-muted);
    }
    .stage-selector .summary b {
      color: var(--fg); font-family: var(--font-mono);
      font-weight: 600;
      font-feature-settings: "tnum";
      margin-left: 4px;
    }

    .mobile-stack {
      display: flex; flex-direction: column; gap: 10px;
      padding: 14px;
    }

    .panel { width: 100%; }
    .dropzones { display: none; }
  }

  @media (min-width: 769px) {
    .mobile-stack, .stage-selector { display: none; }
  }

  /* Empty column hint */
  .col-empty {
    padding: 14px 12px;
    border: 1px dashed var(--line-2);
    border-radius: var(--radius);
    color: var(--fg-subtle);
    font-size: 12px;
    text-align: center;
  }


/* === 2. DEAL DETAIL PANEL === */
/* ───── Scrim ───── */
  .scrim {
    position: fixed; inset: 0;
    background: rgba(15, 27, 51, 0.40);
    z-index: 40;
    display: none;
  }
  .scrim.open { display: block; }

  /* ───── Panel ───── */
  .panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 720px; max-width: 100%;
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-2);
    z-index: 50;
    display: flex; flex-direction: column;
    transform: translateX(100%);
    transition: transform .24s cubic-bezier(.32,.72,0,1);
    pointer-events: none;
  }
  .panel.open { transform: translateX(0); pointer-events: auto; }

  /* Header */
  .ph {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    position: sticky; top: 0; z-index: 5;
  }
  .ph .close, .ph .icon-btn {
    background: var(--surface); border: 1px solid var(--line);
    width: 28px; height: 28px; border-radius: 6px;
    cursor: pointer; color: var(--fg-muted);
    display: inline-flex; align-items: center; justify-content: center;
    flex: none;
  }
  .ph .close:hover, .ph .icon-btn:hover { background: var(--surface-2); color: var(--fg); }
  .ph .icon-btn svg, .ph .close svg { width: 13px; height: 13px; }
  .ph .title-wrap { flex: 1; min-width: 0; }
  .ph h2 {
    margin: 0; font-size: 16px; font-weight: 600;
    letter-spacing: -0.01em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .ph .subline {
    font-family: var(--font-mono); font-size: 11px; color: var(--fg-subtle);
    margin-top: 1px; font-feature-settings: "tnum";
  }
  .ph .actions { display: inline-flex; gap: 6px; align-items: center; }
  .ph .btn {
    height: 28px; padding: 0 10px;
    border-radius: var(--radius-sm); border: 1px solid;
    font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px;
  }
  .ph .btn svg { width: 12px; height: 12px; }
  .btn-won  { background: var(--green-l); color: var(--green); border-color: color-mix(in oklab, var(--green) 28%, transparent); }
  .btn-won:hover { background: color-mix(in oklab, var(--green) 22%, var(--surface)); }
  .btn-lost { background: var(--red-l); color: var(--accent-2); border-color: color-mix(in oklab, var(--accent-2) 28%, transparent); }
  .btn-lost:hover { background: color-mix(in oklab, var(--accent-2) 22%, var(--surface)); }

  /* Stage breadcrumb */
  .stage-row {
    display: flex; align-items: center; gap: 14px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    flex: none;
  }
  .crumb { font-size: 12px; color: var(--fg-muted); }
  .crumb b { color: var(--fg); font-weight: 600; }
  .crumb-trigger {
    background: none; border: 0; padding: 2px 4px; cursor: pointer; border-radius: 4px;
    color: inherit; font: inherit;
  }
  .crumb-trigger:hover { background: var(--surface-2); }
  .stage-dots { display: flex; gap: 5px; margin-left: auto; align-items: center; }
  .stage-dots .d {
    width: 10px; height: 10px; border-radius: 50%;
    background: transparent; border: 1.5px solid var(--line-2);
    cursor: pointer;
  }
  .stage-dots .d.filled { background: var(--accent); border-color: var(--accent); }
  .stage-dots .d.current { box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 18%, transparent); }
  .stage-dots .d:hover { border-color: var(--accent); }

  /* Body two-column */
  .body {
    flex: 1; min-height: 0;
    display: grid;
    grid-template-columns: 40% 60%;
  }

  /* Facts (left) */
  .facts {
    border-right: 1px solid var(--line);
    overflow-y: auto;
    padding: 14px 16px 24px;
  }
  .fact {
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
  .fact:last-child { border-bottom: 0; }
  .fact .lbl {
    font-size: 10px; color: var(--fg-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-bottom: 3px;
  }
  .fact .val {
    font-size: 13px; color: var(--fg);
    cursor: text;
    border-radius: 3px;
    padding: 2px 4px; margin: -2px -4px;
    transition: background .1s;
  }
  .fact .val:hover { background: var(--surface-2); outline: 1px solid var(--line); }
  .fact .val.empty { color: var(--fg-subtle); font-style: italic; }
  .fact .val.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
  .fact-headline .val {
    font-family: var(--font-mono); font-size: 22px; font-weight: 700;
    letter-spacing: -0.02em; color: var(--fg);
    font-feature-settings: "tnum";
  }
  .fact-headline { padding: 10px 0 12px; }
  .fact-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .fact-row .fact { border-bottom: 0; padding: 0; }
  .fact-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
  .pool-chip {
    display: inline-block;
    background: var(--surface-2); border: 1px solid var(--line);
    padding: 2px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 500;
  }
  .pool-chip[data-pool="myyja"] { background: var(--accent-l); color: var(--accent); border-color: color-mix(in oklab, var(--accent) 18%, transparent); }

  /* Priority chip */
  .prio {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px;
  }
  .prio .pdot {
    width: 9px; height: 9px; border-radius: 50%;
    flex: none;
  }
  .prio[data-prio="kuum"] .pdot { background: var(--accent-2); }
  .prio[data-prio="soe"]  .pdot { background: var(--amber); }
  .prio[data-prio="kulm"] .pdot { background: transparent; border: 1.5px dashed var(--fg-subtle); }

  .fact--no-border { border-bottom: 0 !important; }
  .contact-stack { display: flex; flex-direction: column; gap: 1px; }
  .contact-stack .name { font-weight: 600; }
  .contact-stack .meta { font-family: var(--font-mono); font-size: 12px; color: var(--fg-muted); font-feature-settings: "tnum"; }
  .contact-stack a { color: inherit; text-decoration: none; }
  .contact-stack a:hover { color: var(--accent); }

  .avm {
    background: var(--accent-l);
    border: 1px solid color-mix(in oklab, var(--accent) 14%, transparent);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    margin-top: 4px;
  }
  .avm .lbl { color: var(--accent); font-weight: 600; }
  .avm .val { color: var(--accent); font-family: var(--font-mono); font-size: 16px; font-weight: 700; padding: 0; margin: 0; font-feature-settings: "tnum"; }
  .avm .val:hover { background: transparent; outline: none; }
  .avm .meta { font-size: 11px; color: var(--fg-muted); font-family: var(--font-mono); margin-top: 2px; font-feature-settings: "tnum"; }

  .obj-link {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-top: 8px;
    text-decoration: none; color: var(--fg);
    transition: border-color .12s, background .12s;
  }
  .obj-link:hover { border-color: var(--accent); background: var(--surface-2); }
  .obj-link .thumb {
    width: 36px; height: 36px; border-radius: 4px;
    background:
      repeating-linear-gradient(135deg, var(--line) 0 4px, var(--surface-2) 4px 8px);
    border: 1px solid var(--line);
    flex: none;
  }
  .obj-link .info { flex: 1; min-width: 0; }
  .obj-link .info .t { font-weight: 600; font-size: 12px; }
  .obj-link .info .s { font-size: 11px; color: var(--fg-muted); font-family: var(--font-mono); font-feature-settings: "tnum"; }
  .obj-link .arrow { color: var(--fg-subtle); }

  /* Activity (right) */
  .activity {
    display: flex; flex-direction: column;
    min-height: 0;
  }
  .activity-bar {
    display: flex; gap: 6px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    flex: none;
  }
  .activity-bar button {
    height: 30px; padding: 0 12px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm); cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; font-weight: 500;
  }
  .activity-bar button:hover { background: var(--surface-2); border-color: var(--line-2); }
  .activity-bar button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .activity-bar button.primary:hover { filter: brightness(1.1); }
  .activity-bar button svg { width: 12px; height: 12px; }

  /* Inline log form */
  .log-form {
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    padding: 12px 16px;
    display: none;
    flex-direction: column; gap: 8px;
  }
  .log-form.open { display: flex; }
  .log-form-row { display: flex; gap: 8px; align-items: center; }
  .log-form select, .log-form input[type="datetime-local"] {
    height: 28px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0 8px;
  }
  .log-form textarea {
    width: 100%; min-height: 56px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    resize: vertical;
    font-family: inherit;
  }
  .log-form .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
  .log-form button {
    height: 26px; padding: 0 10px;
    border-radius: var(--radius-sm); border: 1px solid var(--line);
    background: var(--surface); cursor: pointer;
    font-size: 12px;
  }
  .log-form button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

  /* Next step pinned */
  .next-step {
    margin: 12px 16px 6px;
    padding: 11px 12px 11px 14px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-left: 3px solid var(--amber);
    border-radius: var(--radius-sm);
    display: flex; align-items: flex-start; gap: 10px;
  }
  .next-step[data-state="overdue"] { border-left-color: var(--accent-2); }
  .next-step[data-state="future"]  { border-left-color: var(--green); }
  .next-step[data-state="none"]    { border-left-color: var(--fg-subtle); }
  .next-step .dot {
    width: 9px; height: 9px; border-radius: 50%;
    margin-top: 5px; flex: none;
  }
  .next-step[data-state="overdue"] .dot { background: var(--accent-2); }
  .next-step[data-state="today"] .dot   { background: var(--amber); }
  .next-step[data-state="future"] .dot  { background: var(--green); }
  .next-step[data-state="none"] .dot    { background: transparent; border: 1.5px dashed var(--fg-subtle); }
  .next-step .ns-body { flex: 1; min-width: 0; }
  .next-step .ns-label {
    font-size: 10px; color: var(--fg-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-bottom: 2px;
  }
  .next-step .ns-text { font-weight: 500; font-size: 13px; }
  .next-step .ns-when {
    font-family: var(--font-mono); font-size: 11px;
    color: var(--fg-muted); margin-top: 2px;
    font-feature-settings: "tnum";
  }
  .next-step .ns-when.overdue { color: var(--accent-2); font-weight: 600; }
  .next-step .ns-when.today   { color: var(--amber); font-weight: 600; }
  .next-step .ns-actions { display: flex; gap: 4px; }
  .next-step .ns-actions button {
    background: transparent; border: 1px solid var(--line);
    width: 24px; height: 24px; border-radius: 5px;
    cursor: pointer; color: var(--fg-muted);
    display: inline-flex; align-items: center; justify-content: center;
  }
  .next-step .ns-actions button:hover { background: var(--surface); color: var(--fg); border-color: var(--line-2); }
  .next-step .ns-actions svg { width: 11px; height: 11px; }

  /* Timeline */
  .timeline-wrap {
    flex: 1; min-height: 0; overflow-y: auto;
    padding: 6px 16px 24px;
  }
  .tl-divider {
    display: flex; align-items: center; gap: 10px;
    margin: 10px 0 4px;
    color: var(--fg-subtle);
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  }
  .tl-divider::before, .tl-divider::after {
    content: ""; flex: 1; height: 1px;
    background: var(--line);
  }

  .tl-entry {
    display: grid;
    grid-template-columns: 22px 1fr auto;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--line);
    align-items: flex-start;
  }
  .tl-entry:last-child { border-bottom: 0; }
  .tl-icon {
    width: 22px; height: 22px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 5px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--fg-muted);
    flex: none;
    font-size: 11px;
  }
  .tl-icon svg { width: 11px; height: 11px; }
  .tl-entry[data-type="kone"]      .tl-icon { background: var(--accent-l); color: var(--accent); border-color: color-mix(in oklab, var(--accent) 16%, transparent); }
  .tl-entry[data-type="email"]     .tl-icon { background: var(--surface); color: var(--accent); }
  .tl-entry[data-type="kohtumine"] .tl-icon,
  .tl-entry[data-type="vaatamine"] .tl-icon { background: var(--amber-l); color: var(--amber); border-color: color-mix(in oklab, var(--amber) 26%, transparent); }
  .tl-entry[data-type="markus"]    .tl-icon { background: var(--surface-2); }
  .tl-entry[data-type="fail"]      .tl-icon { background: var(--surface-2); }
  .tl-entry[data-type="staadium_muutus"] {
    opacity: 0.78;
  }
  .tl-entry[data-type="staadium_muutus"] .tl-icon {
    background: transparent; border-style: dashed;
  }
  .tl-entry[data-type="staadium_muutus"] .tl-title { font-weight: 500; }

  .tl-content { min-width: 0; }
  .tl-title {
    font-size: 13px; font-weight: 600;
    line-height: 1.35;
  }
  .tl-body {
    color: var(--fg-muted);
    font-size: 12px;
    line-height: 1.45;
    margin-top: 2px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .tl-body.expanded { -webkit-line-clamp: unset; }
  .tl-more {
    display: inline-block;
    background: none; border: 0; padding: 2px 0;
    color: var(--accent); cursor: pointer; font-size: 11px;
    font-weight: 500;
  }
  .tl-more:hover { text-decoration: underline; }
  .tl-meta {
    font-family: var(--font-mono); font-size: 11px;
    color: var(--fg-subtle); white-space: nowrap;
    font-feature-settings: "tnum";
    text-align: right;
    line-height: 1.4;
    flex: none;
  }
  .tl-meta b { color: var(--fg-muted); font-weight: 500; }

  /* Stage selector dropdown */
  .stage-menu {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
    padding: 4px;
    z-index: 100;
    min-width: 220px;
    display: none;
  }
  .stage-menu.open { display: block; }
  .stage-menu button {
    width: 100%; text-align: left;
    background: transparent; border: 0;
    padding: 7px 10px; border-radius: 4px;
    cursor: pointer;
    display: flex; align-items: center; gap: 8px;
    font-size: 13px;
  }
  .stage-menu button:hover { background: var(--surface-2); }
  .stage-menu button.current { background: var(--accent-l); color: var(--accent); font-weight: 600; }
  .stage-menu .pct {
    margin-left: auto;
    font-family: var(--font-mono); font-size: 11px; color: var(--fg-subtle);
    font-feature-settings: "tnum";
  }

  /* Inline editing */
  .val.editing {
    background: var(--surface);
    outline: 2px solid var(--accent);
    outline-offset: -1px;
  }
  .inline-input {
    width: 100%;
    background: transparent;
    border: 0; outline: 0;
    font: inherit; color: inherit;
    padding: 0;
  }

  /* Lost-reason modal */


/* === 3. WON/LOST CONFIRM MODAL === */
  .modal-back {
    position: fixed; inset: 0;
    background: rgba(15, 27, 51, 0.40);
    z-index: 60;
    display: none; align-items: center; justify-content: center;
  }
  .modal-back.open { display: flex; }
  .modal-back .modal {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    width: 420px; max-width: 90vw;
    padding: 18px 20px;
  }
  .modal-back .modal h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
  .modal-back .modal .desc { font-size: 12px; color: var(--fg-muted); margin-bottom: 12px; }
  .modal-back .modal .reason-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
  .modal-back .modal .reason-list label {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    cursor: pointer;
  }
  .modal-back .modal .reason-list label:hover { background: var(--surface-2); }
  .modal-back .modal .reason-list input { accent-color: var(--accent); }
  .modal-back .modal .row-actions { display: flex; gap: 8px; justify-content: flex-end; }
  .modal-back .modal .row-actions button {
    height: 30px; padding: 0 14px;
    border-radius: var(--radius-sm); border: 1px solid var(--line);
    background: var(--surface); cursor: pointer;
    font-weight: 500;
  }
  .modal-back .modal .row-actions button.primary {
    background: var(--accent-2); color: var(--accent-ink); border-color: var(--accent-2);
  }
  .modal-back .modal input[type="number"], .modal input[type="text"] {
    width: 100%;
    height: 36px; padding: 0 12px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
  }

  /* Closed-deal banner */
  .closed-banner {
    display: none;
    align-items: center; gap: 10px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--line);
    font-size: 12px;
  }
  .panel.is-won .closed-banner { display: flex; background: var(--green-l); color: var(--green); }
  .panel.is-lost .closed-banner { display: flex; background: var(--red-l); color: var(--accent-2); }
  .panel.is-won .body, .panel.is-lost .body { opacity: 0.86; }
  .panel.is-won .val, .panel.is-lost .val { pointer-events: none; }

  /* Mobile */
  @media (max-width: 1023px) {
    .panel { width: 90vw; }
  }
  @media (max-width: 768px) {
    .panel { width: 100vw; }
    .body { grid-template-columns: 1fr; }
    .facts { border-right: 0; border-bottom: 1px solid var(--line); }
    .stage-row { flex-wrap: wrap; gap: 8px; }
    .stage-dots { margin-left: 0; }
    .ph .btn span { display: none; }
  }


/* === 4. NEW DEAL FORM MODAL === */
/* ───── Scrim ───── */
  .form-scrim {
    position: fixed; inset: 0;
    background: rgba(15, 27, 51, 0.40);
    z-index: 40;
    display: none;
    align-items: center; justify-content: center;
    padding: 24px;
    overflow-y: auto;
  }
  .form-scrim.open { display: flex; }
  .form-scrim.shake .modal { animation: shake .42s; }
  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(3px); }
  }

  /* ───── Modal ───── */
  .form-scrim .modal {
    width: 560px; max-width: 100%;
    max-height: calc(100vh - 48px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    display: flex; flex-direction: column;
    animation: pop .22s cubic-bezier(.32,.72,0,1);
    overflow: hidden;
  }
  @keyframes pop { from { transform: translateY(8px) scale(.985); opacity: 0; } to { transform: none; opacity: 1; } }

  /* Header */
  .mh {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    flex: none;
  }
  .mh h2 {
    margin: 0; font-size: 16px; font-weight: 600;
    letter-spacing: -0.01em;
    flex: 1;
  }
  .mh .close {
    background: var(--surface); border: 1px solid var(--line);
    width: 28px; height: 28px; border-radius: 6px;
    cursor: pointer; color: var(--fg-muted);
    display: inline-flex; align-items: center; justify-content: center;
  }
  .mh .close:hover { background: var(--surface-2); color: var(--fg); }
  .mh .close svg { width: 13px; height: 13px; }

  /* Match badge */
  .match-banner {
    display: none;
    align-items: center; gap: 10px;
    padding: 9px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--accent-l);
    font-size: 12px;
    color: var(--accent);
    flex: none;
  }
  body[data-state="match"] .match-banner { display: flex; }
  .match-banner .mb-id {
    font-family: var(--font-mono); font-feature-settings: "tnum";
    font-weight: 600;
    background: var(--surface); border: 1px solid color-mix(in oklab, var(--accent) 24%, transparent);
    padding: 2px 7px; border-radius: 4px;
    font-size: 11px;
  }
  .match-banner .mb-text { flex: 1; }
  .match-banner .mb-dismiss {
    background: transparent; border: 0;
    color: var(--accent); cursor: pointer;
    padding: 2px 6px; font-size: 11px;
    text-decoration: underline;
  }

  /* Error banner */
  .err-banner {
    display: none;
    align-items: center; gap: 8px;
    padding: 9px 18px;
    background: var(--red-l);
    color: var(--accent-2);
    border-bottom: 1px solid color-mix(in oklab, var(--accent-2) 22%, transparent);
    font-size: 12px;
    flex: none;
  }
  body[data-state="server-error"] .err-banner { display: flex; }
  .err-banner.show { display: flex; }
  .err-banner svg { width: 14px; height: 14px; flex: none; }

  /* Body — scrollable */
  .mb {
    flex: 1; min-height: 0;
    overflow-y: auto;
    padding: 6px 0 4px;
  }

  /* Section */
  .sec { border-bottom: 1px solid var(--line); }
  .sec:last-child { border-bottom: 0; }
  .sec-pin { padding: 14px 18px 16px; }
  .sec-head {
    width: 100%;
    display: flex; align-items: center; gap: 8px;
    padding: 12px 18px;
    background: transparent; border: 0;
    cursor: pointer;
    text-align: left;
    color: var(--fg);
  }
  .sec-head:hover { background: var(--surface-2); }
  .sec-head .caret {
    width: 14px; height: 14px;
    color: var(--fg-subtle);
    transition: transform .15s;
    flex: none;
  }
  .sec[data-open="true"] .sec-head .caret { transform: rotate(90deg); }
  .sec-head .lbl {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--fg-muted);
    flex: none;
  }
  .sec-head .summary {
    flex: 1;
    font-size: 12px; color: var(--fg-subtle);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    text-align: right;
    font-family: var(--font-mono);
    font-feature-settings: "tnum";
  }
  .sec-head .summary.empty { font-style: italic; }
  .sec-body {
    display: none;
    padding: 4px 18px 16px;
  }
  .sec[data-open="true"] .sec-body { display: block; }

  /* Field */
  .field { margin-bottom: 12px; }
  .field:last-child { margin-bottom: 0; }
  .field .lbl {
    display: flex; align-items: center; gap: 4px;
    font-size: 10px; color: var(--fg-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-bottom: 5px;
    font-weight: 600;
  }
  .field .lbl .req { color: var(--accent-2); margin-left: 1px; }
  .field .lbl .info {
    width: 12px; height: 12px;
    border: 1px solid var(--line-2);
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 8px; color: var(--fg-subtle);
    cursor: help;
    text-transform: none; letter-spacing: 0;
    margin-left: 2px;
  }
  .field .help {
    font-size: 11px; color: var(--fg-subtle);
    margin-top: 5px;
  }
  .field .help.error {
    color: var(--accent-2);
    font-weight: 500;
  }

  /* Input — borrowed from inline-input pattern */
  .inp, .sel, .ta {
    width: 100%;
    height: 34px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0 11px;
    font-size: 13px;
    color: var(--fg);
    transition: border-color .12s, box-shadow .12s;
  }
  .ta { height: auto; min-height: 64px; padding: 8px 11px; resize: vertical; line-height: 1.4; }
  .inp:hover, .sel:hover, .ta:hover { border-color: var(--line-2); }
  .inp:focus, .sel:focus, .ta:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 14%, transparent);
  }
  .inp.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
  .inp.invalid {
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent-2) 18%, transparent);
  }
  .sel {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16' fill='none'><path d='M4 6l4 4 4-4' stroke='%235C6478' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
  }

  /* Input with suffix (currency / pct) */
  .inp-wrap {
    position: relative;
    display: flex; align-items: center;
  }
  .inp-wrap .inp { padding-right: 38px; }
  .inp-wrap .suffix {
    position: absolute; right: 11px;
    color: var(--fg-subtle); font-size: 12px;
    font-family: var(--font-mono);
    pointer-events: none;
  }

  /* Two-up grid */
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

  /* Pool radio (segmented) */
  .seg {
    display: inline-flex; padding: 3px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: var(--radius-sm);
  }
  .seg label {
    cursor: pointer;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13px; font-weight: 500;
    color: var(--fg-muted);
    display: inline-flex; align-items: center; gap: 6px;
    transition: background .12s, color .12s;
  }
  .seg input { display: none; }
  .seg label:hover { color: var(--fg); }
  .seg label.checked {
    background: var(--surface);
    color: var(--fg);
    box-shadow: var(--shadow-1);
  }
  .seg .pool-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--fg-subtle);
  }
  .seg input[value="myyja"] + .pool-label .pool-dot { background: var(--accent); }
  .seg input[value="ostja"] + .pool-label .pool-dot { background: var(--amber); }

  /* Priority radio */
  .prio-row {
    display: flex; gap: 6px;
  }
  .prio-row label {
    flex: 1;
    cursor: pointer;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 13px;
    color: var(--fg);
    transition: border-color .12s, background .12s;
  }
  .prio-row label:hover { border-color: var(--line-2); background: var(--surface-2); }
  .prio-row input { display: none; }
  .prio-row label.checked {
    border-color: var(--accent);
    background: var(--accent-l);
  }
  .prio-row .pdot {
    width: 9px; height: 9px; border-radius: 50%;
    flex: none;
  }
  .prio-row label[data-prio="kuum"] .pdot { background: var(--accent-2); }
  .prio-row label[data-prio="soe"]  .pdot { background: var(--amber); }
  .prio-row label[data-prio="kulm"] .pdot { background: transparent; border: 1.5px dashed var(--fg-subtle); }

  /* Computed callout (commission) */
  .computed {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--accent-l);
    border: 1px solid color-mix(in oklab, var(--accent) 14%, transparent);
    border-radius: var(--radius-sm);
    display: flex; align-items: baseline; gap: 8px;
    font-size: 12px;
  }
  .computed .arrow { color: var(--accent); font-weight: 700; }
  .computed .lbl-c { color: var(--accent); font-weight: 600; }
  .computed .val-c {
    margin-left: auto;
    font-family: var(--font-mono); font-feature-settings: "tnum";
    font-size: 15px; font-weight: 700;
    color: var(--accent);
  }
  .computed .val-c.empty { color: var(--fg-subtle); font-weight: 500; }
  .computed .meta {
    font-size: 11px; color: var(--fg-muted);
    margin-left: 6px;
  }

  /* Object search */
  .obj-search-wrap { position: relative; }
  .obj-results {
    display: none;
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-2);
    z-index: 10;
    max-height: 220px; overflow-y: auto;
  }
  .obj-results.show { display: block; }
  .obj-results button {
    width: 100%;
    display: flex; align-items: center; gap: 10px;
    padding: 9px 11px;
    background: transparent; border: 0; border-bottom: 1px solid var(--line);
    text-align: left;
    cursor: pointer;
  }
  .obj-results button:last-child { border-bottom: 0; }
  .obj-results button:hover { background: var(--surface-2); }
  .obj-results .thumb {
    width: 30px; height: 30px; border-radius: 4px;
    background:
      repeating-linear-gradient(135deg, var(--line) 0 4px, var(--surface-2) 4px 8px);
    border: 1px solid var(--line);
    flex: none;
  }
  .obj-results .info { flex: 1; min-width: 0; }
  .obj-results .info .t { font-weight: 600; font-size: 12px; }
  .obj-results .info .s { font-size: 11px; color: var(--fg-muted); font-family: var(--font-mono); font-feature-settings: "tnum"; }

  .obj-linked {
    display: none;
    align-items: center; gap: 10px;
    padding: 9px 11px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
  }
  .obj-linked.show { display: flex; }
  .obj-linked .thumb {
    width: 32px; height: 32px; border-radius: 4px;
    background:
      repeating-linear-gradient(135deg, var(--line) 0 4px, var(--surface-2) 4px 8px);
    border: 1px solid var(--line);
    flex: none;
  }
  .obj-linked .info { flex: 1; min-width: 0; }
  .obj-linked .info .t { font-weight: 600; font-size: 12px; }
  .obj-linked .info .s { font-size: 11px; color: var(--fg-muted); font-family: var(--font-mono); font-feature-settings: "tnum"; }
  .obj-linked .unlink {
    background: transparent; border: 0;
    color: var(--fg-subtle); cursor: pointer;
    padding: 4px 6px; font-size: 11px;
  }
  .obj-linked .unlink:hover { color: var(--accent-2); }

  .avm-callout {
    display: none;
    margin-top: 10px;
    padding: 9px 12px;
    background: var(--accent-l);
    border: 1px solid color-mix(in oklab, var(--accent) 14%, transparent);
    border-radius: var(--radius-sm);
  }
  .avm-callout.show { display: block; }
  .avm-callout .lbl-c {
    font-size: 10px; color: var(--accent); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
  }
  .avm-callout .val-c {
    font-family: var(--font-mono); font-feature-settings: "tnum";
    font-size: 16px; font-weight: 700; color: var(--accent);
    margin-top: 1px;
  }
  .avm-callout .meta {
    font-size: 11px; color: var(--fg-muted);
    font-family: var(--font-mono); font-feature-settings: "tnum";
    margin-top: 1px;
  }

  /* Footer */
  .mf {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    background: var(--surface);
    flex: none;
  }
  .mf .hint {
    font-size: 11px; color: var(--fg-subtle);
    flex: 1;
    font-family: var(--font-mono);
    font-feature-settings: "tnum";
  }
  .mf .hint kbd {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--fg-muted);
  }
  .btn {
    height: 34px; padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    cursor: pointer;
    font-weight: 500; font-size: 13px;
    color: var(--fg);
    display: inline-flex; align-items: center; gap: 7px;
  }
  .btn:hover { background: var(--surface-2); }
  .btn.primary {
    background: var(--accent); color: var(--accent-ink);
    border-color: var(--accent);
    font-weight: 600;
  }
  .btn.primary:hover { background: color-mix(in oklab, var(--accent) 92%, #000); }
  .btn.primary:disabled, .btn:disabled {
    opacity: .55; cursor: not-allowed;
  }
  .spinner {
    width: 12px; height: 12px;
    border: 1.6px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  body[data-state="saving"] .mb,
  body[data-state="saving"] .mh .close { pointer-events: none; opacity: .6; }
  body[data-state="saving"] .btn:not(#savingBtn) { display: none; }
  body[data-state="saving"] #savingBtn { display: inline-flex; }
  #savingBtn { display: none; }

  /* Demo state pill (out-of-form) */
  .state-pill {
    position: fixed; left: 16px; bottom: 16px;
    z-index: 60;
    display: inline-flex; gap: 4px; padding: 4px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-1);
    font-size: 11px;
  }
  .state-pill .lbl {
    padding: 4px 8px;
    color: var(--fg-subtle);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    align-self: center;
  }
  .state-pill button {
    background: transparent; border: 0;
    padding: 5px 9px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--fg-muted);
    font-weight: 500;
  }
  .state-pill button:hover { background: var(--surface-2); color: var(--fg); }
  .state-pill button.active {
    background: var(--accent); color: var(--accent-ink);
  }

  /* Mobile */
  @media (max-width: 640px) {
    .form-scrim { padding: 0; align-items: stretch; }
    .modal {
      width: 100%; max-width: 100%; max-height: 100vh;
      border-radius: 0; border: 0;
    }
    .grid-2 { grid-template-columns: 1fr; }
    .state-pill { left: 8px; right: 8px; bottom: 8px; flex-wrap: wrap; }
  }

/* === 5. tagahoov BACK BUTTON (top-left of topbar, replaces brand) === */
.brand-back {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  border-right: 1px solid var(--line);
  margin-right: 4px;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius-sm);
  transition: background-color .12s;
}
.brand-back:hover { background: var(--surface-2); }
.brand-back .arrow {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
}
.brand-back .arrow svg { width: 14px; height: 14px; }
.brand-back .brand-mark { font-weight: 700; letter-spacing: -0.01em; font-size: 14px; color: var(--accent); padding-right: 8px; }
.brand-back:hover .arrow { color: var(--fg); }

/* "Tegevused täna" sidebar */
.layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 10px;
  height: calc(100vh - 49px);
}
.layout > .kanban-wrap {
  height: auto;
  padding: 14px 0 80px 18px;
  min-width: 0;
}
.activity-sidebar {
  border-left: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
  padding: 14px 16px 80px;
}
.activity-sidebar h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.activity-sidebar h3 + h3 { margin-top: 18px; }
.act-item {
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .12s;
}
.act-item:hover { border-color: var(--line-2); }
.act-item .ai-title {
  font-size: 12px; font-weight: 500; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.act-item .ai-step {
  font-size: 11px; color: var(--fg-muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.act-item.overdue { border-left: 3px solid var(--accent-2); }
.act-item.today   { border-left: 3px solid var(--amber); }
.act-empty {
  font-size: 11px; color: var(--fg-subtle); padding: 6px 10px; font-style: italic;
}

/* Hide sidebar on small screens — kanban swallows full width */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .activity-sidebar { display: none; }
}

/* Loading + empty state for the kanban */
.kanban-loading,
.kanban-empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--fg-subtle);
  height: 100%;
  font-style: italic;
}

/* When deal panel open, dim kanban slightly */
body.panel-open .kanban-wrap { opacity: 0.6; transition: opacity .2s; }

/* Toast — for save errors / success */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  z-index: 100; font-size: 12px;
  animation: toastIn .25s;
}
.toast.err { background: var(--accent-2); }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* === 6. SIDEBAR COLLAPSE + JÄRGMINE SAMM PARANDUSED (v2) === */

/* Sidebar header */
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.sidebar-head h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg);
}
.sidebar-toggle {
  background: none; border: 0; padding: 4px;
  cursor: pointer; color: var(--fg-subtle);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px;
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--fg); }
.sidebar-toggle svg { width: 12px; height: 12px; }

/* Sub-headers (Üle aja, Täna, Sel nädalal) */
.activity-sidebar h4 {
  margin: 14px 0 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.activity-sidebar h4:first-of-type { margin-top: 10px; }

/* Sidebar collapsed state */
.layout.sidebar-collapsed {
  grid-template-columns: 1fr;
}
.layout.sidebar-collapsed .activity-sidebar { display: none; }
.layout.sidebar-collapsed .sidebar-reopen { display: flex !important; }

/* Reopen button (when sidebar collapsed) */
.sidebar-reopen {
  position: fixed; top: 65px; right: 0;
  width: 24px; height: 60px;
  background: var(--surface);
  border: 1px solid var(--line); border-right: 0;
  border-radius: 6px 0 0 6px;
  cursor: pointer; color: var(--fg-muted);
  align-items: center; justify-content: center;
  z-index: 30;
}
.sidebar-reopen:hover { background: var(--surface-2); color: var(--fg); }
.sidebar-reopen svg { width: 12px; height: 12px; }

/* Next step: alati nähtav, default empty state */
.next-step { display: flex !important; }
.next-step[data-state="empty"] {
  background: var(--surface-2);
  border-style: dashed;
  border-color: var(--line);
}
.next-step[data-state="empty"] .ns-text {
  color: var(--fg-subtle);
  font-style: italic;
}
.next-step[data-state="empty"] .ns-when { display: none; }
.next-step[data-state="empty"] #nsDone { display: none; }
.next-step[data-state="empty"] .dot {
  background: transparent; border: 1.5px dashed var(--fg-subtle);
}

/* Inline edit form for next step */
.ns-edit-form {
  margin: 8px 16px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.ns-edit-form.open { display: block !important; }
.ns-edit-row {
  display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-bottom: 8px;
}
.ns-edit-row input {
  height: 28px; padding: 0 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font: inherit; color: var(--fg);
}
.ns-edit-row input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.ns-edit-form .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.ns-edit-form .row-actions button {
  height: 26px; padding: 0 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer; font: inherit;
}
.ns-edit-form .row-actions button.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}


/* === 7. PANEL: dünaamilised väljad (allikas/prioriteet popover, märkused, lingitud objekt) === */

/* Empty state for "Lingitud objekt" — looks like obj-link but clickable to open search */
.obj-link-empty {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit; color: inherit;
  transition: border-color .12s, background .12s;
}
.obj-link-empty:hover {
  border-color: var(--accent);
  background: var(--surface);
}
.obj-link-empty .thumb {
  width: 32px; height: 32px; border-radius: 4px;
  background: repeating-linear-gradient(135deg, var(--line) 0 4px, var(--surface-2) 4px 8px);
  border: 1px solid var(--line);
  flex: none;
}
.obj-link-empty .info { flex: 1; min-width: 0; }
.obj-link-empty .info .t { font-weight: 500; font-size: 12px; }
.obj-link-empty .info .s { font-size: 11px; color: var(--fg-subtle); margin-top: 2px; }

/* Inline-edit: select-style fields (allikas, prioriteet) */
.val-select {
  cursor: pointer;
  border: 1px dashed transparent;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 4px;
  position: relative;
}
.val-select:hover {
  border-color: var(--line-2);
  background: var(--surface);
}
.val-select.editing {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0;
  margin: 0;
}

/* Popover for select choices */
.val-popover {
  position: absolute;
  top: 100%; left: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  z-index: 60;
  min-width: 180px;
  padding: 4px;
}
.val-popover button {
  display: block; width: 100%;
  padding: 7px 10px;
  background: transparent; border: 0;
  text-align: left;
  font: inherit; color: var(--fg);
  border-radius: 4px;
  cursor: pointer;
}
.val-popover button:hover { background: var(--surface-2); }
.val-popover button.active { background: var(--accent); color: var(--accent-ink); }
.val-popover button.clear {
  border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px;
  color: var(--fg-subtle); font-size: 11px;
}
.val-popover button .pdot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.val-popover button[data-prio="kuum"] .pdot { background: var(--accent-2); }
.val-popover button[data-prio="soe"]  .pdot { background: var(--amber); }
.val-popover button[data-prio="kulm"] .pdot { background: var(--fg-subtle); }

/* Textarea inline edit (märkused) */
.val-textarea {
  cursor: pointer;
  white-space: pre-wrap;
  min-height: 22px;
  padding: 6px 8px;
  border: 1px dashed transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg);
}
.val-textarea:hover {
  border-color: var(--line-2);
  background: var(--surface);
}
.val-textarea.empty {
  color: var(--fg-subtle);
  font-style: italic;
}
.val-textarea.editing {
  padding: 0;
  border: none;
  background: transparent;
  cursor: text;
}
.val-textarea textarea {
  width: 100%;
  min-height: 80px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font: inherit;
  color: inherit;
  resize: vertical;
}
