/* CRMish panel. Sized for a host-side drawer (380-700px) but works full-width standalone.
   No external fonts: the worker CSP is default-src 'self', so Google Fonts would be blocked. */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-sunken: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --fg: #101828;
  --fg-muted: #667085;
  --fg-faint: #98a2b3;
  --accent: #175cd3;
  --accent-soft: #eff4ff;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --info-soft: #f4f3ff;
  --info: #5925dc;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d;
    --bg-sunken: #1d2026;
    --surface: #1d2026;
    --border: #2b2f38;
    --border-strong: #3a3f4a;
    --fg: #eceef2;
    --fg-muted: #98a2b3;
    --fg-faint: #6c7484;
    --accent: #84adff;
    --accent-soft: #1b2437;
    --ok: #75e0a7;
    --ok-soft: #14291f;
    --warn: #fec84b;
    --warn-soft: #2a2113;
    --info-soft: #221b38;
    --info: #c3b5fd;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bg: #16181d;
  --bg-sunken: #1d2026;
  --surface: #1d2026;
  --border: #2b2f38;
  --border-strong: #3a3f4a;
  --fg: #eceef2;
  --fg-muted: #98a2b3;
  --fg-faint: #6c7484;
  --accent: #84adff;
  --accent-soft: #1b2437;
  --ok: #75e0a7;
  --ok-soft: #14291f;
  --warn: #fec84b;
  --warn-soft: #2a2113;
  --info-soft: #221b38;
  --info: #c3b5fd;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.panel { display: flex; flex-direction: column; height: 100%; max-width: 760px; margin: 0 auto; }

/* ---------- header ---------- */
.head { padding: 16px 16px 0; border-bottom: 1px solid var(--border); background: var(--bg); }
.head-top { display: flex; gap: 12px; align-items: flex-start; }

.avatar {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 16px; font-weight: 600; letter-spacing: .01em;
}

.head-text { flex: 1 1 auto; min-width: 0; }
.head-text h1 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.3; word-break: break-word; }
.head-sub { margin: 2px 0 0; color: var(--fg-muted); font-size: 13px; word-break: break-word; }
.head-sub a { color: inherit; }

.icon-btn {
  flex: 0 0 auto; width: 32px; height: 32px; padding: 0;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--fg-muted); cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--fg); }
.icon-btn:disabled { opacity: .45; cursor: default; background: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 20px; white-space: nowrap;
  background: var(--bg-sunken); color: var(--fg-muted); border: 1px solid var(--border);
}
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.chip-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; margin: 12px 0 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto; padding: 8px 12px 10px; border: 0; background: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  color: var(--fg-muted); font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.tab:hover:not(:disabled) { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.tab:disabled { color: var(--fg-faint); cursor: default; }
.tab .dot { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--fg-faint); margin-left: 5px; vertical-align: middle; }

/* ---------- body ---------- */
.body { flex: 1 1 auto; overflow-y: auto; padding: 16px; background: var(--bg-sunken); }
.section + .section { margin-top: 16px; }
.section-title { margin: 0 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--fg-faint); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 8px; }
.card-pad { padding: 12px 14px; }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.stat-v { font-size: 20px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-l { margin-top: 2px; font-size: 12px; color: var(--fg-muted); }

/* activity feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--border); }
.feed li:first-child { border-top: 0; }
.feed-mark { flex: 0 0 auto; width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: var(--border-strong); }
.feed-mark.is-created { background: var(--accent); }
.feed-mark.is-done { background: var(--ok); }
.feed-body { min-width: 0; flex: 1 1 auto; }
.feed-what { font-size: 13px; }
.feed-what .what { color: var(--fg-muted); }
.feed-when { font-size: 12px; color: var(--fg-faint); margin-top: 1px; }

/* item list */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.filter { padding: 4px 11px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--fg-muted); font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
.filter[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.item { width: 100%; text-align: left; }
.item-head { display: flex; gap: 10px; align-items: flex-start; width: 100%; padding: 12px 14px; background: none; border: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.item-head:hover { background: var(--bg-sunken); }
.item-main { flex: 1 1 auto; min-width: 0; }
.item-name { font-size: 13px; font-weight: 500; line-height: 1.45; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.item-caret { flex: 0 0 auto; color: var(--fg-faint); font-size: 11px; margin-top: 3px; transition: transform .15s ease; }
.item[open] .item-caret, .item-head[aria-expanded="true"] .item-caret { transform: rotate(90deg); }

.detail { padding: 0 14px 14px; border-top: 1px solid var(--border); margin-top: 0; padding-top: 12px; }
.detail dl { margin: 0; display: grid; grid-template-columns: minmax(80px, auto) 1fr; gap: 4px 12px; font-size: 13px; }
.detail dt { color: var(--fg-muted); }
.detail dd { margin: 0; min-width: 0; word-break: break-word; }
.detail .desc { margin: 10px 0 0; font-size: 13px; color: var(--fg-muted); white-space: pre-wrap; word-break: break-word; }
.detail .sub { margin: 12px 0 6px; font-size: 12px; font-weight: 600; color: var(--fg-faint); text-transform: uppercase; letter-spacing: .04em; }

.trail { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.trail li { display: flex; gap: 8px; padding: 3px 0; }
.trail .when { flex: 0 0 auto; color: var(--fg-faint); font-variant-numeric: tabular-nums; }

.peers { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }

.actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--fg); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--bg-sunken); }

/* empty / message states */
.empty { padding: 28px 20px; text-align: center; color: var(--fg-muted); }
.empty h3 { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--fg); }
.empty p { margin: 0 auto; max-width: 42ch; font-size: 13px; line-height: 1.6; }
.empty .mark { font-size: 22px; display: block; margin-bottom: 10px; opacity: .5; }

.note { font-size: 12px; color: var(--fg-faint); line-height: 1.55; margin: 8px 2px 0; }

.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--bg-sunken) 37%, var(--border) 63%); background-size: 400% 100%; animation: sh 1.2s ease infinite; border-radius: var(--radius-sm); }
@keyframes sh { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .item-caret { transition: none; } }

.hidden { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.detail .desc.is-clamped { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.detail .more { margin-top: 4px; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
.detail .more:hover { text-decoration: underline; }

.chip-wrap { white-space: normal; text-align: left; line-height: 1.35; padding-top: 3px; padding-bottom: 3px; }

/* ---------- Zendesk ticket rows ----------
   A ticket row is a feed row with chips and, later, a summary paragraph under it. */
.feed-what a { color: inherit; text-decoration: none; font-variant-numeric: tabular-nums; }
.feed-what a:hover { text-decoration: underline; }
.feed-body .item-meta { margin-top: 6px; }
.feed-body .chip { margin-right: 4px; }
.feed-what .chip { margin-left: 6px; vertical-align: baseline; }
.feed-body .note { margin: 6px 0 0; }

/* ---------- summary slot ---------- */
.summary-slot { margin-top: 6px; }
.note.summary { color: var(--fg, inherit); }
.note.subtle { opacity: .7; font-style: italic; }
.mini-btn {
  font: inherit; font-size: 12px; line-height: 1;
  padding: 5px 10px; margin-top: 2px;
  border: 1px solid var(--line, #d8dee7); border-radius: 999px;
  background: transparent; color: inherit; cursor: pointer;
}
.mini-btn:hover:not(:disabled) { background: var(--hover, rgba(0,0,0,.04)); }
.mini-btn:disabled { opacity: .55; cursor: default; }
