/* FiniteDesk agent workspace — dark theme default (fleet norm). Self-contained;
   no external fonts/CDNs (CSP script-src 'self'). */
:root {
  --fd-accent: var(--app-accent, #0ea5e9);
  --fd-bg: #0f172a;
  --fd-panel: #131c31;
  --fd-panel-2: #1a2439;
  --fd-border: #24314d;
  --fd-text: #e6ecf6;
  --fd-muted: #93a1bd;
  --fd-internal: #3a2c07;      /* amber wash for internal notes — hard visual line */
  --fd-internal-bd: #7a5c12;
  --fd-radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fd-bg); color: var(--fd-text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.fd-boot { padding: 40px; color: var(--fd-muted); }
a { color: var(--fd-accent); }

/* shell -------------------------------------------------------------------- */
.fd-shell { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: 52px 1fr;
  grid-template-areas: "top top" "rail main"; height: 100vh; }
.fd-top { grid-area: top; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--fd-border); background: var(--fd-panel); }
.fd-top .brand { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.fd-top .brand img { width: 22px; height: 22px; }
.fd-top .spacer { flex: 1; }
.fd-search { width: 320px; max-width: 40vw; background: var(--fd-panel-2);
  color: var(--fd-text); border: 1px solid var(--fd-border); border-radius: 999px;
  padding: 7px 14px; font: inherit; margin-left: 14px; }
.fd-search:focus { outline: none; border-color: var(--fd-accent); }
.fd-search::placeholder { color: var(--fd-muted); }
.fd-search-subj { font-weight: 600; }
.fd-search-snip { font-size: 12px; color: var(--fd-muted); margin-top: 3px; }
.fd-search-snip .fd-tag { text-transform: capitalize; }
.fd-pill { font-size: 12px; color: var(--fd-muted); border: 1px solid var(--fd-border);
  border-radius: 999px; padding: 2px 10px; }

.fd-rail { grid-area: rail; border-right: 1px solid var(--fd-border);
  background: var(--fd-panel); padding: 14px 10px; overflow: auto; }
.fd-rail h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--fd-muted); margin: 14px 8px 6px; }
.fd-rail .q { display: flex; justify-content: space-between; align-items: center;
  padding: 7px 10px; border-radius: 8px; cursor: pointer; color: var(--fd-text); }
.fd-rail .q:hover { background: var(--fd-panel-2); }
.fd-rail .q.active { background: color-mix(in srgb, var(--fd-accent) 22%, transparent);
  color: #fff; }
.fd-rail .q .count { font-size: 12px; color: var(--fd-muted); }
/* server-defined queues: a "team" tag on shared views + a hover delete × */
.fd-q-shared { font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--fd-muted); border: 1px solid var(--fd-border); border-radius: 5px;
  padding: 0 4px; margin-left: 4px; vertical-align: middle; }
.fd-rail .q .fd-q-del { display: none; border: none; background: transparent;
  color: var(--fd-muted); cursor: pointer; font-size: 15px; line-height: 1;
  padding: 0 2px; margin-left: 4px; }
.fd-rail .q:hover .fd-q-del { display: inline; }
.fd-rail .q .fd-q-del:hover { color: var(--fd-danger, #e5484d); }
/* New-view builder condition rows */
.fd-clause { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.fd-clause .nv-f { flex: 0 0 34%; }
.fd-clause .nv-o { flex: 0 0 24%; }
.fd-clause .nv-v { flex: 1 1 auto; min-width: 0; }
.fd-clause .nv-rm { flex: 0 0 auto; padding: 4px 9px; }

.fd-main { grid-area: main; overflow: auto; padding: 20px 24px; }

/* buttons + inputs --------------------------------------------------------- */
.fd-btn { background: var(--fd-accent); color: #04121f; border: 0; font-weight: 600;
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; }
.fd-btn:hover { filter: brightness(1.08); }
.fd-btn.ghost { background: transparent; color: var(--fd-text);
  border: 1px solid var(--fd-border); }
.fd-btn.ghost:hover { background: var(--fd-panel-2); }
.fd-btn:disabled { opacity: .5; cursor: default; }
.fd-in, .fd-sel, .fd-ta { width: 100%; background: var(--fd-panel-2); color: var(--fd-text);
  border: 1px solid var(--fd-border); border-radius: 8px; padding: 9px 11px; font: inherit; }
.fd-ta { min-height: 84px; resize: vertical; }
.fd-row { display: flex; gap: 10px; align-items: center; }
.fd-field { margin-bottom: 12px; }
.fd-field label { display: block; font-size: 12px; color: var(--fd-muted); margin-bottom: 5px; }

/* queue table -------------------------------------------------------------- */
.fd-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.fd-head h1 { font-size: 18px; margin: 0; }
.fd-head .spacer { flex: 1; }
table.fd-table { width: 100%; border-collapse: collapse; }
.fd-table th { text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--fd-muted); padding: 8px 10px; border-bottom: 1px solid var(--fd-border); }
.fd-table td { padding: 11px 10px; border-bottom: 1px solid var(--fd-border); }
.fd-table tr.click { cursor: pointer; }
.fd-table tr.click:hover td { background: var(--fd-panel); }
.fd-key { font-family: ui-monospace, "Cascadia Code", monospace; color: var(--fd-accent); }
.fd-empty { color: var(--fd-muted); padding: 40px 0; text-align: center; }

.badge { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--fd-border); }
.badge.todo { color: #7dd3fc; border-color: #235; }
.badge.in_progress { color: #fbbf24; border-color: #543; }
.badge.done { color: #6ee7b7; border-color: #254; }
.prio { font-size: 12px; text-transform: capitalize; color: var(--fd-muted); }
.prio.high, .prio.urgent { color: #fca5a5; }

/* ticket view -------------------------------------------------------------- */
.fd-ticket { max-width: 860px; }
.fd-ticket .hdr { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.fd-ticket .hdr h1 { font-size: 20px; margin: 0; flex: 1; }
.fd-ticket .meta { color: var(--fd-muted); font-size: 13px; margin-bottom: 18px; }
.fd-ticket .meta .fd-key { font-size: 13px; }
.fd-desc { background: var(--fd-panel); border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius); padding: 14px 16px; margin-bottom: 22px; }

.fd-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }

.fd-conv { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.fd-c { border: 1px solid var(--fd-border); border-radius: var(--fd-radius);
  padding: 12px 14px; background: var(--fd-panel); }
.fd-c.internal { background: var(--fd-internal); border-color: var(--fd-internal-bd); }
.fd-c .c-head { display: flex; gap: 8px; align-items: center; font-size: 12px;
  color: var(--fd-muted); margin-bottom: 6px; }
.fd-c .c-tag { font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  font-size: 10px; padding: 1px 7px; border-radius: 4px; }
.fd-c .c-tag.public { background: #0c3f57; color: #7dd3fc; }
.fd-c .c-tag.internal { background: #7a5c12; color: #ffe9b3; }
.fd-c .c-body { white-space: normal; }

.fd-reply { border: 1px solid var(--fd-border); border-radius: var(--fd-radius);
  padding: 14px; background: var(--fd-panel); }
.fd-reply .toggle { display: inline-flex; border: 1px solid var(--fd-border);
  border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.fd-reply .toggle button { background: transparent; color: var(--fd-muted); border: 0;
  padding: 6px 14px; cursor: pointer; font: inherit; }
.fd-reply .toggle button.on { color: #fff; }
.fd-reply .toggle button.on.public { background: #0c3f57; }
.fd-reply .toggle button.on.internal { background: #7a5c12; color: #ffe9b3; }

/* cards / dialogs ---------------------------------------------------------- */
.fd-card { max-width: 460px; background: var(--fd-panel); border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius); padding: 22px; }
.fd-card h2 { margin: 0 0 16px; font-size: 17px; }
.fd-err { color: #fca5a5; font-size: 13px; min-height: 18px; margin: 4px 0; }
.fd-modal-bg { position: fixed; inset: 0; background: rgba(3,8,20,.62);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.link { color: var(--fd-accent); cursor: pointer; }
.crumb { color: var(--fd-muted); cursor: pointer; margin-bottom: 12px; display: inline-block; }
.crumb:hover { color: var(--fd-text); }

/* email loop panel (v0.2) -------------------------------------------------- */
.fd-mailpanel { border: 1px solid var(--fd-border); border-radius: var(--fd-radius);
  background: var(--fd-panel); padding: 12px 14px; margin: 14px 0; }
.fd-mailpanel h3 { margin: 0 0 8px; }
.fd-parts { margin-bottom: 8px; font-size: 13px; color: var(--fd-muted); }
.fd-chip { display: inline-block; background: var(--fd-bg); border: 1px solid var(--fd-border);
  border-radius: 999px; padding: 1px 9px; margin: 2px; color: var(--fd-text); font-size: 12px; }
.fd-maillog { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.fd-maillog td { padding: 4px 8px; border-top: 1px solid var(--fd-border); }
.fd-msgid { font-family: ui-monospace, "Cascadia Code", monospace; color: var(--fd-muted);
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fd-dir { font-weight: 600; font-size: 11px; letter-spacing: .04em; }
.fd-dir.in { color: #6ee7b7; }
.fd-dir.out { color: #7dd3fc; }

/* --- v0.3 SLA chips, tags, macros (desk-spec §2.5) --- */
.sla-chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; margin-left: 6px; border: 1px solid var(--fd-border);
  color: var(--fd-muted); white-space: nowrap; }
.sla-chip.ok { color: #7dd3fc; border-color: #235; }
.sla-chip.warn { color: #fbbf24; border-color: #543; }
.sla-chip.breach { color: #fca5a5; border-color: #6b2626; background: #2a1414; }
.sla-chip.paused { color: #93a1bd; border-color: var(--fd-border); }
.sla-chip.met { color: #6ee7b7; border-color: #254; }
.fd-tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px;
  margin-left: 5px; background: var(--fd-panel-2); border: 1px solid var(--fd-border);
  color: var(--fd-muted); }
.fd-resolution { color: #6ee7b7; font-size: 12px; }
.fd-macrobar { display: flex; gap: 8px; align-items: center; margin: 0 0 18px; flex-wrap: wrap; }

/* --- v0.5 collaboration: links + escalation + approvals --- */
.fd-collabpanel, .fd-apppanel { border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius); background: var(--fd-panel);
  padding: 12px 14px; margin: 14px 0; }
.fd-collabpanel h3, .fd-apppanel h3 { margin: 0 0 8px; }
.fd-linkrow { display: flex; gap: 8px; align-items: center; padding: 4px 0;
  font-size: 13px; border-top: 1px solid var(--fd-border); }
.fd-linkrow:first-of-type { border-top: 0; }
.fd-linkrow a { color: var(--fd-accent); text-decoration: none; }
.fd-linkrow a:hover { text-decoration: underline; }
.fd-linkkind { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--fd-muted); min-width: 96px; }
.fd-approw { padding: 8px 0; border-top: 1px solid var(--fd-border); font-size: 13px; }
.fd-approw:first-of-type { border-top: 0; }
.fd-apstatus { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--fd-border); color: var(--fd-muted); }
.fd-apstatus.pending { color: #fbbf24; border-color: #543; }
.fd-apstatus.approved { color: #6ee7b7; border-color: #254; }
.fd-apstatus.rejected { color: #fca5a5; border-color: #6b2626; }
.fd-apstatus.cancelled { color: #93a1bd; }
.fd-slapanel { background: var(--fd-panel); border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius); padding: 12px 14px; margin-bottom: 18px; }
.fd-slarow { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
.fd-slametric { text-transform: capitalize; font-size: 13px; min-width: 120px; }

/* --- Attachments (desk-spec §2.1 attachments + inline preview) ------------- */
.fd-attpanel { background: var(--fd-panel); border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius); padding: 12px 14px; margin-bottom: 18px; }
.fd-atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.fd-att { display: inline-flex; align-items: center; gap: 6px; max-width: 260px;
  font-size: 12px; padding: 4px 8px; border: 1px solid var(--fd-border);
  border-radius: 8px; background: var(--fd-panel-2); }
.fd-att a { color: var(--fd-text); text-decoration: none; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.fd-att a:hover { color: var(--fd-accent); }
.fd-att .fd-att-size { color: var(--fd-muted); font-size: 11px; }
.fd-att.img { flex-direction: column; align-items: stretch; width: 132px;
  max-width: 132px; padding: 6px; }
.fd-att.img a { display: block; }
.fd-att.img img { display: block; width: 100%; height: 84px; object-fit: cover;
  border-radius: 6px; background: var(--fd-bg); }
.fd-att.img .fd-att-name { display: block; margin-top: 4px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.fd-att-del { margin-left: auto; background: transparent; border: 0; cursor: pointer;
  color: var(--fd-muted); font-size: 15px; line-height: 1; padding: 0 2px; }
.fd-att-del:hover { color: #f87171; }
.fd-attach-label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font-size: 13px; color: var(--fd-muted); border: 1px solid var(--fd-border);
  border-radius: 8px; padding: 7px 11px; }
.fd-attach-label:hover { background: var(--fd-panel-2); color: var(--fd-text); }

/* --- workspace-ux: notification bell + inbox panel (desk-spec §2.9/§5) ----- */
.fd-bell-wrap { position: relative; display: inline-flex; }
.fd-bell { position: relative; background: transparent; border: 1px solid var(--fd-border);
  color: var(--fd-text); border-radius: 999px; width: 34px; height: 34px; cursor: pointer;
  font-size: 15px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.fd-bell:hover { background: var(--fd-panel-2); }
.fd-bell-badge { position: absolute; top: -4px; right: -4px; min-width: 17px; height: 17px;
  padding: 0 4px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 10px;
  font-weight: 700; line-height: 17px; text-align: center; box-shadow: 0 0 0 2px var(--fd-panel); }
.fd-kbd-btn { cursor: pointer; background: transparent; }
.fd-kbd-btn:hover { background: var(--fd-panel-2); color: var(--fd-text); }
.fd-notif-panel { position: absolute; top: 42px; right: 0; width: 360px; max-width: 92vw;
  max-height: 70vh; overflow: auto; background: var(--fd-panel); border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius); box-shadow: 0 12px 40px rgba(0,0,0,.5); z-index: 60; }
.fd-notif-head { display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px; border-bottom: 1px solid var(--fd-border); font-weight: 600; font-size: 13px;
  position: sticky; top: 0; background: var(--fd-panel); }
.fd-notif-clear { background: transparent; border: 0; color: var(--fd-accent); cursor: pointer;
  font: inherit; font-size: 12px; }
.fd-notif-clear:hover { text-decoration: underline; }
.fd-notif-list { display: flex; flex-direction: column; }
.fd-notif-empty { padding: 34px 16px; text-align: center; color: var(--fd-muted); }
.fd-notif { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--fd-border); }
.fd-notif:last-child { border-bottom: 0; }
.fd-notif.unread { background: color-mix(in srgb, var(--fd-accent) 8%, transparent); }
.fd-notif.onboard { background: color-mix(in srgb, #a855f7 10%, transparent); }
.fd-notif.onboard.read { background: color-mix(in srgb, #a855f7 5%, transparent); }
.fd-notif-icon { font-size: 18px; line-height: 1.2; flex: 0 0 auto; }
.fd-notif-main { flex: 1 1 auto; min-width: 0; }
.fd-notif-title { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.fd-notif-body { font-size: 12.5px; color: var(--fd-muted); line-height: 1.5; }
.fd-notif-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.fd-notif-row .fd-btn { padding: 5px 10px; font-size: 12px; }

/* --- workspace-ux: keyboard help overlay (desk-spec §2.4) ------------------ */
.fd-kbd-overlay { position: fixed; inset: 0; background: rgba(3,8,20,.62); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.fd-kbd-card { width: 520px; max-width: 100%; max-height: 84vh; overflow: auto;
  background: var(--fd-panel); border: 1px solid var(--fd-border); border-radius: var(--fd-radius);
  padding: 20px 22px; }
.fd-kbd-cardhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.fd-kbd-cardhead h2 { margin: 0; font-size: 16px; }
.fd-kbd-x { background: transparent; border: 0; color: var(--fd-muted); font-size: 22px;
  line-height: 1; cursor: pointer; }
.fd-kbd-x:hover { color: var(--fd-text); }
.fd-kbd-table { width: 100%; border-collapse: collapse; }
.fd-kbd-table td { padding: 8px 6px; border-bottom: 1px solid var(--fd-border); font-size: 13px;
  color: var(--fd-muted); vertical-align: top; }
.fd-kbd-table td.fd-kbd-keys { white-space: nowrap; width: 42%; }
.fd-kbd-table kbd { display: inline-block; background: var(--fd-panel-2); border: 1px solid var(--fd-border);
  border-bottom-width: 2px; border-radius: 6px; padding: 2px 7px; font-family: ui-monospace,
  "Cascadia Code", monospace; font-size: 12px; color: var(--fd-text); }
.fd-kbd-sep { color: var(--fd-muted); font-size: 11px; margin: 0 2px; }
.fd-kbd-foot { margin-top: 14px; font-size: 12px; color: var(--fd-muted); }

/* --- workspace-ux: bulk toolbar + select checkboxes (desk-spec §2.4) ------- */
.fd-bulkbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--fd-panel); border: 1px solid var(--fd-accent); border-radius: var(--fd-radius);
  padding: 10px 12px; margin-bottom: 14px; }
.fd-bulk-count { font-weight: 600; font-size: 13px; }
.fd-bulk-grp { display: inline-flex; align-items: center; gap: 6px; }
.fd-bulkbar .spacer { flex: 1; }
.fd-bulk-tag { width: 130px; padding: 6px 9px; }
.fd-bulk-tr { width: 160px; padding: 6px 9px; }
.fd-bulk-cell { width: 34px; text-align: center; }
.fd-bulk-cb, #fd-bulk-all { cursor: pointer; width: 15px; height: 15px; accent-color: var(--fd-accent); }
.fd-table tr.fd-row-checked td { background: color-mix(in srgb, var(--fd-accent) 12%, transparent); }
.fd-table tr.fd-row-sel td { box-shadow: inset 3px 0 0 var(--fd-accent); }
.fd-table tr.fd-row-sel td:first-child { box-shadow: inset 3px 0 0 var(--fd-accent); }

/* reports / service dashboards (desk-spec §2.10 / §5) ---------------------- */
.fd-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 20px; }
.fd-card { background: var(--fd-panel); border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius); padding: 12px 14px; }
.fd-card .l { font-size: 12px; color: var(--fd-muted); }
.fd-card .n { font-size: 24px; font-weight: 700; margin-top: 4px; }
.fd-card .s { font-size: 11px; color: var(--fd-muted); margin-top: 3px; }
.fd-report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px; }
.fd-report-sec h2 { font-size: 14px; margin: 0 0 8px; color: var(--fd-text); }
.fd-report-sec { min-width: 0; overflow-x: auto; }
.fd-num { text-align: right; font-variant-numeric: tabular-nums; }
.fd-barcell { width: 34%; }
.fd-bar { display: block; height: 8px; border-radius: 999px; background: var(--fd-panel-2);
  overflow: hidden; min-width: 40px; }
.fd-bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--fd-accent); }
.fd-bar-fill.prio-urgent, .fd-bar-fill.prio-high { background: #fca5a5; }
.fd-bar-fill.prio-medium { background: var(--fd-accent); }
.fd-bar-fill.prio-low, .fd-bar-fill.prio-lowest { background: var(--fd-muted); }
.fd-report-ctl { font-size: 13px; }
.fd-report-foot { margin-top: 18px; font-size: 12px; color: var(--fd-muted); }

/* --- admin audit log (desk-spec §2.11) --- */
.fd-audit-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 12px 0 14px; }
.fd-audit-filters .fd-in { width: auto; font-size: 13px; }
.fd-audit-lbl { font-size: 12px; color: var(--fd-muted); display: inline-flex;
  gap: 6px; align-items: center; }
.fd-audit-table { width: 100%; }
.fd-audit-table th, .fd-audit-table td { vertical-align: top; }
.fd-audit-ts { white-space: nowrap; color: var(--fd-muted); font-size: 12px; }
.fd-audit-act { font-weight: 600; }
.fd-audit-raw { font-size: 11px; color: var(--fd-muted); font-family: ui-monospace,
  SFMono-Regular, Menlo, monospace; }
.fd-audit-json { margin: 8px 0 0; padding: 8px 10px; background: var(--fd-panel-2);
  border: 1px solid var(--fd-border); border-radius: 6px; font-size: 12px;
  max-width: 420px; overflow-x: auto; white-space: pre; }
.fd-audit-foot { display: flex; align-items: center; gap: 8px; }
.fd-audit-foot .spacer { flex: 1; }
