/* ---------- theme: neutral zinc, near-black accent ---------- */
:root {
  --sl-font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --sl-color-primary-50: #fafafa; --sl-color-primary-100: #f4f4f5; --sl-color-primary-200: #e4e4e7;
  --sl-color-primary-300: #a1a1aa; --sl-color-primary-400: #52525b; --sl-color-primary-500: #27272a;
  --sl-color-primary-600: #18181b; --sl-color-primary-700: #09090b; --sl-color-primary-800: #09090b;
  --sl-color-primary-900: #09090b; --sl-color-primary-950: #09090b;
  --sl-input-border-radius-small: 6px; --sl-input-border-radius-medium: 7px; --sl-input-border-radius-large: 8px;
  --sl-input-border-color: #e4e4e7; --sl-input-border-color-hover: #d4d4d8;
  --sl-focus-ring-color: rgba(24, 24, 27, .18);
  --sl-input-focus-ring-color: rgba(24, 24, 27, .12);

  --bg: #ffffff;
  --surface: #ffffff;
  --subtle: #fafafa;
  --hover: #f4f4f5;
  --border: #e4e4e7;
  --text: #09090b;
  --muted: #71717a;
  --radius: 10px;
  color-scheme: light;
}
:root.sl-theme-dark {
  --sl-color-primary-50: #18181b; --sl-color-primary-100: #27272a; --sl-color-primary-200: #3f3f46;
  --sl-color-primary-300: #71717a; --sl-color-primary-400: #d4d4d8; --sl-color-primary-500: #e4e4e7;
  --sl-color-primary-600: #fafafa; --sl-color-primary-700: #ffffff; --sl-color-primary-800: #ffffff;
  --sl-color-primary-900: #ffffff; --sl-color-primary-950: #ffffff;
  --sl-input-border-color: #27272a; --sl-input-border-color-hover: #3f3f46;
  --sl-input-background-color: #09090b;
  --sl-focus-ring-color: rgba(250, 250, 250, .2);
  --sl-input-focus-ring-color: rgba(250, 250, 250, .12);

  --bg: #09090b;
  --surface: #09090b;
  --subtle: #111113;
  --hover: #18181b;
  --border: #27272a;
  --text: #fafafa;
  --muted: #a1a1aa;
  color-scheme: dark;
}

:not(:defined) { visibility: hidden; }
/* Shoelace hosts set their own display, which beats the browser's [hidden] rule */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sl-font-sans); font-size: 14px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1 1 240px; min-width: 0; }
.full { width: 100%; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

.brand-mark {
  width: 24px; height: 24px; border-radius: 6px; display: inline-grid; place-items: center; flex-shrink: 0;
  background: var(--text); color: var(--bg); font-size: 13px;
}

.tag {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px;
  border: 1px solid var(--border); font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap;
}

/* status: small dot + label, colour only where it means something */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .6; }
.status.ok { color: #16a34a; }
.status.warn { color: #d97706; }
.status.bad { color: #dc2626; }
.status.busy::before { display: none; }
.status sl-spinner { font-size: 11px; --track-width: 2px; --indicator-color: var(--muted); }

/* ---------- login / error ---------- */
.login-bg { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--subtle); }
.login-wrap { width: 100%; max-width: 360px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; margin-bottom: 20px; }
.login-card { padding: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 16px; }
.login-card h2 { font-size: 17px; }
.login-card p { margin: -10px 0 0; font-size: 13.5px; }
.code-input::part(input) { text-align: center; letter-spacing: .5em; font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; }
#login-error { margin-top: 14px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 16px; }

.error-card { max-width: 400px; width: 100%; }
.error-code { font-size: 44px; font-weight: 600; letter-spacing: -.03em; line-height: 1; color: var(--muted); }

/* ---------- app layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--subtle); border-right: 1px solid var(--border); padding: 12px 10px;
}
.sidebar-brand { display: flex; align-items: center; gap: 9px; padding: 6px 8px 16px; font-weight: 600; }
.sidebar-label { font-size: 12px; color: var(--muted); padding: 8px 8px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 6px; margin-bottom: 1px;
  color: var(--muted); transition: background .12s, color .12s;
}
.nav-item sl-icon { font-size: 15px; }
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--hover); color: var(--text); font-weight: 500; }
.sidebar-scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 24px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }
.nav-toggle { display: none; font-size: 18px; }
.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 3px 8px 3px 3px; border-radius: 7px;
  border: 0; background: none; color: var(--text); cursor: pointer; font: inherit;
}
.user-chip:hover { background: var(--hover); }
.user-chip sl-avatar { --size: 24px; font-size: 11px; }
.user-chip sl-icon { color: var(--muted); font-size: 12px; }
.user-email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.content { padding: 32px; max-width: 1120px; width: 100%; margin: 0 auto; }

@media (max-width: 960px) {
  .sidebar { position: fixed; z-index: 40; left: 0; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; }
  .sidebar.open + .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .3); }
  .nav-toggle { display: inline-flex; }
  .content { padding: 20px 16px; }
  .topbar { padding: 0 12px; }
  .user-email { display: none; }
}

/* ---------- page header + stats ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 4px 0 0; }

.stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 24px;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.stat { padding: 14px 18px; }
.stat + .stat { border-left: 1px solid var(--border); }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 20px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-value sl-skeleton { width: 40px; height: 20px; margin-top: 4px; }
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr; }
  .stat + .stat { border-left: 0; border-top: 1px solid var(--border); }
}

/* ---------- home ---------- */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.agent-card { display: flex; gap: 12px; align-items: center; padding: 16px; transition: background .12s, border-color .12s; }
.agent-card:hover { background: var(--subtle); border-color: #d4d4d8; }
.agent-card h3 { font-size: 14.5px; margin-bottom: 2px; }
.agent-card p { margin: 0; font-size: 13px; }
.agent-card-arrow { margin-left: auto; color: var(--muted); }

/* ---------- tabs ---------- */
.tabs-panel { border: 0; }
/* Shoelace places its sliding indicator by summing the preceding tabs' widths, which
   ignores the gap between tabs. Hide it and underline the active tab directly instead. */
.tabs-panel sl-tab-group { --indicator-color: transparent; --track-color: var(--border); --track-width: 1px; }
.tabs-panel sl-tab { margin-right: 20px; }
.tabs-panel sl-tab::part(base) { padding: 10px 0; font-size: 13.5px; box-shadow: inset 0 -2px 0 transparent; transition: box-shadow .12s; }
.tabs-panel sl-tab[active]::part(base) { color: var(--text); box-shadow: inset 0 -2px 0 var(--text); }
.tabs-panel sl-tab-panel::part(base) { padding: 20px 0 0; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 12.5px; font-weight: 500; color: var(--muted);
  padding: 9px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--subtle); }
.data-table tr.is-selected { background: var(--hover); }
.data-table sl-icon-button { font-size: 15px; color: var(--muted); }
.col-check, .col-action { width: 1%; }
.table-msg { text-align: center; padding: 40px 16px !important; color: var(--muted); }
.table-foot { padding: 10px 2px 0; font-size: 12.5px; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.file-icon { display: grid; place-items: center; font-size: 16px; color: var(--muted); flex-shrink: 0; }
.name-main { font-weight: 500; word-break: break-word; }
.name-sub { font-size: 12px; color: var(--muted); word-break: break-all; }
@media (max-width: 720px) { .hide-sm { display: none; } }

/* ---------- add content ---------- */
.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
@media (max-width: 900px) { .add-grid { grid-template-columns: 1fr; } }
.section-title { font-size: 14px; margin-bottom: 12px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; cursor: pointer;
  padding: 28px 16px; border: 1px dashed #d4d4d8; border-radius: var(--radius); color: var(--text);
  transition: border-color .12s, background .12s;
}
.sl-theme-dark .dropzone { border-color: #3f3f46; }
.dropzone:hover, .dropzone.is-dragover { border-color: var(--muted); background: var(--subtle); }
.dropzone-icon { font-size: 18px; color: var(--muted); margin-bottom: 4px; }
.file-list { list-style: none; margin: 8px 0 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.file-list li .fname { flex: 1; word-break: break-all; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.form-row.end { justify-content: flex-end; margin-top: 0; }
sl-divider { --spacing: 28px; --color: var(--border); }

.recent-list { display: flex; flex-direction: column; }
.recent-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.recent-item:last-child { border-bottom: 0; }
.recent-item .meta { flex: 1; min-width: 0; }

/* ---------- search ---------- */
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.k-select { width: 140px; }
.results { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.result-card { padding: 14px 16px; transition: border-color .12s; }
.result-card.is-selected { border-color: #dc2626; }
.result-top { display: flex; gap: 10px; align-items: flex-start; }
.result-top .meta { flex: 1; min-width: 0; }
.result-content { margin-top: 10px; white-space: pre-wrap; line-height: 1.6; max-height: 8em; overflow: hidden; position: relative; color: var(--text); font-size: 13.5px; }
.result-content.clamped::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2.4em; background: linear-gradient(transparent, var(--surface)); }
.result-content.expanded { max-height: none; }
.result-content.expanded::after { display: none; }
.result-content mark { background: rgba(250, 204, 21, .35); color: inherit; border-radius: 2px; padding: 0 1px; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 44px 20px; }
.empty > sl-icon { font-size: 22px; color: var(--muted); margin-bottom: 4px; }
.empty h3 { font-size: 14.5px; }
.empty p { margin: 0; max-width: 400px; font-size: 13.5px; }

/* ---------- delete tray + dialog ---------- */
.delete-tray {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0, 0, 0, .08);
  max-width: calc(100vw - 32px); font-size: 13px;
}
.delete-tray[hidden] { display: none; }
body.has-tray .content { padding-bottom: 96px; }

.delete-dialog { --width: 520px; }
.delete-dialog::part(panel) { border-radius: 12px; }
.dialog-intro { margin: 0; font-size: 13.5px; }
.delete-list { list-style: none; padding: 0; margin: 14px 0; max-height: 300px; overflow-y: auto; border-top: 1px solid var(--border); }
.delete-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.delete-list li .meta { flex: 1; min-width: 0; }
