/*
 * compono-ui: the shared look of the web clients (PageClient, Studio, Admin Center).
 * Served at /ui/compono-ui.css by every server that links Compono.Ui/UiAssets.cs.
 *
 * One calm, neutral surface with a single accent (BIZZCORE petrol). Light and dark tokens; the theme follows the system
 * unless <html data-theme="light|dark"> sets it. <html data-density="compact"> makes rows and controls lower.
 */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ------------------------------------------------ tokens */
:root {
  color-scheme: light;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --sidebar: #fbfcfd;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --line: #eef0f3;
  --text: #111827;
  --muted: #556070;
  --subtle: #8a94a3;
  --accent: #17769d;
  --accent-hover: #125f7f;
  --accent-soft: #e6f2f7;
  --accent-text: #0f5a78;
  --on-accent: #ffffff;
  --ok: #15803d;
  --ok-soft: #e8f5ec;
  --warn: #b45309;
  --warn-soft: #fdf3e4;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --row-hover: #f5f7fa;
  --selected: #e8f2f7;
  --selected-hover: #dcebf3;
  --backdrop: rgba(17, 24, 39, .32);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 12px rgba(16, 24, 40, .10);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, .18);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --control-h: 32px;
  --row-h: 36px;
  --sidebar-w: 240px;
}

/* Dark: by the system (unless the light theme is chosen) or chosen. Both blocks hold the same values. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1317; --surface: #141b21; --surface-2: #1a232a; --sidebar: #10171c;
    --border: #25303a; --border-strong: #34424e; --line: #1e2830;
    --text: #e8edf2; --muted: #9eaab6; --subtle: #6d7a87;
    --accent: #5fb3d6; --accent-hover: #82c6e3; --accent-soft: #16303c; --accent-text: #8fd0ea; --on-accent: #06202b;
    --ok: #5bd08a; --ok-soft: #13301f; --warn: #f0b35a; --warn-soft: #33260f; --bad: #f58a8a; --bad-soft: #3a1717;
    --row-hover: #18222a; --selected: #163243; --selected-hover: #1c3c50;
    --backdrop: rgba(0, 0, 0, .55);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 4px 12px rgba(0, 0, 0, .45); --shadow-lg: 0 16px 40px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1317; --surface: #141b21; --surface-2: #1a232a; --sidebar: #10171c;
  --border: #25303a; --border-strong: #34424e; --line: #1e2830;
  --text: #e8edf2; --muted: #9eaab6; --subtle: #6d7a87;
  --accent: #5fb3d6; --accent-hover: #82c6e3; --accent-soft: #16303c; --accent-text: #8fd0ea; --on-accent: #06202b;
  --ok: #5bd08a; --ok-soft: #13301f; --warn: #f0b35a; --warn-soft: #33260f; --bad: #f58a8a; --bad-soft: #3a1717;
  --row-hover: #18222a; --selected: #163243; --selected-hover: #1c3c50;
  --backdrop: rgba(0, 0, 0, .55);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 4px 12px rgba(0, 0, 0, .45); --shadow-lg: 0 16px 40px rgba(0, 0, 0, .6);
}

:root[data-density="compact"] { --control-h: 28px; --row-h: 30px; }

/* ------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 13px/1.45 var(--font); font-feature-settings: "cv11", "ss03";
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
::selection { background: var(--selected-hover); color: var(--text); }
a { color: var(--accent-text); }
a:hover { color: var(--accent-hover); }
code, kbd, pre { font-family: var(--mono); font-size: .92em; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
h1, h2, h3 { letter-spacing: -0.01em; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; white-space: nowrap; cursor: pointer; text-decoration: none; user-select: none;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover:not(:disabled) { background: var(--row-hover); color: var(--text); }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { color: var(--muted); }
.btn.primary, .btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary svg, .btn-primary svg { color: currentColor; }
.btn.primary:hover:not(:disabled), .btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn.danger, .btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger svg, .btn-danger svg { color: currentColor; }
.btn.danger:hover:not(:disabled), .btn-danger:hover:not(:disabled) { filter: brightness(.92); background: var(--bad); color: #fff; }
.btn.ghost, .btn-ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled), .btn-ghost:hover:not(:disabled) { background: var(--row-hover); }
.btn.icon, .btn-icon { width: var(--control-h); padding: 0; }
.btn.on, .btn[aria-pressed="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent-text); }
.btn.on svg, .btn[aria-pressed="true"] svg { color: var(--accent-text); }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent-text); font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }

/* ------------------------------------------------ form controls */
.input, .select, textarea.input {
  width: 100%; height: var(--control-h); padding: 0 10px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; padding: 8px 10px; line-height: 1.5; resize: vertical; }
.input::placeholder, textarea.input::placeholder { color: var(--subtle); }
.input:hover:not(:disabled), .select:hover:not(:disabled) { border-color: color-mix(in srgb, var(--border-strong) 60%, var(--text)); }
.input:focus, .select:focus, textarea.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--muted); }
.input.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 18%, transparent); }
.field-label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* ------------------------------------------------ surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { margin: 0; font-size: 14px; font-weight: 600; flex: 1; min-width: 0; }
.section-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 12px; white-space: nowrap; max-width: 100%; }
.chip .chip-label { color: var(--muted); }
.chip .chip-value { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }

.kbd, kbd.kbd { display: inline-block; font: 500 11px/16px var(--font); padding: 0 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); background: var(--surface-2); }

.banner { display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-radius: var(--radius); border: 1px solid transparent; }
.banner.error { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.banner.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }

/* ------------------------------------------------ tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 0 12px; height: 36px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); }
.table td { padding: 0 12px; height: var(--row-h); border-bottom: 1px solid var(--line); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--row-hover); }

/* ------------------------------------------------ menus and popovers */
.menu, .popover {
  position: absolute; z-index: 40; min-width: 180px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg);
}
.menu button, .menu a {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 30px; padding: 0 10px; border: 0; border-radius: 5px;
  background: none; color: var(--text); text-align: left; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.menu button:hover:not(:disabled), .menu button:focus-visible, .menu a:hover { background: var(--row-hover); outline: none; }
.menu button:disabled { opacity: .45; cursor: default; }
.menu svg { color: var(--muted); }
.menu .menu-title, .menu .group { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 8px 10px 4px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ------------------------------------------------ dialogs */
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); max-width: min(440px, calc(100vw - 32px)); width: 100%;
}
dialog::backdrop { background: var(--backdrop); }
dialog[open] { animation: dialog-in .16s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }
dialog .content { padding: 20px 22px 16px; }
dialog h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
dialog .buttons { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 12px 22px; background: var(--surface-2); border-top: 1px solid var(--border); border-radius: 0 0 12px 12px; }
dialog .buttons button { min-width: 80px; height: var(--control-h); padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); font-weight: 500; cursor: pointer; }
dialog .buttons button:hover:not(:disabled) { background: var(--row-hover); }
dialog .buttons button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
dialog .buttons button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
dialog .buttons button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
/* A quiet destructive action beside the others (e.g. delete the record of a card window). */
dialog .buttons button.delete { color: var(--bad); }
dialog .buttons button.delete:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); }
dialog .buttons button:disabled { opacity: .45; cursor: default; }

/* ------------------------------------------------ toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; width: min(400px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 10px 10px 10px 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast .toast-icon { width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; background: var(--accent-soft); color: var(--accent-text); }
.toast .toast-icon svg { width: 14px; height: 14px; stroke-width: 2; }
.toast.ok .toast-icon { background: var(--ok-soft); color: var(--ok); }
.toast.warn .toast-icon { background: var(--warn-soft); color: var(--warn); }
.toast.bad .toast-icon { background: var(--bad-soft); color: var(--bad); }
.toast .toast-body { flex: 1; min-width: 0; padding-top: 2px; overflow-wrap: anywhere; }
.toast .toast-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.toast .toast-actions a, .toast .toast-actions button { color: var(--accent-text); font-weight: 500; cursor: pointer; border: 0; background: none; padding: 0; text-decoration: none; }
.toast .toast-actions a:hover, .toast .toast-actions button:hover { text-decoration: underline; }
.toast .toast-close { border: 0; background: none; color: var(--muted); width: 24px; height: 24px; border-radius: 5px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.toast .toast-close:hover { background: var(--row-hover); color: var(--text); }
@media (prefers-reduced-motion: reduce) { dialog[open], .toast { animation: none; } }

/* ------------------------------------------------ app shell: sidebar, topbar, content */
.app { display: flex; height: 100vh; height: 100dvh; min-height: 0; }
.sidebar {
  width: var(--sidebar-w); flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--sidebar); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; min-width: 0; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.brand-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 12px; }
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 32px; padding: 0 10px; border: 0; border-radius: var(--radius);
  background: none; color: var(--muted); font-weight: 500; text-align: left; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.side-item > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.side-item:hover { background: var(--row-hover); color: var(--text); }
.side-item.active, .side-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.side-item.active svg, .side-item[aria-current="page"] svg { color: var(--accent-text); }
.side-item .chevron { width: 14px; height: 14px; transition: transform .15s; }
.side-item[aria-expanded="false"] .chevron { transform: rotate(-90deg); }
.side-sub { display: flex; flex-direction: column; gap: 1px; margin: 1px 0 4px; }
.side-sub .side-item { height: 30px; padding-left: 36px; font-weight: 400; }
.side-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0 10px; margin: 16px 0 6px; }
.side-foot { border-top: 1px solid var(--border); padding: 8px; display: flex; flex-direction: column; gap: 1px; }

.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.topbar { height: 52px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px 0 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.crumbs a, .crumbs button { color: var(--muted); text-decoration: none; border: 0; background: none; padding: 3px 4px; border-radius: 4px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.crumbs a:hover, .crumbs button:hover { color: var(--text); background: var(--row-hover); }
.crumbs .sep { width: 14px; height: 14px; color: var(--subtle); }
.crumbs .current { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; padding: 3px 4px; }
.palette-trigger {
  display: inline-flex; align-items: center; gap: 8px; width: 300px; max-width: 34vw; height: 32px; padding: 0 8px 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--muted); cursor: pointer; text-align: left;
}
.palette-trigger:hover { border-color: var(--border-strong); color: var(--text); }
.palette-trigger > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }

/* ------------------------------------------------ command palette */
dialog.palette { width: 640px; max-width: calc(100vw - 32px); margin-top: 12vh; border-radius: 14px; }
dialog.palette[open] { animation-duration: .12s; }
.palette-search { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.palette-search svg { width: 18px; height: 18px; color: var(--muted); }
.palette-search input { flex: 1; height: 100%; border: 0; outline: none; background: none; font-size: 15px; }
.palette-list { max-height: min(440px, 60vh); overflow-y: auto; padding: 6px; }
.palette-group { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 38px; padding: 4px 10px; border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer; }
.palette-item[aria-selected="true"] { background: var(--accent-soft); }
.palette-item .pi-icon { width: 26px; height: 26px; border-radius: 7px; background: var(--surface-2); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.palette-item[aria-selected="true"] .pi-icon { background: var(--surface); color: var(--accent-text); }
.palette-item .pi-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.palette-item .pi-label { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .pi-label mark { background: none; color: var(--accent-text); font-weight: 650; }
.palette-item .pi-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .pi-hint { font-size: 12px; color: var(--muted); white-space: nowrap; }
.palette-empty { padding: 32px 12px; text-align: center; color: var(--muted); }
.palette-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 9px 16px; border-top: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: 12px; border-radius: 0 0 14px 14px; }

/* ------------------------------------------------ narrow screens: the sidebar becomes a drawer */
.menu-toggle { display: none; }
.drawer-scrim { display: none; }
@media (max-width: 760px) {
  .menu-toggle { display: inline-flex; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 70; width: min(300px, 86vw); transform: translateX(-102%); transition: transform .2s ease-out; box-shadow: var(--shadow-lg); }
  .app.drawer-open .sidebar { transform: none; }
  .app.drawer-open .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 65; background: var(--backdrop); }
  .topbar { padding: 0 8px; gap: 6px; }
  .palette-trigger { width: 36px; padding: 0; justify-content: center; }
  .palette-trigger > span, .palette-trigger .kbd { display: none; }
  .toasts { right: 8px; left: 8px; bottom: 8px; width: auto; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
