/* Ethertronix Hub design layer (screen only). Loaded after styles-v1.9.14.css.
   Direction: calm, light-first workspace (Stripe / Linear / Plane): neutral surfaces, Inter at readable sizes,
   real tables, colour used for meaning. The company colour (--brand) is the only accent.
   Printed/PDF documents keep their own .print-* styles and are not touched here. */

:root, :root[data-theme="light"] {
  color-scheme: light;
  font-family: Inter, "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --surface-3: #f0f1f3;
  --text: #15181c;
  --text-2: #464c55;
  --muted: #6b727c;
  --border: #e7e8eb;
  --border-strong: #d6d8dc;
  --sidebar: #f7f7f8;
  --sidebar-2: #efeff1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-pop: 0 8px 28px rgba(16, 24, 40, .12), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --ok-fg: #13774f; --ok-bg: #e8f6ef;
  --info-fg: #1f5aa6; --info-bg: #eaf1fd;
  --warn-fg: #8a5300; --warn-bg: #fff3df;
  --danger-fg: #b3361f; --danger-bg: #fdecea;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111316;
  --surface: #16191d;
  --surface-2: #1b1e23;
  --surface-3: #23272d;
  --text: #eceef1;
  --text-2: #b6bcc4;
  --muted: #8b929b;
  --border: #272b31;
  --border-strong: #353a41;
  --sidebar: #0d0f11;
  --sidebar-2: #16191d;
  --shadow: none;
  --shadow-pop: 0 10px 32px rgba(0, 0, 0, .5);
  --ok-fg: #7fd8b2; --ok-bg: #133126;
  --info-fg: #9cc2ff; --info-bg: #172840;
  --warn-fg: #ffcf85; --warn-bg: #3a2c12;
  --danger-fg: #ffab9c; --danger-bg: #3e1f1a;
}

@media screen {
  body { background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, sans-serif; font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01"; }
  button, input, select, textarea { font-family: inherit; }
  :focus-visible { outline: 2px solid rgba(var(--brand-rgb), .55); outline-offset: 2px; }

  /* ---------- Shell ---------- */
  .app-shell { background: var(--bg); }
  .sidebar { background: var(--sidebar); border-right: 1px solid var(--border); box-shadow: none; padding: 12px 10px; gap: 6px; }
  .sidebar::before, .sidebar::after { display: none !important; }
  .sidebar-company { background: transparent; border: 1px solid transparent; box-shadow: none; border-radius: 8px; padding: 8px; }
  .sidebar-company:hover { background: var(--sidebar-2); }
  .sidebar-company b { font-size: 14px; color: var(--text); }
  .sidebar-company span { font-size: 12px; color: var(--muted); }
  .sidebar nav { display: grid; gap: 14px; margin-top: 6px; }
  .nav-group { display: grid; gap: 1px; }
  .nav-section { font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 0 10px 4px; letter-spacing: .01em; }
  .sidebar nav button, .sidebar-bottom > button {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 6px 10px;
    border: 0; border-radius: 7px; background: transparent; box-shadow: none;
    color: var(--text-2); font-size: 14px; font-weight: 500; text-align: left;
  }
  .sidebar nav button svg, .sidebar-bottom > button svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
  .sidebar nav button:hover, .sidebar-bottom > button:hover { background: var(--sidebar-2); color: var(--text); }
  .sidebar nav button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border), var(--shadow); }
  :root[data-theme="dark"] .sidebar nav button.active { background: var(--surface-3); box-shadow: none; }
  .sidebar nav button.active svg { color: var(--brand); }
  .sidebar-bottom { border-top: 1px solid var(--border); padding-top: 8px; gap: 1px; }
  .sync-chip { font-size: 12px; color: var(--muted); padding: 6px 10px; background: transparent; border: 0; }
  .sync-chip.saved { color: var(--muted); }
  .sync-chip.error, .sync-chip.schema-missing { color: var(--danger-fg); background: var(--danger-bg); border-radius: 7px; }

  .new-menu { position: relative; padding: 2px 0 4px; }
  .new-button {
    display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 36px;
    border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    font-size: 14px; font-weight: 600; box-shadow: var(--shadow); cursor: pointer;
  }
  .new-button:hover { border-color: var(--brand); }
  .new-button svg { width: 16px; height: 16px; color: var(--brand); }
  .new-popover {
    position: absolute; z-index: 40; top: 42px; left: 0; right: 0; padding: 6px; display: grid; gap: 1px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-pop);
  }
  .new-popover button { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font-size: 14px; text-align: left; cursor: pointer; }
  .new-popover button:hover { background: var(--surface-2); }
  .new-popover svg { width: 16px; height: 16px; color: var(--muted); }

  .main-shell { background: var(--bg); }
  .topbar { background: var(--bg); border-bottom: 1px solid var(--border); backdrop-filter: none; height: 52px; padding: 0 28px; }
  .breadcrumbs { font-size: 13px; color: var(--muted); }
  .breadcrumbs strong { color: var(--text); font-weight: 600; }
  .company-pill { font-size: 13px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); box-shadow: none; }
  main.content { padding: 28px 32px 48px; max-width: 1240px; }

  /* ---------- Page head ---------- */
  .page-head { margin-bottom: 18px; align-items: flex-end; }
  .page-head h1 { font-size: 24px; line-height: 1.25; letter-spacing: -0.02em; font-weight: 650; margin: 0; }
  .page-head p { font-size: 14px; color: var(--muted); margin: 4px 0 0; }
  .eyebrow { display: none; }

  /* ---------- Buttons ---------- */
  .button { height: 36px; padding: 0 14px; border-radius: 8px; font-size: 14px; font-weight: 600; gap: 7px; box-shadow: var(--shadow); transform: none !important; }
  .button svg { width: 16px; height: 16px; }
  .button.primary { background: var(--text); border-color: var(--text); color: var(--bg); box-shadow: var(--shadow); filter: none; }
  .button.primary:hover { background: #2c3138; border-color: #2c3138; }
  :root[data-theme="dark"] .button.primary:hover { background: #ffffff; }
  .button.ghost { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); }
  .button.ghost:hover { background: var(--surface-2); }
  .icon-button { border-radius: 7px; }
  .link-button { border: 0; background: none; color: var(--text-2); font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px 0; }
  .link-button:hover { color: var(--text); text-decoration: underline; }

  /* ---------- Toolbar, search, filter tabs (underline style) ---------- */
  .toolbar { gap: 14px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
  .search-box { height: 36px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); box-shadow: none; min-width: 260px; }
  .search-box input { font-size: 14px; }
  .search-box svg { width: 16px; color: var(--muted); }
  .toolbar-count { font-size: 13px; color: var(--muted); }
  .status-tabs { gap: 18px; border-bottom: 1px solid var(--border); padding-bottom: 0; flex: 1 1 auto; }
  .status-tabs button {
    border: 0; border-radius: 0; background: transparent; color: var(--muted);
    font-size: 14px; font-weight: 500; padding: 8px 0 10px; margin-bottom: -1px; border-bottom: 2px solid transparent;
  }
  .status-tabs button:hover { color: var(--text); }
  .status-tabs button.active { color: var(--text); font-weight: 600; background: transparent; border-bottom-color: var(--text); }
  .tab-count { font-size: 12px; background: var(--surface-3); color: var(--muted); }
  .status-tabs button.active .tab-count { background: var(--text); color: var(--bg); }

  /* ---------- Panels & tables ---------- */
  .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
  .document-row {
    grid-template-columns: 32px minmax(220px, 1.6fr) minmax(110px, .7fr) 130px minmax(120px, .7fr) 96px;
    padding: 11px 16px; gap: 14px; border-bottom: 1px solid var(--border); transition: background .12s;
  }
  .document-row:last-child { border-bottom: 0; }
  .document-row:hover { background: var(--surface-2); }
  .document-row.static:hover { background: transparent; }
  .document-row.table-head { padding-top: 9px; padding-bottom: 9px; background: var(--surface-2); cursor: default; font-size: 12.5px; font-weight: 600; color: var(--muted); }
  .document-row.table-head:hover { background: var(--surface-2); }
  .document-row.table-head .num { text-align: right; }
  .doc-icon { width: 30px; height: 30px; border-radius: 7px; background: var(--surface-3); color: var(--text-2); }
  .doc-primary b { font-size: 14px; font-weight: 600; }
  .doc-primary span, .doc-date span { font-size: 13px; color: var(--muted); }
  .doc-date b { font-size: 14px; font-weight: 500; }
  .doc-date span { display: none; }
  .doc-total { font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
  .row-actions { justify-content: flex-end; opacity: .55; transition: opacity .12s; }
  .document-row:hover .row-actions, .customer-card:hover .row-actions { opacity: 1; }
  .row-actions button { width: 30px; height: 30px; border-radius: 7px; background: transparent; border: 1px solid transparent; color: var(--muted); }
  .row-actions button:hover { background: var(--surface-3); color: var(--text); }
  .row-actions button.danger:hover { color: var(--danger-fg); background: var(--danger-bg); }
  .row-actions svg { width: 16px; height: 16px; }

  /* Status pills: one shape, colour carries meaning. */
  .status, .priority {
    display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px;
    font-size: 12.5px; font-weight: 600; background: var(--surface-3); color: var(--text-2);
  }
  .status::before, .priority::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
  .status-paid, .status-accepted, .ticket-status-resolved { color: var(--ok-fg) !important; background: var(--ok-bg) !important; }
  .status-sent, .ticket-status-open { color: var(--info-fg) !important; background: var(--info-bg) !important; }
  .status-overdue, .status-declined, .status-cancelled, .priority-urgent { color: var(--danger-fg) !important; background: var(--danger-bg) !important; }
  .ticket-status-waiting-on-client, .priority-high, .status-expired { color: var(--warn-fg) !important; background: var(--warn-bg) !important; }

  /* ---------- Customers ---------- */
  .customer-grid { gap: 12px; }
  .customer-card { border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); padding: 14px; }
  .customer-card:hover { border-color: var(--border-strong); }
  .customer-avatar { border-radius: 8px; background: var(--surface-3); color: var(--text-2); font-size: 13px; font-weight: 700; }
  .customer-copy h3 { font-size: 15px; }
  .customer-copy p, .customer-copy span { font-size: 13px; color: var(--muted); }

  /* ---------- Forms & modals ---------- */
  .field-label, .field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
  .field input, .field select, .field textarea, .bom-line input, .bom-line select, .reply-box textarea, .portal-picker select {
    font-size: 14px; border-radius: 8px; border-color: var(--border-strong); background-color: var(--surface);
  }
  .field input, .field select, .bom-line input, .bom-line select, .portal-picker select { height: 38px; }
  .modal-backdrop { background: rgba(15, 18, 22, .45); backdrop-filter: blur(2px); }
  .modal { border-radius: 14px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-pop); }
  .modal-head h2 { font-size: 18px; letter-spacing: -0.01em; }
  .modal-head p { font-size: 13.5px; color: var(--muted); }
  .modal-actions { border-top: 1px solid var(--border); padding-top: 14px; }

  /* ---------- Empty states ---------- */
  .empty-state { padding: 44px 20px; }
  .empty-state h3 { font-size: 16px; }
  .empty-state p { font-size: 14px; color: var(--muted); }
  .empty-icon { background: var(--surface-3); color: var(--text-2); border-radius: 10px; box-shadow: none; }

  /* ---------- Home ---------- */
  .home { display: grid; gap: 20px; }
  .home-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
  .home-date { margin: 0; color: var(--muted); font-size: 13.5px; }
  .home-head h1 { margin: 2px 0 0; font-size: 26px; letter-spacing: -0.02em; font-weight: 650; }
  .home-actions { display: flex; gap: 8px; }
  .home-money { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
  .home-money > div { padding: 16px 18px; border-left: 1px solid var(--border); display: grid; gap: 2px; }
  .home-money > div:first-child { border-left: 0; }
  .home-money span { font-size: 13px; color: var(--muted); font-weight: 500; }
  .home-money b { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
  .home-money small { font-size: 13px; color: var(--muted); }
  .home-money .is-danger b { color: var(--danger-fg); }
  .section-title { font-size: 15px; font-weight: 650; margin: 0 0 10px; }
  .section-row { display: flex; justify-content: space-between; align-items: baseline; }
  .flow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); margin-top: -10px; }
  .flow-stage { position: relative; display: grid; gap: 2px; text-align: left; padding: 14px 18px; border: 0; border-left: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; }
  .flow-stage:first-child { border-left: 0; }
  .flow-stage:hover { background: var(--surface-2); }
  .flow-stage::after { content: ""; position: absolute; right: -7px; top: 50%; width: 12px; height: 12px; transform: translateY(-50%) rotate(45deg); background: var(--surface); border-top: 1px solid var(--border); border-right: 1px solid var(--border); z-index: 1; }
  .flow-stage:last-child::after { display: none; }
  .flow-stage:hover::after { background: var(--surface-2); }
  .flow-label { font-size: 13px; color: var(--muted); font-weight: 500; }
  .flow-count { font-size: 28px; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
  .flow-caption { font-size: 13.5px; }
  .flow-sub { font-size: 12.5px; color: var(--muted); }
  .home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 20px; align-items: start; }
  .attention { display: grid; overflow: hidden; }
  .attention-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 14px; border: 0; border-top: 1px solid var(--border); background: transparent; text-align: left; color: var(--text); cursor: pointer; font-size: 14px; }
  .attention-row:first-child { border-top: 0; }
  .attention-row:hover { background: var(--surface-2); }
  .attention-tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
  .attention-tag.danger { color: var(--danger-fg); background: var(--danger-bg); }
  .attention-tag.warn { color: var(--warn-fg); background: var(--warn-bg); }
  .attention-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .attention-amount { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
  .attention-empty { margin: 0; padding: 18px 14px; color: var(--muted); }
  .document-list.compact .document-row { grid-template-columns: 30px minmax(0, 1fr) 92px 92px 110px; }
  .doc-date b { white-space: nowrap; }
  .document-list.compact .doc-primary span, .document-list.compact .doc-primary b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .doc-primary { min-width: 0; }
  .document-list.compact .row-actions { display: none; }

  /* ---------- Tickets (Linear-style thread + properties) ---------- */
  .ticket-head { align-items: center; }
  .ticket-title h1 { font-size: 22px; letter-spacing: -0.02em; }
  .ticket-title .eyebrow { display: block; color: var(--muted); font-size: 12.5px; letter-spacing: 0; text-transform: none; margin: 0 0 2px; }
  .ticket-layout { grid-template-columns: minmax(0, 1fr) 280px; }
  .message { border-radius: 10px; }
  .message header b { font-size: 14px; }
  .message p { font-size: 14px; line-height: 1.6; }
  .ticket-side { position: sticky; top: 72px; }

  /* ---------- Responsive ---------- */
  @media (max-width: 980px) {
    .home-grid { grid-template-columns: 1fr; }
    .flow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .flow-stage:nth-child(2)::after { display: none; }
    .flow-stage:nth-child(n+3) { border-top: 1px solid var(--border); }
    .flow-stage:nth-child(3) { border-left: 0; }
  }
  @media (max-width: 720px) {
    main.content { padding: 18px 16px 40px; }
    .home-money { grid-template-columns: 1fr; }
    .home-money > div { border-left: 0; border-top: 1px solid var(--border); }
    .home-money > div:first-child { border-top: 0; }
    .document-row { grid-template-columns: 30px minmax(0, 1fr) auto; }
    .document-row .doc-date, .document-row .row-actions, .document-row.table-head { display: none; }
    .search-box { min-width: 0; flex: 1 1 100%; }
  }
}

@media screen {
  /* ---------- Workspace chooser (first visit / switching) ---------- */
  .chooser-backdrop { background: rgba(15, 18, 22, .5); backdrop-filter: blur(3px); }
  .chooser { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-pop); padding: 32px; max-width: 720px; }
  .chooser::before, .chooser::after { display: none !important; }
  .chooser-kicker { display: none; }
  .chooser h1 { font-size: 22px; letter-spacing: -0.02em; color: var(--text); }
  .chooser p { font-size: 14px; color: var(--muted); }
  .company-choice { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: none; padding: 14px; }
  .company-choice:hover { border-color: var(--choice); background: var(--surface-2); }
  .company-choice.selected { border-color: var(--choice); box-shadow: 0 0 0 3px rgba(var(--choice-rgb), .15); }
  .company-choice h2 { font-size: 16px; color: var(--text); }
  .company-choice span { font-size: 13px; color: var(--muted); }
  .choice-logo { background: #0f1317; border-radius: 9px; }
  .choice-arrow { background: var(--surface-3) !important; color: var(--text) !important; box-shadow: none !important; border-radius: 8px; }
}

@media screen {
  /* ---------- Document editor: form left, live preview right (Contra / Acctual pattern) ---------- */
  .editor-toolbar { min-height: 56px; padding: 10px 24px; background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 52px; z-index: 20; }
  .editor-toolbar > div { gap: 8px; }
  .editor-title span { font-size: 12px; color: var(--muted); }
  .editor-title b { font-size: 15px; }
  .save-state { font-size: 13px; color: var(--muted); margin-right: 4px; }
  .save-state.done { color: var(--ok-fg); }
  .receipt-button, .convert-button { background: var(--surface) !important; border: 1px solid var(--border-strong) !important; color: var(--text) !important; box-shadow: var(--shadow) !important; }
  .receipt-button svg, .convert-button svg { color: var(--ok-fg); }
  .editor-panel { background: var(--bg); border-right: 1px solid var(--border); }
  .editor-section { padding: 20px 22px; }
  .section-label, .editor-section > .section-label { color: var(--text) !important; font-size: 15px !important; font-weight: 650 !important; letter-spacing: 0 !important; text-transform: none !important; margin-bottom: 12px !important; }
  .inline-tip { font-size: 13px; background: var(--surface-2); border-color: var(--border); color: var(--text-2); }
  /* Preview column: quiet canvas, A4 sheet scaled to fit; PDF export (.pdf-exporting) renders at full size. */
  .editor-layout { background: var(--surface-2); }
  .print-sheet:not(.pdf-exporting) { box-shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 12px 32px rgba(16, 24, 40, .08); border-radius: 4px; }
}
@media screen and (min-width: 1000px) {
  .editor-layout { display: grid !important; grid-template-columns: minmax(380px, 480px) minmax(0, 1fr) !important; overflow: visible; }
  .editor-panel { min-height: calc(100vh - 108px); }
  .print-sheet:not(.pdf-exporting) { position: sticky !important; top: 128px !important; margin: 24px auto !important; zoom: .5; }
}
@media screen and (min-width: 1300px) { .print-sheet:not(.pdf-exporting) { zoom: .6; } }
@media screen and (min-width: 1550px) { .print-sheet:not(.pdf-exporting) { zoom: .72; } }
@media screen and (min-width: 1800px) { .print-sheet:not(.pdf-exporting) { zoom: .85; } }
@media screen { .editor-layout { overflow-x: hidden; } }

@media screen {
  /* ---------- Document form (editor.js) ---------- */
  .df { display: grid; }
  .df-section { padding: 20px 22px; border-bottom: 1px solid var(--border); display: grid; gap: 12px; }
  .df-section h3 { margin: 0; font-size: 15px; font-weight: 650; }
  .df-section-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
  .df-section-head small { color: var(--muted); font-size: 13px; }
  .df label { display: grid; gap: 6px; }
  .df-label { display: flex; align-items: baseline; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
  .df-label small { font-weight: 400; color: var(--muted); font-size: 12px; }
  .df input, .df select, .df textarea {
    width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 8px;
    background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit;
  }
  .df textarea { height: auto; padding: 9px 11px; resize: vertical; line-height: 1.5; }
  .df select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b929b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 14px; }
  .df input:focus, .df select:focus, .df textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .14); }
  .df input[type="number"] { font-variant-numeric: tabular-nums; }
  .df-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .df-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .df-row { display: flex; gap: 8px; align-items: center; }
  .df-row > input, .df-row > select { flex: 1 1 auto; min-width: 0; }
  .df-num { text-align: right; font-variant-numeric: tabular-nums; }
  .df-muted { color: var(--muted); }
  .df-link { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 4px 0; color: var(--text-2); font-size: 14px; font-weight: 600; cursor: pointer; justify-self: start; }
  .df-link:hover { color: var(--text); }
  .df-link svg { width: 15px; height: 15px; }
  .df-icon { display: inline-grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; flex: none; }
  .df-icon:hover { background: var(--surface-3); color: var(--text); }
  .df-icon.danger:hover { background: var(--danger-bg); color: var(--danger-fg); }
  .df-icon svg { width: 16px; height: 16px; }
  .df-explain { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }
  .df-explain.bad { color: var(--danger-fg); }
  .df-empty { margin: 0; padding: 18px; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 10px; }

  .df-banners { padding: 14px 22px 0; display: grid; gap: 8px; }
  .df-banner { margin: 0; display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13.5px; color: var(--text-2); }
  .df-banner.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok-fg); }
  .df-banner svg { width: 16px; height: 16px; }
  .df-banner .df-link { margin-left: auto; color: inherit; }

  /* Segmented controls and plan cards */
  .df-seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 8px; background: var(--surface-3); }
  .df-seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap; }
  .df-seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }
  .df-plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
  .df-plans button { display: grid; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; }
  .df-plans button b { font-size: 14px; }
  .df-plans button span { font-size: 12.5px; color: var(--muted); }
  .df-plans button.on { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .14); }
  .df-presets { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
  .df-presets button { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); border-radius: 999px; padding: 3px 10px; font-size: 13px; cursor: pointer; }
  .df-presets button:hover { border-color: var(--text-2); }
  .df-presets button.on { background: var(--text); border-color: var(--text); color: var(--bg); }

  /* Customer picker */
  .df-combo { position: relative; }
  .df-combo-input { display: flex !important; align-items: center; gap: 8px; height: 40px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); }
  .df-combo-input:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .14); }
  .df-combo-input svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
  .df .df-combo-input input { border: 0; box-shadow: none; padding: 0; height: 100%; background: transparent; }
  .df-pop { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0; min-width: 240px; max-height: 320px; overflow: auto; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-pop); display: grid; gap: 1px; }
  .df-pop-title { padding: 6px 8px 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
  .df-pop-row, .df-pop-create { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 8px; border: 0; border-radius: 7px; background: transparent; color: var(--text); text-align: left; cursor: pointer; font-size: 14px; }
  .df-pop-row { justify-content: flex-start; }
  .df-pop-row > span:not(.df-avatar):not(.df-num) { display: grid; flex: 1; min-width: 0; }
  .df-pop-row > .df-num { flex: none; color: var(--text-2); font-size: 13px; }
  .df-pop-row small { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .df-pop-row:hover, .df-pop-create:hover { background: var(--surface-2); }
  .df-pop-create { justify-content: flex-start; color: var(--brand); font-weight: 600; border-bottom: 1px solid var(--border); border-radius: 7px 7px 0 0; margin-bottom: 2px; }
  .df-pop-create svg { width: 16px; height: 16px; }
  .df-pop-empty { margin: 0; padding: 10px 8px; color: var(--muted); font-size: 13px; }
  .df-avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: rgba(var(--brand-rgb), .12); color: var(--brand); font-weight: 700; font-size: 13px; flex: none; }
  .df-avatar.sm { width: 28px; height: 28px; border-radius: 7px; font-size: 11.5px; }
  .df-customer-card { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
  .df-customer-copy { display: grid; gap: 1px; flex: 1; min-width: 0; font-size: 13.5px; color: var(--text-2); }
  .df-customer-copy b { font-size: 14.5px; color: var(--text); }

  /* Items table */
  .df-table { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
  .df-tr { display: grid; grid-template-columns: minmax(0, 1fr) 56px 84px 92px 64px; gap: 8px; align-items: start; padding: 8px 8px 8px 10px; border-top: 1px solid var(--border); }
  .df-tr:first-child { border-top: 0; }
  .df-th { align-items: center; padding-top: 8px; padding-bottom: 8px; background: var(--surface-2); border-radius: 10px 10px 0 0; font-size: 12.5px; font-weight: 600; color: var(--muted); }
  .df-tr input { height: 36px; padding: 0 8px; }
  .df-amount { padding-top: 9px; font-weight: 600; font-size: 14px; }
  .df-row-actions { display: flex; justify-content: flex-end; padding-top: 3px; }
  .df-item-cell { display: grid; gap: 4px; min-width: 0; }
  .df-item-name { position: relative; }
  .df-item-name .df-pop { min-width: 340px; right: auto; }
  .df-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; border: 0; background: none; padding: 0; text-align: left; cursor: pointer; min-width: 0; }
  .df-tag { font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
  .df-tag.rec { background: var(--info-bg); color: var(--info-fg); }
  .df-desc { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .df-charge { width: 100%; grid-template-columns: minmax(0, 1fr) 110px; border-left: 0; border-right: 0; border-bottom: 0; background: transparent; text-align: left; color: var(--text); cursor: pointer; font-size: 14px; padding: 10px 12px; }
  .df-charge:hover { background: var(--surface-2); }
  .df-charge small { display: block; color: var(--muted); font-size: 12.5px; }
  .df-add-row { display: flex; flex-wrap: wrap; gap: 8px; }
  .df-add { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px dashed var(--border-strong); border-radius: 8px; background: transparent; color: var(--text); font-size: 13.5px; font-weight: 600; cursor: pointer; justify-self: start; }
  .df-add:hover { border-style: solid; background: var(--surface-2); }
  .df-add svg { width: 15px; height: 15px; }
  .df-bom { position: relative; }
  .df-bom .df-pop { min-width: 260px; right: auto; }

  /* Summary */
  .df-summary { gap: 8px; background: var(--surface-2); }
  .df-summary > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; color: var(--text-2); }
  .df-discount label { display: flex !important; align-items: baseline; gap: 6px; }
  .df-discount label small { color: var(--muted); font-size: 12px; }
  .df-discount input { width: 120px; height: 34px; text-align: right; }
  .df-total { padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--border-strong); color: var(--text) !important; font-size: 17px !important; font-weight: 700; }
  .df-then { font-size: 13.5px !important; color: var(--muted) !important; }

  /* Side panel for line details */
  .df-drawer-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(15, 18, 22, .32); display: flex; justify-content: flex-end; animation: df-fade .12s ease-out; }
  .df-drawer { width: min(520px, 100vw); height: 100%; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-pop); display: grid; grid-template-rows: auto 1fr auto; animation: df-slide .16s ease-out; }
  .df-drawer header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
  .df-drawer header h3 { margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .df-drawer-body { overflow: auto; padding: 18px 20px; display: grid; gap: 20px; align-content: start; }
  .df-drawer-body section { display: grid; gap: 8px; }
  .df-drawer footer { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }
  .df-drawer-total { margin-left: auto; display: grid; text-align: right; }
  .df-drawer-total span { font-size: 12.5px; color: var(--muted); }
  .df-drawer-total b { font-size: 16px; font-variant-numeric: tabular-nums; }
  .df-danger { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--danger-fg); font-weight: 600; font-size: 13.5px; cursor: pointer; padding: 6px 0; }
  .df-danger svg { width: 15px; height: 15px; }
  @keyframes df-fade { from { opacity: 0; } }
  @keyframes df-slide { from { transform: translateX(24px); opacity: .6; } }
  @media (prefers-reduced-motion: reduce) { .df-drawer, .df-drawer-backdrop { animation: none; } }
}
@media screen and (min-width: 1000px) {
  .editor-layout { grid-template-columns: minmax(470px, 560px) minmax(0, 1fr) !important; }
}
@media screen and (max-width: 560px) {
  .df-grid2, .df-grid3 { grid-template-columns: 1fr; }
  .df-tr { grid-template-columns: minmax(0, 1fr) 56px 80px; }
  .df-tr .df-amount, .df-th span:nth-child(4), .df-th span:nth-child(5) { display: none; }
  .df-row-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media screen {
  /* ---------- Company switcher ---------- */
  .co-switcher { position: relative; }
  .co-current { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: 9px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
  .co-current:hover, .co-current[aria-expanded="true"] { background: var(--sidebar-2); }
  .co-name { display: grid; min-width: 0; flex: 1; line-height: 1.25; }
  .co-name b { font-size: 14.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .co-name small { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .co-chevron { color: var(--muted); flex: none; }
  .co-mark { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 9px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
  .co-mark.sm { width: 28px; height: 28px; border-radius: 7px; }
  .co-mark img { max-width: 72%; max-height: 72%; width: auto; height: auto; }
  .co-mark.ethertronix { background: #0b141d; }
  .co-mark.safecyber { background: #ffffff; }
  :root[data-theme="dark"] .co-mark { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08); }
  .co-menu { position: absolute; z-index: 50; top: calc(100% + 6px); left: 0; width: max(100%, 250px); padding: 6px; display: grid; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-pop); }
  .co-menu-title { padding: 6px 8px 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
  .co-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
  .co-menu button:hover { background: var(--surface-2); }
  .co-menu button.on { background: var(--surface-2); }
  .co-check { width: 16px; height: 16px; color: var(--brand); flex: none; }
  .co-menu kbd { font: 600 11px Inter, system-ui, sans-serif; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
  .top-actions:empty { display: none; }
}

@media screen {
  /* ---------- Roles & approvals ---------- */
  fieldset.df { border: 0; margin: 0; padding: 0; min-width: 0; }
  fieldset.df:disabled .df-add, fieldset.df:disabled .df-link, fieldset.df:disabled .df-row-actions { display: none; }
  .df-approval { margin: 14px 22px 0; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 14px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-size: 14px; color: var(--text-2); }
  .df-approval > span { display: flex; align-items: center; gap: 8px; flex: 1 1 240px; }
  .df-approval svg { width: 16px; height: 16px; flex: none; }
  .df-approval.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok-fg); }
  .df-approval.need, .df-approval.wait { background: var(--warn-bg); border-color: transparent; color: var(--warn-fg); }
  .df-approval.bad { background: var(--danger-bg); border-color: transparent; color: var(--danger-fg); }
  .df-approval .button { height: 32px; }
  .df-approval .df-row { flex-wrap: wrap; }
  .df-reject input { min-width: 220px; height: 32px; }
  .df-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; animation: df-pulse 1.6s ease-in-out infinite; }
  @keyframes df-pulse { 50% { opacity: .35; } }
  @media (prefers-reduced-motion: reduce) { .df-dot { animation: none; } }
  .nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: grid; place-items: center; background: var(--warn-bg); color: var(--warn-fg); font-size: 12px; font-weight: 700; }
  .approval-row .row-actions .approve { color: var(--ok-fg); }
  .approval-row .row-actions .approve:hover { background: var(--ok-bg); }
  .team-row { grid-template-columns: 36px minmax(0, 1fr) 170px 130px 48px; }
  .team-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: rgba(var(--brand-rgb), .12); color: var(--brand); font-size: 12px; font-weight: 700; }
  .team-seen { font-size: 13px; color: var(--muted); }
  .team-role { height: 34px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); padding: 0 10px; font-size: 13.5px; }
  .team-pad { padding: 16px; }
  .role-legend { margin-top: 14px; display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
  .role-legend b { color: var(--text-2); }
  .temp-cred p { display: grid; gap: 2px; margin: 0 0 12px; }
  .temp-cred span { font-size: 12.5px; color: var(--muted); }
  .temp-cred code { font-size: 16px; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; letter-spacing: .02em; user-select: all; }
  @media (max-width: 720px) { .team-row { grid-template-columns: 36px minmax(0, 1fr) 110px; } .team-seen, .team-row .row-actions { display: none; } }
}

@media screen {
  /* Sidebar: the nav list scrolls on short screens; switcher, New and the bottom controls stay put. */
  .sidebar { display: flex !important; flex-direction: column; overflow: hidden; }  /* keeps the original fixed, full-height position */
  .sidebar nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 8px; scrollbar-width: thin; }
  .sidebar-bottom { flex: none; }
  .sidebar nav { gap: 10px; }
  .sidebar nav button, .sidebar-bottom > button { min-height: 32px; }
}
@media screen { .df-approval > span { display: block; } .df-approval > span > svg { display: inline-block; vertical-align: -3px; margin-right: 6px; } }
