/* AgentMem web console.
 *
 * Hand-written because the server's CSP is `default-src 'self'` with no
 * `unsafe-inline`: every rule has to live in this file, since a `style=`
 * attribute is silently dropped by the browser.
 *
 * Layout is an app shell — a permanently dark sidebar next to a themed
 * content column — so the console reads as a tool rather than a document.
 * The sidebar keeps its dark palette in both themes on purpose: it is
 * chrome, not content, and the constant anchor makes the content area's
 * light/dark switch feel deliberate.
 */

:root {
  color-scheme: light dark;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-hover: #f5f7f9;
  --border: #e3e7ec;
  --border-strong: #d0d7de;
  --text: #10151c;
  --text-muted: #5f6b7a;
  --text-faint: #8a95a3;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef1fe;
  --accent-ring: rgba(79, 70, 229, 0.22);
  --on-accent: #ffffff;

  --ok-bg: #e6f6ed;
  --ok-fg: #0b7a43;
  --warn-bg: #fdf0da;
  --warn-fg: #93610b;
  --neutral-bg: #eceff3;
  --neutral-fg: #58636f;
  --danger-bg: #fdeceb;
  --danger-fg: #b42318;
  --danger-border: #f5c6c2;

  --sidebar-bg: #141922;
  --sidebar-raised: #1d2431;
  --sidebar-text: #c3ccd8;
  --sidebar-strong: #ffffff;
  --sidebar-muted: #788495;
  --sidebar-border: #252d3a;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(16, 21, 28, 0.05), 0 1px 3px rgba(16, 21, 28, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 21, 28, 0.07), 0 1px 3px rgba(16, 21, 28, 0.05);
  --shadow-lg: 0 16px 40px rgba(16, 21, 28, 0.14), 0 2px 8px rgba(16, 21, 28, 0.06);

  --sidebar-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1a212a;
    --surface-hover: #1e252f;
    --border: #262d38;
    --border-strong: #333c49;
    --text: #e5edf5;
    --text-muted: #97a3b2;
    --text-faint: #717d8c;

    --accent: #7c74f2;
    --accent-hover: #8f88f5;
    --accent-soft: #1e2140;
    --accent-ring: rgba(124, 116, 242, 0.3);
    --on-accent: #ffffff;

    --ok-bg: #10301f;
    --ok-fg: #56d394;
    --warn-bg: #34260c;
    --warn-fg: #e0a83c;
    --neutral-bg: #222a34;
    --neutral-fg: #9aa5b1;
    --danger-bg: #3a1a19;
    --danger-fg: #f28b82;
    --danger-border: #5c2b28;

    --sidebar-bg: #0b0f15;
    --sidebar-raised: #161d27;
    --sidebar-border: #1e2530;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Inline SVG has no intrinsic size, so an icon with no rule of its own
 * falls back to the 300x150 replaced-element default and blows the layout
 * apart. Every icon gets a sane default here; the few larger marks
 * override it below. */
svg {
  width: 16px;
  height: 16px;
  flex: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 15px;
}

p {
  margin: 0;
}

/* ---------------------------------------------------------------- shell */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 22px;
  color: var(--sidebar-strong);
}

.brand__mark {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(140deg, #6366f1, #8b5cf6 55%, #a855f7);
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.4);
}

.brand__mark svg {
  width: 17px;
  height: 17px;
  color: #fff;
}

.brand__name {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.brand__sub {
  display: block;
  font-size: 11px;
  font-weight: 450;
  color: var(--sidebar-muted);
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  padding: 0 8px 8px;
}

.nav__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.13s ease, color 0.13s ease;
}

.nav__link svg {
  width: 16px;
  height: 16px;
  flex: none;
  opacity: 0.75;
}

.nav__link:hover {
  background: var(--sidebar-raised);
  color: var(--sidebar-strong);
  text-decoration: none;
}

.nav__link[aria-current="page"] {
  background: var(--sidebar-raised);
  color: var(--sidebar-strong);
  box-shadow: inset 2px 0 0 var(--accent);
}

.nav__link[aria-current="page"] svg {
  opacity: 1;
  color: #a5a0f8;
}

.sidebar__foot {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--sidebar-border);
}

.who {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 12px;
  min-width: 0;
}

.who__avatar {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--sidebar-raised);
  color: #b9c2ce;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  border: 1px solid var(--sidebar-border);
}

.who__text {
  min-width: 0;
}

.who__email {
  display: block;
  font-size: 12.5px;
  color: var(--sidebar-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.who__role {
  display: block;
  font-size: 11px;
  color: var(--sidebar-muted);
}

.sidebar__foot .btn {
  width: 100%;
  justify-content: center;
  background: transparent;
  border-color: var(--sidebar-border);
  color: var(--sidebar-text);
}

.sidebar__foot .btn:hover {
  background: var(--sidebar-raised);
  color: var(--sidebar-strong);
  border-color: #333c4a;
}

/* ----------------------------------------------------------------- main */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar__sub {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-muted);
}

.topbar__meta {
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 7px;
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex: none;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16);
}

.content {
  padding: 24px 28px 48px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 1400px;
  width: 100%;
}

/* ---------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
}

.stat__label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat__label svg {
  width: 14px;
  height: 14px;
  color: var(--text-faint);
}

.stat__value {
  margin-top: 6px;
  font-size: 26px;
  font-weight: 620;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.stat__hint {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.stat--attention .stat__value {
  color: var(--warn-fg);
}

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 13px 17px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.card__title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card__title svg {
  width: 15px;
  height: 15px;
  color: var(--text-faint);
  flex: none;
}

.card__note {
  font-size: 12px;
  color: var(--text-faint);
}

.card__body {
  padding: 17px;
}

.card__body > * + * {
  margin-top: 14px;
}

/* --------------------------------------------------------------- tables */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  font-weight: 550;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface-2);
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  /* Cell text is already length-capped where it can be long (paths are
   * middle-truncated, stems clipped), so wrapping only ever produced
   * ragged two-line cells and, in the narrowest column, near-vertical
   * text. The table scrolls inside .table-wrap instead. */
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--surface-hover);
}

td.num {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.mono--dim {
  color: var(--text-muted);
}

.chip-id {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--neutral-bg);
  border-radius: 5px;
  padding: 2px 6px;
}

/* --------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 550;
  line-height: 1.5;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--neutral-bg);
  color: var(--neutral-fg);
}

.badge--ok {
  background: var(--ok-bg);
  color: var(--ok-fg);
}

.badge--warn {
  background: var(--warn-bg);
  color: var(--warn-fg);
}

.badge--danger {
  background: var(--danger-bg);
  color: var(--danger-fg);
}

.badge--accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* -------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.4;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.13s ease, border-color 0.13s ease, box-shadow 0.13s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-faint);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--sm {
  font-size: 12px;
  padding: 5px 10px;
}

.btn--block {
  width: 100%;
  justify-content: center;
  padding: 9px 14px;
}

/* ---------------------------------------------------------------- forms */

.field {
  display: block;
}

.field + .field {
  margin-top: 14px;
}

.field__label {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text);
  margin-bottom: 5px;
}

.field__hint {
  display: block;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-faint);
  margin-top: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  transition: border-color 0.13s ease, box-shadow 0.13s ease;
}

select {
  appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.filters {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.filters .field {
  min-width: 170px;
}

.filters .field--grow {
  flex: 1 1 300px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* --------------------------------------------------------------- alerts */

.alert {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid transparent;
}

.alert svg {
  width: 15px;
  height: 15px;
  flex: none;
  margin-top: 2px;
}

.alert--error {
  background: var(--danger-bg);
  color: var(--danger-fg);
  border-color: var(--danger-border);
}

.alert--ok {
  background: var(--ok-bg);
  color: var(--ok-fg);
  border-color: transparent;
}

.alert--info {
  background: var(--accent-soft);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ---------------------------------------------------------- empty state */

.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty svg {
  width: 26px;
  height: 26px;
  color: var(--text-faint);
  opacity: 0.6;
}

.empty__title {
  margin-top: 9px;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text);
}

.empty__hint {
  margin-top: 3px;
  font-size: 12.5px;
}

/* ------------------------------------------------------------- disclose */

details.disclose > summary {
  list-style: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 550;
  color: var(--accent);
  padding: 4px 0;
  user-select: none;
}

details.disclose > summary::-webkit-details-marker {
  display: none;
}

details.disclose > summary:hover {
  text-decoration: underline;
}

details.disclose[open] > summary {
  color: var(--text-muted);
}

.disclose__panel {
  display: flex;
  gap: 7px;
  align-items: center;
  margin-top: 7px;
  padding: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.disclose__panel select {
  min-width: 130px;
  font-size: 12.5px;
  padding: 5px 26px 5px 9px;
}

/* --------------------------------------------------------------- layout */

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
  align-items: start;
}

.kv {
  display: grid;
  grid-template-columns: minmax(88px, auto) 1fr;
  gap: 8px 16px;
  font-size: 13px;
}

.kv dt {
  color: var(--text-muted);
}

.kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--text-muted);
}

.faint {
  color: var(--text-faint);
  font-size: 12px;
}

/* ---------------------------------------------------------------- login */

.login {
  min-height: 100vh;
  /* Explicit, rather than relying on being a block-level child of a plain
   * body: an earlier revision also put this class on <body>, which made
   * this element a grid item and shrink-to-fit, collapsing the page into a
   * narrow centred strip. */
  width: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  background-image: radial-gradient(
      circle at 15% 0%,
      rgba(99, 102, 241, 0.13),
      transparent 45%
    ),
    radial-gradient(circle at 88% 105%, rgba(168, 85, 247, 0.13), transparent 45%);
}

.login__card {
  width: 100%;
  max-width: 388px;
}

.login__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  text-align: center;
}

.login__mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #6366f1, #8b5cf6 55%, #a855f7);
  box-shadow: 0 8px 22px rgba(99, 102, 241, 0.35);
}

.login__mark svg {
  width: 25px;
  height: 25px;
  color: #fff;
}

.login__title {
  font-size: 19px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.login__tagline {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.login__panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 26px 24px;
}

.login__panel .btn--block {
  margin-top: 20px;
}

.login__foot {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.7;
}

.login .alert {
  margin-bottom: 16px;
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
  }

  .brand {
    padding: 0;
  }

  .nav {
    flex-direction: row;
    flex: 1 1 auto;
    gap: 4px;
  }

  .nav__label {
    display: none;
  }

  .sidebar__foot {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .who {
    padding: 0;
  }

  .who__text {
    display: none;
  }

  .topbar,
  .content {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (max-width: 560px) {
  .brand__sub {
    display: none;
  }

  .nav__link span {
    display: none;
  }

  .nav__link {
    padding: 8px;
  }
}
