/* ================================================================
   NexusDesk 3.11 — UI polish (desktop) and mobile app experience.
   Loaded last so it can refine earlier layers without !important.
   ================================================================ */

/* ---------- Desktop and shared polish ---------- */
.panel-body.priority-breakdown { padding: 6px 22px 22px; }
body.light .pbar { background: #e6ebf5; }
body.light .prio-head { color: #5d6c86; }
body.light .ticket-table td { color: #4f5f7a; }
body.light .ticket-no { color: #6d7a93; }
.ticket-no { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; }
.ticket-table td.is-unassigned { color: var(--faint); font-style: italic; }
.ticket-table tbody tr:focus-within { background: var(--surface2); }
.ticket-table tbody tr.is-selected { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.breadcrumb .crumb-page { font-weight: 650; color: var(--text); }
.filter-toggle { display: none; }
.filter-count {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--primary); color: #fff; font-size: 11px; margin-left: 4px;
}
.toast { cursor: pointer; animation: nd-toast-in .22s ease-out; }
@keyframes nd-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
body.light .toast { background: #17243b; border-color: #17243b; color: #f2f5ff; }
body.light .toast.error { background: #fff1f3; border-color: #f2b8c1; color: #9b1c31; }
body.light .toast.success { background: #ecfbf5; border-color: #a7e4cd; color: #0d6b4c; }
:is(.btn, .icon-btn, .nav-link, .mobile-tab, .filter-select, input, select, textarea):focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Phones ---------- */
@media (max-width: 670px) {
  /* Top bar: show the page you're on instead of a truncated "Workspace…" */
  .topbar .breadcrumb { max-width: none; flex: 1; min-width: 0; font-size: 17px; }
  .topbar .breadcrumb .crumb-root { display: none; }
  .topbar .breadcrumb .crumb-page { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -.2px; }
  .topbar .top-left { flex: 1; }

  /* Toasts sit above the bottom tab bar, full width, easy to dismiss */
  #toast-zone { left: 12px; right: 12px; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); align-items: stretch; }
  .toast { max-width: none; font-size: 14px; padding: 13px 16px; border-radius: 14px; }

  /* Ticket filters collapse behind one button */
  .toolbar { flex-wrap: wrap; }
  .toolbar .search-input { flex: 1 1 0; flex-basis: 0; width: auto; }
  .filter-toggle { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 16px; flex: 0 0 auto; }
  #ticket-toolbar .filter-select { display: none; }
  #ticket-toolbar.filters-open .filter-select { display: block; }

  /* Ticket queue as cards instead of a squeezed table */
  .desktop-hint { display: none; }
  .ticket-table { min-width: 0; display: block; }
  .ticket-table thead { display: none; }
  .ticket-table tbody { display: grid; gap: 0; }
  .ticket-table tbody tr {
    display: grid; grid-template-columns: auto auto 1fr auto; grid-template-areas:
      "sel title title title"
      "sel status prio updated"
      "sel assignee assignee assignee";
    column-gap: 10px; row-gap: 8px; padding: 14px 16px; border-top: 1px solid var(--line2);
    border-left: 3px solid transparent;
  }
  .ticket-table:not(.selecting) tbody tr {
    grid-template-columns: auto auto 1fr; grid-template-areas:
      "title title title"
      "status prio updated"
      "assignee assignee assignee";
  }
  .ticket-table tbody tr.prio-row-urgent { border-left-color: #ff7486; }
  .ticket-table tbody tr.prio-row-high { border-left-color: #ffb675; }
  .ticket-table td, .ticket-table td:nth-child(n+4) { display: block; padding: 0; border: 0; font-size: 13px; min-width: 0; }
  .ticket-table td.c-sel { grid-area: sel; display: none; align-self: center; }
  .ticket-table.selecting td.c-sel { display: block; }
  .ticket-table.selecting td.c-sel input { width: 22px; height: 22px; }
  .ticket-table td.c-title { grid-area: title; }
  .ticket-table .ticket-title { white-space: normal; max-width: none; font-size: 15px; line-height: 1.35; }
  .ticket-table .ticket-no { font-size: 12px; }
  .ticket-table td.c-status { grid-area: status; align-self: center; }
  .ticket-table td.c-prio { grid-area: prio; align-self: center; }
  .ticket-table td.c-cat { display: none; }
  .ticket-table td.c-updated { grid-area: updated; align-self: center; text-align: right; color: var(--faint); font-size: 12px; }
  .ticket-table td.c-assignee { grid-area: assignee; font-size: 12px; color: var(--muted); }
  .ticket-table td.c-assignee::before { content: "Assigned to "; color: var(--faint); font-style: normal; }
  .ticket-table td.c-assignee.is-unassigned::before { content: ""; }
  .ticket-table tbody tr:active { background: var(--surface2); }

  /* Ticket detail: tabs scroll sideways with a fade hint */
  .nd-ticket-tabs {
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
    mask-image: linear-gradient(90deg, #000 85%, transparent);
  }
  .nd-ticket-tabs::-webkit-scrollbar { display: none; }
  .nd-ticket-tabs [role="tab"] { flex: 0 0 auto; scroll-snap-align: start; min-height: 44px; }
  .detail-title { font-size: 21px; line-height: 1.25; }

  /* Dialogs become bottom sheets that use the full height */
  .dialog { border-radius: 22px 22px 0 0; }
  .dialog-top { position: sticky; top: 0; z-index: 3; background: inherit; }
  #dialog-close { width: 44px; height: 44px; }
  .modal-footer { position: sticky; bottom: calc(-1 * env(safe-area-inset-bottom, 0px)); background: inherit; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); z-index: 2; }
  .modal-footer .btn { min-height: 46px; flex: 1; justify-content: center; }

  /* Comfortable tap targets everywhere */
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; }
  .filter-select, .field input, .field select { min-height: 46px; }
  .field textarea { min-height: 110px; }
  .ops-tabs, .chip-row { overflow-x: auto; scrollbar-width: none; }
}

/* Light theme surfaces for phone sheets */
@media (max-width: 670px) {
  body.light .dialog-top, body.light .modal-footer { background: #fff; }
}

/* ---------- Phones: page-level layout fixes ---------- */
@media (max-width: 670px) {
  /* KPI grids: two per row, an odd last card spans the row instead of leaving a gap */
  .ops-metrics, .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .ops-metrics > :last-child:nth-child(odd), .metrics > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .ops-kpi { padding: 14px; min-width: 0; }
  /* Team summary: three compact tiles in one row */
  .nd-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .nd-stats .statbox { padding: 12px; gap: 4px; }
  .nd-stats .statbox strong { font-size: 24px; }
  .nd-stats .statbox small { font-size: 11px; line-height: 1.25; }
  /* Dashboard hero is decorative: keep it short on phones */
  .gradient-banner { padding: 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
  .gradient-banner h2 { font-size: 19px; line-height: 1.25; }
  .gradient-banner p { display: none; }
  /* Section intro text: tighter */
  .page-head p { font-size: 13px; }
  .eyebrow { font-size: 10px; }
}
body.light .field label { color: #4e5d77; }
@media (max-width: 670px) {
  .toolbar:has(#ops-company-search) .search-input { flex: 1 1 100%; }
  .toolbar:has(#ops-company-search) .tag { margin-left: 2px; }
  .ops-customer-groups { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); mask-image: linear-gradient(90deg, #000 88%, transparent); }
  .ops-customer-groups > * { flex: 0 0 auto; }
}

/* ---------- 3.12 credential vault ---------- */
.ops-secret-text { flex: 1; min-width: 0; }
.ops-secret-text strong, .ops-secret-text small { overflow-wrap: anywhere; }
.ops-secret-actions { display: flex; gap: 6px; flex-shrink: 0; }
.ops-vault-search { margin: 0 0 12px; }
.ops-secret-value { user-select: all; }
@media (max-width: 670px) {
  .ops-secret-row { flex-wrap: wrap; }
  .ops-secret-actions { width: 100%; }
  .ops-secret-actions .btn { flex: 1; }
}
.ops-line-editable { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ops-line-editable > div { min-width: 0; }
.ops-line-editable small a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.ops-status-cell { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.file-row .file-remove { margin-left: auto; }

/* ---------- 3.12 quick search palette ---------- */
.nd-palette { position: fixed; inset: 0; z-index: 140; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.nd-palette.hidden { display: none; }
.nd-palette-shade { position: absolute; inset: 0; background: rgba(5, 10, 22, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.nd-palette-box { position: relative; width: min(640px, 100%); max-height: min(70vh, 560px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; animation: nd-toast-in .16s ease-out; }
.nd-palette-input { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line2); color: var(--faint); font-size: 18px; }
.nd-palette-input input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 16px; padding: 6px 0; }
.nd-palette-input input::-webkit-search-cancel-button { display: none; }
.nd-palette-list { overflow-y: auto; padding: 6px; overscroll-behavior: contain; }
.nd-palette-group { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 700; padding: 10px 10px 4px; }
.nd-palette-item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; cursor: pointer; min-height: 48px; }
.nd-palette-item.active { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.nd-palette-item.is-empty { cursor: default; opacity: .8; }
.nd-palette-icon { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; border-radius: 8px; background: var(--surface2); color: var(--muted); }
.nd-palette-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.nd-palette-text strong { font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nd-palette-text small { font-size: 12px; color: var(--faint); }
.nd-palette-foot { display: flex; gap: 16px; padding: 9px 14px; border-top: 1px solid var(--line2); font-size: 11px; color: var(--faint); }
.nd-palette-foot kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-right: 3px; background: var(--surface2); }
body.palette-open { overflow: hidden; }
@media (max-width: 670px) {
  .nd-palette { padding: 0; align-items: stretch; }
  .nd-palette-box { width: 100%; max-height: none; height: 100dvh; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top, 0px); }
  .nd-palette-foot { display: none; }
  .nd-palette-list { flex: 1; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 900px) {
  .top-search { display: inline-flex; width: 40px; min-width: 40px; height: 40px; padding: 0; justify-content: center; font-size: 0; border-radius: 12px; }
  .top-search span { font-size: 21px; }
  .top-search kbd { display: none; }
}

/* ---------- 3.12 sticky Reply / Note bar on phones ---------- */
.nd-quick-compose { display: none; }
@media (max-width: 670px) {
  .nd-quick-compose {
    display: flex; gap: 8px; position: sticky; bottom: 0; z-index: 4; margin: 14px -18px 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border-top: 1px solid var(--line);
    box-shadow: 0 -8px 20px rgba(0, 0, 0, .12);
  }
  body.light .nd-quick-compose { background: #fff; }
  .nd-quick-compose .btn { flex: 1; min-height: 48px; justify-content: center; font-size: 15px; }
}
@media (max-width: 670px) {
  /* While typing (keyboard open) the bar would only cover the form. */
  .dialog-content:has(.nd-compose :is(textarea, input, select):focus) .nd-quick-compose { display: none; }
}

/* ---------- 3.13 email settings ---------- */
.nd-switch-row { align-items: flex-start; gap: 12px; padding: 12px; border: 1px solid var(--line2); border-radius: 12px; margin: 0 0 10px; cursor: pointer; }
.nd-switch-row input { width: 20px; height: 20px; margin-top: 2px; flex-shrink: 0; accent-color: var(--primary); }
.nd-switch-row span { display: flex; flex-direction: column; gap: 3px; }
.nd-switch-row strong { color: var(--text); font-size: 13px; }
.nd-switch-row small { font-size: 12px; line-height: 1.4; }

/* ---------- 3.13 saved replies ---------- */
.nd-template-bar { margin: 6px 0 8px; }
.nd-template-bar select { width: 100%; max-width: 320px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 0 10px; }
.nd-template-manage { margin-top: 8px; border: 1px solid var(--line2); border-radius: 12px; padding: 10px 12px; background: var(--surface2); }
.nd-template-manage-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.nd-template-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line2); }
.nd-template-row small { display: block; color: var(--faint); font-size: 11px; }
@media (max-width: 670px) { .nd-template-bar select { max-width: none; height: 46px; } }

/* ---------- 3.13: quick ticket views ---------- */
.nd-views { display: flex; gap: 6px; margin: 0 0 12px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.nd-views::-webkit-scrollbar { display: none; }
.nd-view-chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.nd-view-chip:hover { color: var(--text); border-color: var(--primary); }
.nd-view-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (max-width: 670px) {
  .nd-views { margin: 0 -16px 10px; padding: 0 16px; }
  .nd-view-chip { padding: 8px 14px; min-height: 36px; }
}

/* ---------- 3.17: announcements and maintenance mode from the control panel ----------
   .nd-notice is this fixed banner only. Rows in the bell's inbox are .nd-inbox-item (styles.css). */
.nd-notice {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 410;
  display: flex; align-items: center; gap: 14px; width: max-content; max-width: min(720px, calc(100vw - 32px));
  padding: 10px 12px 10px 16px; border-radius: 12px; font-size: 13px; line-height: 1.4;
  background: #15233b; border: 1px solid #2f4d7a; color: #dbe9ff; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.nd-notice.warning { background: #2b2113; border-color: #7a5a24; color: #ffe3b5; }
body.light .nd-notice { background: #eef4ff; border-color: #bcd2f5; color: #1d3f73; }
body.light .nd-notice.warning { background: #fff6e6; border-color: #eccb8c; color: #6d4a0c; }
.nd-notice button {
  flex: 0 0 auto; padding: 4px 10px; border-radius: 8px; font: inherit; font-size: 12px; cursor: pointer;
  background: transparent; border: 1px solid currentColor; color: inherit;
}
#nd-maintenance { top: 64px; }
@media (max-width: 670px) {
  .nd-notice { left: 16px; right: 16px; width: auto; max-width: none; transform: none; }
}

/* ---------- 3.13: connection-lost banner ---------- */
.nd-offline {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 400;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 10px 12px 10px 14px; border-radius: 12px; font-size: 13px;
  background: #2a1520; border: 1px solid #7a2c3f; color: #ffd9e1; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
body.light .nd-offline { background: #fff1f3; border-color: #f2b8c1; color: #9b1c31; }
.nd-offline.hidden { display: none; }
.nd-offline-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff5d7a; flex: 0 0 auto; animation: nd-pulse 1.2s ease-in-out infinite; }
@keyframes nd-pulse { 50% { opacity: .3; } }
@media (max-width: 670px) {
  .nd-offline { bottom: calc(78px + env(safe-area-inset-bottom)); left: 16px; right: 16px; transform: none; max-width: none; }
}

/* ---------- 3.14: light theme palette for badges and soft buttons ----------
   The original badge and button colours were designed for the dark theme and looked
   heavy (dark navy blocks) on the light theme. These give soft tints with readable text. */
body.light .pill { background: #f1f3f8; color: #4a5872; border-color: #dfe4ee; }
body.light .pill.open { background: #eaf1ff; color: #2756c5; border-color: #c9d9fb; }
body.light .pill.in_progress { background: #eeedff; color: #4b3fc0; border-color: #d6d2fb; }
body.light .pill.waiting { background: #fff4e5; color: #a25c0b; border-color: #f6d9ad; }
body.light :is(.pill.resolved, .pill.closed, .pill.active, .pill.approved) { background: #e7f8f1; color: #0d7552; border-color: #b6e6d3; }
body.light .pill.urgent, body.light .pill.overdue, body.light .pill.rejected { background: #ffeef0; color: #b4233c; border-color: #f6c4cc; }
body.light .pill.high { background: #fff1e6; color: #b14d0c; border-color: #f7d0b0; }
body.light .pill.medium { background: #efeeff; color: #5148c9; border-color: #d9d6fb; }
body.light .pill.low { background: #e9f7f1; color: #17775a; border-color: #bfe6d6; }
body.light .pill.pending { background: #fff4e5; color: #a25c0b; border-color: #f6d9ad; }
body.light .btn.soft { background: #efedff; border-color: #d7d1fb; color: #4b3fc0; }
body.light .btn.soft:hover { background: #e5e1ff; }
body.light .btn.danger { background: #fff0f2; border-color: #f4c3cb; color: #b4233c; }
body.light .btn.danger:hover { background: #ffe3e7; }
body.light .role-badge { background: #eef1f8; color: #3c4c69; }
body.light .kb-tag { background: #efedff; border-color: #d9d4fb; color: #5148c9; }
body.light .asset-card .asset-type { background: #efedff; }
body.light .activity-dot { background: #eef0fb; color: #5a4fd0; }
body.light :is(.kb-card, .asset-card):hover { background: #fbfcff; border-color: #c9c3f7; box-shadow: 0 8px 24px #3a3f7a14; }

/* ---------- 3.14: team directory ---------- */
.nd-team-tools { display: flex; align-items: center; gap: 12px; padding: 12px 20px 14px; flex-wrap: wrap; }
.nd-team-tools .nd-views { margin: 0; flex: 1 1 auto; }
.nd-team-tools .search-input { flex: 0 1 280px; }
.nd-view-chip b { font-weight: 700; opacity: .7; margin-left: 3px; }
.team-row.hidden { display: none; }
.team-row .team-name { min-width: 0; }
.team-row .team-name small { overflow-wrap: anywhere; }
.nd-team-empty { padding: 18px 20px; }
.role-badge.role-admin { background: #3a2f6b; color: #d6ccff; }
.role-badge.role-agent { background: #1f3b4d; color: #9fdcff; }
body.light .role-badge.role-admin { background: #efedff; color: #4b3fc0; }
body.light .role-badge.role-agent { background: #e6f4fb; color: #1f6b8f; }
@media (max-width: 670px) {
  .nd-team-tools { padding: 10px 16px 12px; }
  .nd-team-tools .nd-views { margin: 0 -16px; padding: 0 16px; flex-basis: 100%; }
  .nd-team-tools .search-input { flex: 1 1 100%; }
  .team-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 6px 12px; padding: 14px 16px; align-items: start; }
  .team-row .avatar, .team-row .team-name { grid-row: span 2; }
  .team-row .role-badge { grid-column: 3; grid-row: 1; justify-self: end; }
  .team-row > .pill { grid-column: 3; grid-row: 2; justify-self: end; }
  .team-row .nd-actions { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .team-row .nd-actions .btn { justify-content: center; min-height: 38px; padding-inline: 6px; }
}

/* ---------- 3.14: links styled as buttons ---------- */
a.btn, a.btn:hover { text-decoration: none; }

/* ---------- 3.14: phones show operations tables as cards ---------- */
@media (max-width: 670px) {
  .ops-table-wrap { overflow: visible; }
  .ops-table, .ops-table tbody { display: block; width: 100%; min-width: 0; }
  .ops-table thead { display: none; }
  .ops-table tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line2); }
  .ops-table tr:last-child { border-bottom: 0; }
  .ops-table td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 4px 0; border: 0; text-align: right; }
  .ops-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; flex: 0 0 auto; }
  .ops-table td:first-child { font-weight: 700; color: var(--text); }
  .ops-table td[colspan] { display: block; text-align: left; color: var(--muted); }
  .ops-table td small { display: block; color: var(--muted); }
  .ops-table .ops-status-cell { justify-content: flex-end; }
}

/* ---------- 3.14: compact company and asset cards on phones ---------- */
@media (max-width: 670px) {
  .ops-company-grid { gap: 10px; }
  .ops-company-card { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 2px 12px; padding: 14px 16px; border-radius: 14px; align-items: center; }
  .ops-company-card .ops-company-monogram { grid-row: span 3; width: 44px; height: 44px; border-radius: 12px; }
  .ops-company-card strong { font-size: 15px; }
  .ops-company-card > :not(.ops-company-monogram) { grid-column: 2; }
  .asset-grid { gap: 10px; }
  .asset-card { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 2px 12px; padding: 14px 16px; }
  .asset-card .asset-type { grid-row: 1 / span 4; margin: 0; }
  .asset-card > :not(.asset-type) { grid-column: 2; }
  .asset-card .tag { justify-self: start; }
  .asset-card h3 { margin: 4px 0 2px; }
  .asset-card p { margin-bottom: 6px; }
}
body.light .ops-company-monogram { background: #ebeefe; color: #4255b8; }

/* ---------- 3.14: clickable overview cards ---------- */
button.metric { font: inherit; color: inherit; text-align: left; width: 100%; cursor: pointer; transition: border-color .15s, transform .15s, box-shadow .15s; }
button.metric:hover { border-color: var(--primary); transform: translateY(-1px); }
.metric-go { color: var(--primary); font-weight: 700; opacity: 0; transition: opacity .15s; }
button.metric:hover .metric-go, button.metric:focus-visible .metric-go { opacity: 1; }
@media (hover: none) { .metric-go { opacity: .8; } }

/* ---------- 3.14: phone table cards use the first column as the card title ---------- */
@media (max-width: 670px) {
  .ops-table td:first-child { justify-content: flex-start; text-align: left; font-size: 15px; padding-bottom: 6px; }
  .ops-table td:first-child::before { display: none; }
}

/* 3.14: .tag text was too faint on the light theme (contrast below 2:1). */
body.light .tag { color: #55637d; }
.detail-meta .tag { font-size: 11px; padding: 5px 9px; font-weight: 600; }

/* ---------- 3.14: compact "Ticket for" card on phones, so the tabs are visible sooner ---------- */
@media (max-width: 670px) {
  .nd-ticket-customer { position: relative; margin: 10px 0 4px; padding: 12px 14px; }
  .nd-ticket-customer-line { margin-bottom: 6px; padding-right: 76px; }
  .nd-ticket-customer .nd-customer-main strong { font-size: 15px; }
  .nd-ticket-customer > small { display: inline; margin: 0; }
  .nd-ticket-customer > small + small::before { content: ' · '; }
  #nd-customer-edit-toggle { position: absolute; top: 9px; right: 9px; font-size: 0; min-height: 30px; padding: 4px 12px; }
  #nd-customer-edit-toggle::after { content: 'Change'; font-size: 12px; }
  body:has(#overlay:not(.hidden) .nd-quick-compose) #toast-zone { bottom: calc(100px + env(safe-area-inset-bottom, 0px)); }
}

/* 3.14: customers see three summary cards */
@media (min-width: 671px) { .metrics.metrics-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- 3.14: running timer chip in the top bar ---------- */
.nd-timer-chip { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; margin-right: 4px; border-radius: 999px; border: 1px solid #2f8f6b; background: #123228; color: #8ff0c9; font: inherit; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; cursor: pointer; }
.nd-timer-chip.hidden { display: none; }
.nd-timer-chip.paused { border-color: #8a6a2c; background: #33281a; color: #f3c77a; }
.nd-timer-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: nd-pulse 1.4s ease-in-out infinite; }
.nd-timer-chip.paused .nd-timer-dot { animation: none; border-radius: 1px; width: 7px; }
body.light .nd-timer-chip { background: #e7f8f1; border-color: #a7e4cd; color: #0d6b4c; }
body.light .nd-timer-chip.paused { background: #fff4e5; border-color: #f6d9ad; color: #a25c0b; }
@media (max-width: 670px) { .nd-timer-chip { height: 34px; padding: 0 10px; font-size: 12px; margin-right: 2px; } }

/* 3.14: the top search kept its dark-theme border on the light theme */
body.light .top-search { border-color: #d9dfea; }
body.light .top-search:hover { border-color: #b9c2d6; }
body.light .top-search kbd { background: #f3f5fa; border-color: #d9dfea; color: #6b7891; }

/* 3.14: form footers inside page panels wrap instead of spilling out of narrow cards, and only dialogs get the sticky phone footer */
#view .modal-footer { flex-wrap: wrap; }
@media (max-width: 670px) { #view .modal-footer { position: static; padding-bottom: 0; background: none; } }

/* ---------- 3.14: SLA hint in ticket lists ---------- */
.nd-due { display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 999px; font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-weight: 700; font-size: 10px; line-height: 1.6; letter-spacing: .02em; vertical-align: 1px; }
.nd-due.overdue { background: #4a2531; color: #ff95a2; }
.nd-due.soon { background: #3c3026; color: #e9bb78; }
body.light .nd-due.overdue { background: #ffeef0; color: #b4233c; }
body.light .nd-due.soon { background: #fff4e5; color: #a25c0b; }

/* 3.14: bigger tap target for panel links on phones */
@media (max-width: 670px) { .panel-link { min-height: 36px; padding: 8px 4px; } }

#dialog:focus { outline: none; }

/* ---------- 3.14: requester picker ---------- */
.nd-requester-field .nd-requester-find { margin-bottom: 6px; }
.nd-requester-field { grid-column: 1 / -1; }

/* ---------- 3.14: dark theme badges for account and approval states ---------- */
:is(.pill.active, .pill.approved) { background: #1e4039; color: #78d5b8; border-color: #32665a; }
.pill.pending { background: #3c3026; color: #e9bb78; border-color: #644933; }
.pill.rejected { background: #4a2531; color: #ff95a2; border-color: #784652; }

/* ---------- 3.14: copilot example questions ---------- */
.nd-suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 16px; max-width: 560px; }
.nd-suggest-chip { border: 1px solid var(--line); background: var(--surface2); color: var(--text); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px; cursor: pointer; text-align: left; }
.nd-suggest-chip:hover { border-color: var(--primary); }

/* 3.14: customer record lists (sites, departments, contacts): name over details, Edit on the right */
.ops-line-editable { flex-direction: row; text-align: left; }
.ops-line-editable > div { flex: 1 1 auto; }
.ops-line-editable > div > strong { display: block; }
.ops-line-editable > div > small { display: block; margin-top: 2px; overflow-wrap: anywhere; }
.ops-line-editable > .btn { flex: 0 0 auto; }
.ops-company-detail .ops-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.ops-linked-ticket { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.nd-trip-miles { margin: -4px 0 4px; font-size: 13px; font-weight: 650; min-height: 1em; }
.nd-trip-miles.ok { color: var(--green, #2bb38a); }
.nd-trip-miles.bad { color: var(--red, #e5546b); }

/* ================================================================
   3.16: AI copilot on phones — the chat fills the screen like a messaging app.
   ================================================================ */
.nd-ai-tabs { display: none; }
.chat-bubble { font-size: 13px; line-height: 1.7; }
@media (max-width: 670px) {
  #view:has(.copilot-layout) .page-head { display: none; }
  #view:has(.copilot-layout) { padding-bottom: 0; }
  .copilot-layout { display: block; min-height: 0; }
  .nd-ai-tabs { display: flex; gap: 6px; align-items: center; margin: 0 0 10px; }
  .nd-ai-tabs [data-ai-pane] { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 650; min-height: 36px; }
  .nd-ai-tabs [data-ai-pane].active { background: var(--primary); border-color: var(--primary); color: #fff; }
  .nd-ai-draft-mini { margin-left: auto; border: 0; background: none; color: var(--primary); font: inherit; font-size: 13px; font-weight: 700; padding: 8px 4px; min-height: 36px; }
  .copilot-layout > aside { display: none; }
  .copilot-layout.show-tools > aside { display: grid; gap: 12px; }
  .copilot-layout.show-tools > .chat-panel { display: none; }
  .copilot-layout > aside .panel { margin: 0; }

  .chat-panel { min-height: 0; height: calc(100dvh - 64px - 46px - 70px - 28px - env(safe-area-inset-bottom, 0px)); border-radius: 16px; overflow: hidden; }
  .chat-panel .panel-head { padding: 10px 12px 10px 14px; }
  .chat-panel .panel-head h3 { font-size: 15px; }
  .chat-panel .panel-head small { display: none; }
  .chat-log { flex: 1 1 auto; min-height: 0; max-height: none; padding: 14px 12px; gap: 14px; overscroll-behavior: contain; }
  .chat-message { max-width: 100%; gap: 8px; }
  .chat-avatar { width: 28px; height: 28px; border-radius: 9px; font-size: 14px; }
  .chat-bubble { font-size: 15px; line-height: 1.55; padding: 10px 13px; }
  .chat-log > .blank { padding: 12px 4px; margin: auto 0; }
  .chat-log > .blank p { font-size: 13px; }
  .chat-log > .blank .blank-icon { margin-bottom: 6px; }
  .nd-suggest { justify-content: flex-start; margin-top: 12px; }
  .nd-suggest-chip { font-size: 14px; padding: 9px 13px; }
  .chat-input { padding: 8px 10px 10px; }
  .chat-compose { padding: 6px; border-radius: 14px; align-items: flex-end; }
  .chat-compose textarea { font-size: 16px; min-height: 44px; max-height: 120px; resize: none; padding: 9px 8px; line-height: 1.35; }
  .chat-compose .btn { min-height: 44px; padding: 0 14px; white-space: nowrap; }
  .chat-hint { display: none; }
  #ai-action-area:empty { display: none; }
}

/* 3.16: chat bubbles on the light theme */
body.light .chat-message.user .chat-bubble { background: #6656e8; border-color: #6656e8; color: #fff; }
body.light .chat-message.user .chat-avatar { background: #dcd8ff; color: #4b3fc0; }
body.light .chat-message:not(.user) .chat-bubble { background: #f4f6fb; border-color: #e2e7f1; color: #24324b; }

/* ---------- 3.16: light theme leftovers from the dark design ---------- */
body.light .field input, body.light .field select, body.light .field textarea { border-color: #d3dae6; }
body.light .field input:focus, body.light .field select:focus, body.light .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px #6c5ce726; }
body.light .auth-card { border-color: #dfe4ee; }
body.light .sidebar-close { background: #eef0f7; color: #33405a; }
body.light .chat-compose { border-color: #d3dae6; }

/* Overview cards that are buttons: keep the content at the top like the other cards */
button.metric { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; }

/* ---------- 3.16: phone overview is about the work, not the banner ---------- */
@media (max-width: 670px) {
  #view:has(#banner-ai) .gradient-banner { display: none; }
  #export-btn { display: none; }
  .metric { min-height: 0; }
}

/* 3.16: the overview chart keeps its proportions on phones (no empty band above and below) */
@media (max-width: 670px) {
  .chart-box { min-height: 0; }
  .chart-svg { height: auto; aspect-ratio: 650 / 210; }
  .chart-label { font-size: 19px; }
  .chart-legend { gap: 10px; font-size: 11px; }
}

.nd-palette-input input:focus, .nd-palette-input input:focus-visible { outline: none; }

/* ---------- 3.16: tighter page headers on phones ----------
   The top bar already names the page, so the eyebrow and description are dropped and the
   page actions sit right under a smaller title. This brings the actual content ~120px higher. */
@media (max-width: 670px) {
  .page-head { gap: 10px; margin-bottom: 14px; }
  .page-head .eyebrow, .page-head p { display: none; }
  .page-head h1 { font-size: 23px; letter-spacing: -.4px; }
  .page-head-actions .btn { min-height: 42px; }
  .toolbar > .tag { display: none; }
  .kb-card { padding: 15px 16px; }
  .kb-card p { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 10px; }
  .kb-card .kb-tag { margin-bottom: 8px; }
  .kb-grid { gap: 10px; }
}

@media (max-width: 670px) { .page-head-actions:empty, .page-head-actions:has(> #export-btn:only-child) { display: none; } }

/* ---------- 3.16: ticket composer controls share one look ---------- */
:is(.nd-time-grid, .nd-post-footer-controls, .nd-template-bar) :is(input:not([type=checkbox]):not([type=radio]), select) {
  font: inherit; font-size: 13px; font-weight: 500; height: 40px; min-height: 40px; padding: 0 11px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface2); color: var(--text);
}
.nd-compose-editor textarea { font: inherit; font-size: 14px; }
body.light :is(.nd-time-grid, .nd-post-footer-controls, .nd-template-bar) :is(input:not([type=checkbox]):not([type=radio]), select),
body.light .nd-compose-editor textarea { background: #fff; border-color: #d3dae6; }
.nd-time-grid input::placeholder { font-size: 13px; color: var(--faint); }
/* Only show the "manual / timer" choice when a timer is actually running */
.nd-time-choice:not(:has(#nd-timer-choice:not(.hidden))) { display: none; }
@media (min-width: 900px) {
  .nd-time-grid { grid-template-columns: 1fr 1.3fr 1fr; }
  .nd-post-footer-controls label { max-width: 320px; }
}

/* ---------- 3.16: desktop polish ---------- */
/* Labels that wrap their input (month pickers, mileage search) match the other form labels */
label.field { display: flex; flex-direction: column; gap: 7px; font-size: 11px; font-weight: 700; color: var(--muted); }
label.field > input, label.field > select { font: inherit; font-size: 13px; font-weight: 500; color: var(--text); height: 40px; }
.nd-mile-search { align-items: flex-end; }
.nd-mile-search > .muted { align-self: center; margin-top: 18px; }
/* Ticket description box: soft border on the light theme */
body.light .detail-desc { border-color: #dfe4ee; }
/* Ticket tabs: clearer active state */
.dialog-content [role=tab][aria-selected="true"] { color: var(--text); }

/* 3.16: on desktop the chat fits the window, so the message box is always visible */
@media (min-width: 671px) {
  .copilot-layout { align-items: start; }
  .chat-panel { height: calc(100vh - 250px); min-height: 520px; position: sticky; top: 20px; }
  .chat-log { flex: 1 1 auto; min-height: 0; max-height: none; }
  .copilot-layout > aside { display: grid; gap: 16px; align-content: start; }
  .copilot-layout > aside .panel { margin: 0; }
}

/* 3.16: the phone Reply / Note bar sits inside the sheet edges (it was 17px off each side) */
@media (max-width: 670px) { .dialog-content.nd-ticket-organized > .nd-quick-compose, .nd-quick-compose { margin-inline: 0; } }

/* 3.17: email delivery health in Billing & integrations */
.nd-mail-health { display: grid; gap: 10px; margin-top: 4px; }
.nd-mail-conn { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.nd-mail-conn strong { color: var(--text); }
.nd-mail-warn { margin: 0; padding: 10px 12px 10px 28px; border: 1px solid rgba(245, 166, 35, .45); background: rgba(245, 166, 35, .09); border-radius: 10px; font-size: 12.5px; line-height: 1.5; display: grid; gap: 4px; }
.nd-mail-alert { display: grid; gap: 4px; padding: 10px 12px; border: 1px solid rgba(239, 68, 68, .45); background: rgba(239, 68, 68, .08); border-radius: 10px; font-size: 12.5px; line-height: 1.5; overflow-wrap: anywhere; }
.nd-mail-h { margin: 6px 0 0; font-size: 13px; }
.nd-mail-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.nd-mail-row { border: 1px solid var(--line2); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; min-width: 0; }
.nd-mail-row-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; min-width: 0; }
.nd-mail-row-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.nd-mail-row-head .pill { flex-shrink: 0; }
.nd-mail-reason { font-size: 12.5px; line-height: 1.5; overflow-wrap: anywhere; }
body.light .nd-mail-warn { background: #fff7e8; border-color: #f3cf8f; color: #5c3d00; }
body.light .nd-mail-alert { background: #fff1f1; border-color: #f4b4b4; color: #7a1d1d; }
