/* Admin console. Plain CSS, no external assets (the CSP allows only 'self').
   --brand is the tenant's primary colour, set from branding at runtime. */

:root {
  --brand: #0a3d62;
  --brand-soft: color-mix(in srgb, var(--brand) 9%, #fff);
  --brand-ring: color-mix(in srgb, var(--brand) 28%, transparent);

  --bg: #f4f5f7;
  --surface: #fff;
  --surface-2: #f8f9fb;
  --fg: #111827;
  --fg-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;

  --ok: #067647;  --ok-bg: #ecfdf3;  --ok-line: #abefc6;
  --warn: #a15c07; --warn-bg: #fffaeb; --warn-line: #fedf89;
  --bad: #b42318; --bad-bg: #fef3f2; --bad-line: #fecdca;
  --info: #175cd3; --info-bg: #eff8ff;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18), 0 4px 8px -4px rgba(16, 24, 40, .06);
  --sidebar: 248px;
  --topbar: 56px;

  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  font: 14px/1.5 var(--sans);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
::selection { background: var(--brand-ring); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

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

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

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
  z-index: 30;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar); padding: 0 16px; flex: none;
  border-bottom: 1px solid var(--line); color: var(--fg);
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand div, .auth-brand div { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sidebar-brand strong, .auth-brand strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-brand span, .auth-brand span { font-size: 12px; color: var(--muted); }

.mark {
  display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--brand); color: #fff;
  font-size: 13px; font-weight: 700; letter-spacing: .02em;
}
.mark.logo { background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.mark.logo img { width: 100%; height: 100%; object-fit: contain; }

.sidebar nav { flex: 1; overflow-y: auto; padding: 8px 10px 24px; overscroll-behavior: contain; }
.nav-group { margin-top: 14px; }
.nav-label {
  padding: 0 10px 6px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: #9ca3af;
}
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  height: 34px; padding: 0 10px; margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--fg-2); font-weight: 500;
}
.sidebar nav a .icon { color: #9ca3af; }
.sidebar nav a:hover { background: var(--surface-2); color: var(--fg); text-decoration: none; }
.sidebar nav a:hover .icon { color: var(--fg-2); }
.sidebar nav a.active { background: var(--brand-soft); color: var(--brand); }
.sidebar nav a.active .icon { color: var(--brand); }

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

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar); padding: 0 28px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.crumbs { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; font-size: 14px; }
.crumbs span { color: var(--muted); }
.crumbs span::after { content: "/"; margin-left: 8px; color: var(--line-strong); }
.crumbs strong { font-weight: 600; }

.user { display: flex; align-items: center; gap: 10px; }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  font-size: 12px; font-weight: 700;
}
.user-text { display: flex; flex-direction: column; line-height: 1.25; }
.user-text strong { font-size: 13px; font-weight: 600; }
.user-text span { font-size: 12px; color: var(--muted); white-space: nowrap; }

.icon-button {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
}
.icon-button:hover:not(:disabled) { background: var(--surface-2); border-color: var(--line); color: var(--fg); filter: none; }
.icon-button.menu { display: none; }
.scrim { display: none; }

.page { width: 100%; max-width: 1240px; padding: 28px 32px 64px; }

.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 24px 0; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ type */

h1, h2, h3, h4 { color: var(--fg); letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 650; margin: 0 0 6px; }
h2 { font-size: 22px; line-height: 1.3; font-weight: 650; margin: 0 0 6px; }
.page > h2 { margin-bottom: 18px; }
.page > h2:has(+ p.muted) { margin-bottom: 4px; }
.page > h2 + p.muted { margin: 0 0 22px; max-width: 78ch; }
h3 {
  font-size: 15px; font-weight: 600; margin: 32px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
h4 { font-size: 13px; font-weight: 600; margin: 16px 0 8px; color: var(--fg-2); }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small, .muted.small { font-size: 12.5px; }
.error { color: var(--bad); font-weight: 500; }
code {
  font: 12px/1.4 var(--mono); word-break: break-all;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; color: var(--fg-2);
}
pre {
  font: 12.5px/1.55 var(--mono);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; overflow: auto; max-height: 560px; box-shadow: var(--shadow); margin: 8px 0;
}
pre code { border: 0; background: none; padding: 0; }

/* Back links ("← Products") at the top of a detail page. */
.page > button.link:first-child { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 500; }
.page > button.link:first-child:hover { color: var(--brand); }

/* ------------------------------------------------------------ controls */

button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px;
  font: 500 13.5px/1 var(--sans); white-space: nowrap;
  color: #fff; background: var(--brand);
  border: 1px solid var(--brand); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); cursor: pointer;
  transition: filter .12s, background-color .12s, border-color .12s, box-shadow .12s;
}
button .icon { width: 16px; height: 16px; }
button:hover:not(:disabled) { filter: brightness(.92); }
button:active:not(:disabled) { filter: brightness(.85); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.block { width: 100%; height: 40px; font-size: 14px; }
button.secondary { background: var(--surface); color: var(--fg-2); border-color: var(--line-strong); }
button.secondary:hover:not(:disabled) { background: var(--surface-2); filter: none; }
button.link {
  height: auto; padding: 0; background: none; border: none; box-shadow: none;
  color: var(--brand); font-weight: 500;
}
button.link:hover:not(:disabled) { text-decoration: underline; filter: none; }
button.danger { background: var(--surface); color: var(--bad); border-color: var(--bad-line); }
button.danger:hover:not(:disabled) { background: var(--bad-bg); filter: none; }

input, select, textarea {
  font: 14px/1.4 var(--sans); color: var(--fg);
  min-height: 34px; padding: 6px 10px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  transition: border-color .12s, box-shadow .12s;
  max-width: 100%;
}
input::placeholder, textarea::placeholder { color: #9ca3af; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
select {
  appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
textarea { width: 100%; font: 12.5px/1.55 var(--mono); padding: 10px 12px; resize: vertical; }
input[type="checkbox"], input[type="radio"] {
  min-height: 0; width: 16px; height: 16px; padding: 0; margin: 0;
  box-shadow: none; accent-color: var(--brand);
}
input[type="file"] { padding: 5px 8px; }
input[type="file"]::file-selector-button {
  font: 500 13px var(--sans); margin-right: 10px; padding: 4px 10px;
  border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface-2); color: var(--fg-2); cursor: pointer;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--fg-2); }
.inline .field, .form.inline .field { flex-direction: row; align-items: center; gap: 8px; }
.inline .field > span, .form.inline .field > span { color: var(--muted); font-weight: 500; }

/* A block form is a card; inline forms are toolbars. */
.form {
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
  margin: 12px 0; padding: 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.form > input:not([type="checkbox"]):not([type="radio"]), .form > select, .form > .field { width: min(100%, 520px); }
.form > .field input, .form > .field select { width: 100%; }
.form > textarea { width: 100%; }
.form:empty { display: none; }
.form.plain, details > .form, .form .form, .card .form { padding: 0; border: 0; box-shadow: none; background: none; }
.inline, .form.inline, .actions {
  display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 10px 0; padding: 0; background: none; border: 0; box-shadow: none;
}
.form.inline > input, .form.inline > select { width: auto; }
.actions:empty, .inline:empty { display: none; }
.actions { margin: 16px 0; }
td .inline { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); font-size: 13px; cursor: pointer; user-select: none;
}
.check:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

/* ------------------------------------------------------------ status */

.status {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 12px 0; padding: 10px 14px;
  border: 1px solid var(--line); border-left-width: 3px; border-radius: var(--radius-sm);
  background: var(--surface); white-space: pre-wrap; overflow-wrap: anywhere;
}
.status:empty { display: none; }
.status.ok { color: #054f31; background: var(--ok-bg); border-color: var(--ok-line); border-left-color: var(--ok); }
.status.error { color: #7a271a; background: var(--bad-bg); border-color: var(--bad-line); border-left-color: var(--bad); }
td .status { margin: 6px 0 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap; line-height: 1;
  background: #f2f4f7; color: #344054; border: 1px solid #e4e7ec;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }
.badge.neutral::before { background: #98a2b3; }
.with-badge { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }

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

.table-wrap {
  margin: 10px 0; overflow-x: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 11px 16px; vertical-align: middle; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
th {
  background: var(--surface-2); color: var(--muted);
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}
tbody tr { transition: background-color .1s; }
.table-wrap:not(.kv) tbody tr:hover { background: #fafbfc; }
/* An unlabelled last column holds row actions: aligned right. */
table:has(thead th:last-child:empty) td:last-child { text-align: right; }
table:has(thead th:last-child:empty) td:last-child > .inline { justify-content: flex-end; }
td input:not([type="checkbox"]), td select { min-height: 30px; padding: 4px 8px; font-size: 13px; }
td button:not(.link) { height: 30px; padding: 0 10px; font-size: 12.5px; }
table table { border: 1px solid var(--line); }

/* Key–value tables: a label column and a value column. */
.table-wrap.kv td { padding: 10px 16px; }
.table-wrap.kv td:first-child { width: 240px; color: var(--muted); font-weight: 500; font-size: 13px; background: var(--surface-2); border-right: 1px solid var(--line); }
.table-wrap.kv td:last-child { text-align: left; }

/* Facts: a definition list in a card. */
dl.facts {
  display: grid; grid-template-columns: minmax(140px, 220px) 1fr;
  margin: 10px 0; padding: 0; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
dl.facts dt, dl.facts dd { margin: 0; padding: 10px 16px; border-bottom: 1px solid var(--line); }
dl.facts dt { color: var(--muted); font-weight: 500; font-size: 13px; background: var(--surface-2); border-right: 1px solid var(--line); }
dl.facts dt:last-of-type, dl.facts dd:last-of-type { border-bottom: 0; }

.card {
  margin: 14px 0; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card .table-wrap { box-shadow: none; }

/* Collapsible panels ("New product", "Add a member"). */
details {
  margin: 16px 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
details > summary {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; cursor: pointer; list-style: none;
  font-weight: 600; color: var(--fg); user-select: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ""; width: 7px; height: 7px; flex: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s; margin-right: 2px;
}
details[open] > summary::before { transform: rotate(45deg); }
details > summary:hover { background: var(--surface-2); border-radius: var(--radius); }
details[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
details > :not(summary) { margin-left: 16px; margin-right: 16px; }
details > :last-child:not(summary) { margin-bottom: 16px; }
details > .form, details > .inline { margin-top: 14px; }
details details { box-shadow: none; }

/* Branding preview. */
.preview { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; max-width: 420px; box-shadow: var(--shadow); }
.preview-bar { color: #fff; padding: 12px 16px; font-weight: 600; }
.preview p { padding: 0 16px; }

/* ------------------------------------------------------------ sign-in */

.auth {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 16px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; padding: 32px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth-brand .mark { width: 40px; height: 40px; font-size: 15px; border-radius: 10px; }
.auth-card h1 { font-size: 20px; }
.auth-card > p.muted { margin: 0 0 22px; }
.auth-card .form.plain { margin: 0; align-items: stretch; gap: 14px; }
.auth-card .form.plain .field, .auth-card .form.plain input { width: 100%; }
.auth-card .status { margin-top: 16px; }
.auth-foot { margin-top: 18px; font-size: 12.5px; color: var(--muted); }

/* ------------------------------------------------------------ narrow screens */

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 272px;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  .nav-open .sidebar { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 25; }
  .icon-button.menu { display: inline-grid; margin-left: -8px; }
  .topbar { padding: 0 16px; }
  .page { padding: 20px 16px 48px; }
  .user-text { display: none; }
  .table-wrap.kv td:first-child, dl.facts { grid-template-columns: 1fr; }
  .table-wrap.kv td:first-child { width: 38%; }
  dl.facts dt { border-right: 0; border-bottom: 0; padding-bottom: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { transition: none !important; animation-duration: 1.5s !important; }
}

/* Per-row tool panels (e.g. an investor's review tools). */
.row-tools { display: flex; align-items: flex-start; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
details.row-panel { margin: 0; box-shadow: none; text-align: left; }
details.row-panel > summary { padding: 0 12px; height: 30px; font-size: 12.5px; font-weight: 500; color: var(--fg-2); }
details.row-panel[open] { flex-basis: 100%; order: 2; }
details.row-panel > .panel-grid {
  display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; align-items: center;
  margin: 12px 14px 14px;
}
.panel-label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.panel-grid .inline { margin: 0; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: #b2ddff; }
.page > .field { align-items: flex-start; margin: 0 0 4px; }
td select { padding-right: 28px; }
input[type="number"] { width: 96px; }
.card.work { display: flex; flex-direction: column; gap: 12px; }
.card.work > .field, .card.work > .field textarea, .card.work > .field input { width: 100%; }
.card.work > h3 { margin: 12px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }
.card.work > .form.inline, .card.work > p { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 4px; background: #f2f4f7; color: var(--fg-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
