/* cozytempl — dashboard styles */

/*
 * Self-hosted Inter font (from @fontsource/inter, SIL Open Font License).
 *
 * The previous build loaded Inter from fonts.googleapis.com, which is a
 * GDPR issue in the EU (Landgericht München ruling 3 O 17493/20 held
 * that exposing the visitor IP to Google without consent violates GDPR
 * art. 6) and a general data-leak. Everything is now served from /static.
 *
 * Two ranges per weight — latin and latin-ext — with explicit
 * unicode-range so the browser only downloads the extended face when
 * the page actually contains non-ASCII glyphs. font-display: swap so
 * the fallback stack renders immediately and the upgrade happens in
 * the background when the file arrives.
 */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/inter-latin-400-normal.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+2074, 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-weight: 400;
  font-display: swap;
  src: url("/static/fonts/inter-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/inter-latin-500-normal.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+2074, 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-weight: 500;
  font-display: swap;
  src: url("/static/fonts/inter-latin-ext-500-normal.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/inter-latin-600-normal.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+2074, 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-weight: 600;
  font-display: swap;
  src: url("/static/fonts/inter-latin-ext-600-normal.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin-700-normal.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+2074, 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-weight: 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin-ext-700-normal.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/*
 * Theme variables. Dark is the historical default; light is a
 * sibling theme, and the actual theme is chosen by a cascade:
 *
 *   1. [data-theme="light"] or [data-theme="dark"] on <html> —
 *      explicit user choice persisted in localStorage and
 *      applied before first paint by the inline script in
 *      base.templ, so there's no flash of the wrong theme on
 *      page load.
 *   2. No explicit choice → the default is dark.
 *   3. No explicit choice AND prefers-color-scheme: light →
 *      the light theme is applied automatically.
 *
 * The same CSS custom property names are used by both themes
 * so component rules never need a selector per theme.
 */

:root,
:root[data-theme="dark"] {
  --color-bg: #0f1117;
  --color-bg-surface: #1a1d27;
  --color-bg-elevated: #242836;
  --color-bg-hover: #2e3345;
  --color-border: #363b4e;
  --color-border-subtle: #2a2e3f;
  --color-text: #e1e4ed;
  --color-text-secondary: #9499ad;
  --color-text-muted: #6b7084;
  --color-primary: #6c8cff;
  --color-primary-hover: #8ba3ff;
  --color-primary-bg: rgba(108, 140, 255, 0.12);
  --color-success: #4ade80;
  --color-success-bg: rgba(74, 222, 128, 0.12);
  --color-warning: #fbbf24;
  --color-warning-bg: rgba(251, 191, 36, 0.12);
  --color-danger: #f87171;
  --color-danger-bg: rgba(248, 113, 113, 0.12);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --transition: 150ms ease;
  --sidebar-width: 260px;
  --header-height: 56px;
  --font-mono: "JetBrains Mono", "Fira Code", "SF Mono", monospace;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Light theme. Component rules never branch on theme — they just
   read the same custom properties, so this block is the entire
   diff between dark and light. Contrast ratios meet WCAG AA for
   body text (7:1) and large text (4.5:1) against the chosen
   backgrounds. */
:root[data-theme="light"] {
  --color-bg: #f7f8fa;
  --color-bg-surface: #ffffff;
  --color-bg-elevated: #eef1f6;
  --color-bg-hover: #e3e7ef;
  --color-border: #d4d9e3;
  --color-border-subtle: #e6e9f0;
  --color-text: #1a1d27;
  --color-text-secondary: #4a5166;
  --color-text-muted: #6b7084;
  --color-primary: #3559ff;
  --color-primary-hover: #5176ff;
  --color-primary-bg: rgba(53, 89, 255, 0.1);
  --color-success: #16a34a;
  --color-success-bg: rgba(22, 163, 74, 0.1);
  --color-warning: #b45309;
  --color-warning-bg: rgba(180, 83, 9, 0.1);
  --color-danger: #dc2626;
  --color-danger-bg: rgba(220, 38, 38, 0.1);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.1);
}

/* Auto-match the system preference when the user has not made
   an explicit choice. The :not() guard means an explicit
   data-theme always wins, regardless of what the OS reports. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --color-bg: #f7f8fa;
    --color-bg-surface: #ffffff;
    --color-bg-elevated: #eef1f6;
    --color-bg-hover: #e3e7ef;
    --color-border: #d4d9e3;
    --color-border-subtle: #e6e9f0;
    --color-text: #1a1d27;
    --color-text-secondary: #4a5166;
    --color-text-muted: #6b7084;
    --color-primary: #3559ff;
    --color-primary-hover: #5176ff;
    --color-primary-bg: rgba(53, 89, 255, 0.1);
    --color-success: #16a34a;
    --color-success-bg: rgba(22, 163, 74, 0.1);
    --color-warning: #b45309;
    --color-warning-bg: rgba(180, 83, 9, 0.1);
    --color-danger: #dc2626;
    --color-danger-bg: rgba(220, 38, 38, 0.1);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.1);
  }
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Skip link. Hidden off-screen until a keyboard user tabs into it,
   at which point it pops into view and lets them jump past the
   header + sidebar straight to the main content. Required by
   WCAG 2.1 SC 2.4.1 Bypass Blocks — every accessibility audit
   will flag its absence. */
.skip-link {
  position: absolute;
  top: -40px;
  left: 8px;
  padding: 8px 16px;
  background: var(--color-primary);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-sm);
  z-index: 200;
  transition: top 150ms ease;
}

.skip-link:focus {
  top: 8px;
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* Visible focus ring everywhere. Browsers mostly do this by default
   now, but we spell it out so the dark theme doesn't drop it on
   custom-styled buttons/links. */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Layout */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  min-height: 100vh;
}

/* Dev mode banner — visible when COZYTEMPL_DEV_MODE=true.
   Bright, high-contrast strip above the app layout so anyone who hits
   a dev-mode instance (including through the shared Cloudflare tunnel)
   sees immediately that authentication is disabled. The `:has()` rule
   below subtracts the banner height from `.app-layout` so the grid
   doesn't push the page past 100vh. */
.dev-mode-banner {
  background: repeating-linear-gradient(
    135deg,
    #f87171 0,
    #f87171 18px,
    #ef4444 18px,
    #ef4444 36px
  );
  color: #1a0000;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.9rem;
  font-weight: 500;
  border-bottom: 2px solid #991b1b;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 50;
}

.dev-mode-banner-label {
  background: #1a0000;
  color: #fca5a5;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex: 0 0 auto;
}

.dev-mode-banner code {
  background: rgba(26, 0, 0, 0.25);
  color: #1a0000;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
}

.dev-mode-banner a {
  margin-left: auto;
  color: #1a0000;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  flex: 0 0 auto;
}

.dev-mode-banner a:hover {
  color: #000;
  text-decoration-thickness: 2px;
}

body:has(.dev-mode-banner) .app-layout {
  min-height: calc(100vh - 48px);
}

/* Header */
.header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 10;
}

.header-logo {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Sidebar */
.sidebar {
  background: var(--color-bg-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 16px 0;
}

.sidebar-section {
  padding: 0 12px;
  margin-bottom: 8px;
}

.sidebar-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding: 8px 12px 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}

.sidebar-item:hover {
  background: var(--color-bg-hover);
  color: var(--color-text);
}

.sidebar-item.active {
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

.sidebar-item .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Tenant tree */
.tenant-tree {
  list-style: none;
}

.tenant-tree .tenant-tree {
  padding-left: 16px;
}

.tenant-node {
  padding: 4px 0;
}

.tenant-toggle {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  width: 18px;
  font-size: 0.75rem;
  transition: transform var(--transition);
}

.tenant-toggle.expanded {
  transform: rotate(90deg);
}

/* Main content */
.main-content {
  padding: 24px;
  overflow-y: auto;
  /* min-width: 0 stops the grid column from expanding to fit the
     intrinsic width of nowrap flex children (the marketplace filter
     pills strip, long app table rows, etc.). Without this, a long
     pills row on mobile made the whole main-content grow past 100vw
     and the entire page scrolled horizontally. */
  min-width: 0;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.breadcrumb a {
  color: var(--color-text-secondary);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--color-primary);
}

.breadcrumb-sep::after {
  content: "/";
  margin: 0 2px;
}

/* Cards */
.card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* Tables */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

thead th.sortable {
  cursor: pointer;
  user-select: none;
}

thead th.sortable:hover {
  color: var(--color-text-secondary);
}

/* Sortable column header driven by a full-width button. The <th>
 * itself keeps the existing padding; the button fills it so the
 * entire cell is clickable, inherits the header font styling, and
 * does not look like a stand-alone widget. The .th-sort-active
 * modifier tints the active column so the ▲ indicator doesn't
 * have to carry the whole visual weight. */
.th-sort {
  padding: 0;
}

.th-sort-button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.th-sort-button:hover {
  color: var(--color-text-secondary);
  background: var(--color-bg-hover);
}

.th-sort-button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.th-sort-active .th-sort-button {
  color: var(--color-text);
}

.th-sort-indicator {
  font-size: 0.7rem;
  line-height: 1;
}

.th-sort-indicator-idle {
  color: var(--color-text-muted);
  opacity: 0.5;
}

.th-sort-button:hover .th-sort-indicator-idle {
  opacity: 1;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-subtle);
  vertical-align: middle;
}

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

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

/* New row flash animation (SSE added events) */
@keyframes row-flash {
  0% {
    background: var(--color-primary-bg);
    box-shadow: inset 3px 0 0 var(--color-primary);
  }
  100% {
    background: transparent;
    box-shadow: inset 3px 0 0 transparent;
  }
}

tr.row-flash td {
  animation: row-flash 1.5s ease-out;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 500;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-ready {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-ready::before {
  background: var(--color-success);
}

.badge-reconciling {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.badge-reconciling::before {
  background: var(--color-warning);
  animation: pulse 1.5s ease-in-out infinite;
}

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

.badge-failed::before {
  background: var(--color-danger);
}

.badge-unknown {
  background: rgba(107, 112, 132, 0.12);
  color: var(--color-text-muted);
}

.badge-unknown::before {
  background: var(--color-text-muted);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-elevated);
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  text-decoration: none;
}

.btn:hover {
  background: var(--color-bg-hover);
  border-color: var(--color-text-muted);
}

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

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

.btn-danger {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger-bg);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 6px;
  border: none;
  background: transparent;
}

.btn-icon:hover {
  background: var(--color-bg-hover);
  border-radius: var(--radius-sm);
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-text-secondary);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}

.form-input.error {
  border-color: var(--color-danger);
}

.form-error {
  font-size: 0.8rem;
  color: var(--color-danger);
  margin-top: 4px;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* Language switcher in the header. A compact sibling of
 * .form-select that uses the same palette variables so it
 * matches the dark/light theme instead of falling back to the
 * OS default select style. Width is auto so it hugs the
 * selected label; padding is tight so it fits next to the
 * theme toggle and avatar without stretching the header row. */
.lang-switcher {
  display: flex;
  align-items: center;
}

.lang-select {
  width: auto;
  padding: 4px 24px 4px 8px;
  background-color: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1.2;
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%),
                    linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) calc(50% - 2px),
                       calc(100% - 7px)  calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  transition: border-color var(--transition);
}

.lang-select:hover {
  border-color: var(--color-primary);
}

.lang-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}

.lang-select option {
  background-color: var(--color-bg-surface);
  color: var(--color-text);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90vw;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(440px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px 14px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: var(--shadow-md);
  animation: toast-in 220ms ease;
  position: relative;
  overflow: hidden;
  min-width: 280px;
}

/* Left accent bar drawn via ::before — no emoji/unicode icons. */
.toast::before {
  content: "";
  flex: 0 0 4px;
  align-self: stretch;
  margin: -2px 2px -2px 0;
  border-radius: 2px;
  background: currentColor;
}

.toast-success {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success);
  color: var(--color-success);
}

.toast-error {
  background: var(--color-danger-bg);
  border: 2px solid var(--color-danger);
  color: var(--color-danger);
  font-weight: 500;
}

/* Auto-dismiss countdown bar (optional visual; driven by CSS animation). */
.toast[data-auto-dismiss]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: currentColor;
  opacity: 0.4;
  transform-origin: left;
  animation: toast-countdown 4000ms linear forwards;
}

@keyframes toast-countdown {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Loading */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--color-text-muted);
  gap: 12px;
}

/* ---- htmx request feedback ---------------------------------------------- */

/*
 * Global top progress bar. The bar is driven by htmx.ts on
 * htmx:beforeRequest / htmx:afterRequest events. A single element in
 * base.templ (#htmx-progress-bar) handles every request across the app.
 *
 * Uses an indeterminate animation rather than a deterministic fill so the
 * bar always moves (giving clear "something is happening" feedback) even
 * on very short requests. The bar slides an 80%-wide highlight back and
 * forth across the top of the viewport while .loading is set; when no
 * class is set the container collapses to height 0 (snaps away instantly).
 * No opacity fade — the indeterminate animation is already eye-catching
 * enough that a hard on/off feels natural and avoids CSS transition
 * state churn on fast successive requests.
 */
#htmx-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 0;
  z-index: 1000;
  pointer-events: none;
  background: transparent;
  overflow: hidden;
}

#htmx-progress-bar::before {
  content: "";
  position: absolute;
  top: 0;
  left: -35%;
  width: 35%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--color-primary-hover) 50%,
    transparent 100%
  );
  box-shadow: 0 0 8px var(--color-primary);
}

#htmx-progress-bar.loading {
  height: 3px;
}

#htmx-progress-bar.loading::before {
  animation: progress-indeterminate 1.1s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% {
    left: -35%;
  }
  100% {
    left: 100%;
  }
}

/*
 * Element issuing an in-flight htmx request. htmx automatically toggles the
 * .htmx-request class on the triggering element and on any element matching
 * hx-indicator. We style buttons/links/inputs to be visibly busy.
 */
.htmx-request {
  pointer-events: none;
}

button.htmx-request,
a.btn.htmx-request,
.tab.htmx-request {
  position: relative;
  color: transparent !important;
  cursor: wait;
}

button.htmx-request::after,
a.btn.htmx-request::after,
.tab.htmx-request::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--color-text);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  color: var(--color-text);
}

.btn-primary.htmx-request::after {
  border-color: #fff;
  border-right-color: transparent;
}

.btn-danger.htmx-request::after {
  border-color: var(--color-danger);
  border-right-color: transparent;
}

/* Inputs (search, selects) get a subtle ring while the fragment is loading. */
input.htmx-request,
select.htmx-request,
textarea.htmx-request {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

/* Dashed link/nav row gets a soft highlight while loading. */
a.sidebar-item.htmx-request,
.mp-pill.htmx-request,
.mp-tag-pill.htmx-request {
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

/* Row being swapped out after a delete. Slides right and fades. */
tr.htmx-swapping {
  animation: row-delete 500ms ease-out forwards;
  pointer-events: none;
}

@keyframes row-delete {
  0% {
    opacity: 1;
    transform: translateX(0);
    background: var(--color-danger-bg);
    box-shadow: inset 3px 0 0 var(--color-danger);
  }
  100% {
    opacity: 0;
    transform: translateX(24px);
    background: var(--color-danger-bg);
    box-shadow: inset 3px 0 0 var(--color-danger);
  }
}

tr.htmx-swapping td {
  border-bottom-color: var(--color-danger);
}

/* The dashboard row is clickable via hx-get; show loading cursor on hover. */
tr[hx-get]:hover {
  cursor: pointer;
}

/* Prevent layout shift while htmx is settling (fade-in for new content). */
#main-content.htmx-swapping {
  opacity: 0;
  transition: opacity 120ms ease-out;
}
#main-content.htmx-settling {
  opacity: 1;
  transition: opacity 180ms ease-in;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

/* Truncated-list warning banner. Shown above the app table when
   ApplicationService.List hit its hard cap so the user knows
   filter/sort operates on a bounded window. Warning-amber on
   subtle amber background so it reads as "informational, not
   catastrophic". */
.truncated-banner {
  margin: 12px 16px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--color-warning);
  background: var(--color-warning-bg);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--color-text);
}

.truncated-banner strong {
  display: block;
  margin-bottom: 2px;
  color: var(--color-warning);
}

.truncated-banner span {
  color: var(--color-text-secondary);
}

/* Error pages (404 / 403 / 500). Rendered by page/error.templ into
   main-content so htmx in-app navigation to a missing resource lands
   on a branded screen instead of a plain-text http.Error body. */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px;
  min-height: 60vh;
}

.error-status {
  font-family: var(--font-mono);
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--color-primary);
  letter-spacing: -0.02em;
}

.error-status-text {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--color-text-muted);
  margin-top: 8px;
  margin-bottom: 24px;
}

.error-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 12px;
}

.error-detail {
  color: var(--color-text-secondary);
  max-width: 480px;
  margin-bottom: 24px;
  line-height: 1.5;
}

/* Connection info */
.connection-info {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  position: relative;
}

.connection-info .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* Connection-info credential in placeholder state. The eyeball
   button fetches and reveals the real value for ~30 seconds (see
   static/ts/reveal.ts) — this styling keeps the dot-dot-dot
   placeholder muted until the user explicitly asks for the value. */
.connection-info.connection-secret {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.connection-info.connection-secret code {
  color: var(--color-text-muted);
  letter-spacing: 0.15em;
}

/* Once revealed, briefly highlight the row so the user sees the
   temporary disclosure landed. The class is added by reveal.ts
   on the htmx:afterSwap for the data-reveal-target span. */
.connection-info.connection-secret-revealed {
  background: var(--color-warning-bg);
  border-color: var(--color-warning);
}

.connection-info.connection-secret-revealed code {
  color: var(--color-text);
  letter-spacing: 0;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 16px;
}

.tab {
  padding: 10px 16px;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}

.tab:hover {
  color: var(--color-text);
}

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* Search */
.search-input {
  position: relative;
}

.search-input input {
  padding-left: 36px;
}

.search-input .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
}

/* Utility */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--color-text-muted); }
.text-mono { font-family: var(--font-mono); }
.hidden { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

/* Marketplace */
.mp-filters {
  margin-bottom: 24px;
}

.mp-search {
  position: relative;
  margin-bottom: 16px;
}

.mp-filter-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.mp-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 100px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-surface);
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}

.mp-pill:hover {
  border-color: var(--color-text-muted);
  color: var(--color-text);
}

.mp-pill.active {
  background: var(--color-primary-bg);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.mp-pill-count {
  font-size: 0.75rem;
  background: var(--color-bg-elevated);
  padding: 1px 6px;
  border-radius: 100px;
  min-width: 20px;
  text-align: center;
}

.mp-pill.active .mp-pill-count {
  background: rgba(108, 140, 255, 0.2);
}

.mp-tag-pill {
  padding: 4px 10px;
  border-radius: 100px;
  border: 1px solid var(--color-border-subtle);
  background: transparent;
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.mp-tag-pill:hover,
.mp-tag-pill.active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-bg);
}

.mp-category {
  margin-bottom: 32px;
}

.mp-category-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border-subtle);
}

.mp-category-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.mp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.mp-card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.mp-card:hover {
  border-color: var(--color-primary);
  background: var(--color-bg-elevated);
}

.mp-card-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mp-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--color-bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mp-card:hover .mp-card-icon {
  background: var(--color-primary-bg);
}

.mp-card-icon img {
  border-radius: 3px;
}

.mp-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
}

.mp-card-desc {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mp-card-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-left: 52px;
}

.mp-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--color-bg);
  border: 1px solid var(--color-border-subtle);
  color: var(--color-text-muted);
}

/* Burger menu */
.burger {
  display: none;
  background: none;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  padding: 4px;
}

.sidebar-overlay {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .burger {
    display: block;
  }

  .sidebar {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 50;
    background: var(--color-bg-surface);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
  }

  .sidebar.open {
    display: block;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
  }

  .sidebar-overlay.open {
    display: block;
  }

  .main-content {
    padding: 16px;
  }

  .modal {
    min-width: auto;
    margin: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .mp-grid {
    grid-template-columns: 1fr;
  }

  .mp-filters .mp-filter-pills {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .flex.items-center.gap-3.mb-4 {
    flex-direction: column;
    align-items: stretch;
  }

  .flex.items-center.gap-3.mb-4 input,
  .flex.items-center.gap-3.mb-4 select {
    max-width: 100% !important;
  }

  /* Hide Created column on mobile */
  table thead th:nth-child(4),
  table tbody td:nth-child(4) {
    display: none;
  }

  .btn-sm {
    padding: 3px 8px;
    font-size: 0.75rem;
  }

  .dev-mode-banner {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.82rem;
  }

  .dev-mode-banner a {
    margin-left: 0;
  }

  body:has(.dev-mode-banner) .app-layout {
    min-height: calc(100vh - 72px);
  }
}

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--color-bg);
}

.login-card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  min-width: 360px;
  box-shadow: var(--shadow-md);
}

.login-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--color-text-secondary);
  margin-bottom: 32px;
}

/* ------------------------------------------------------------------
 * Command palette (Cmd/Ctrl-K overlay).
 * Rendered client-side by static/ts/palette.ts into a single
 * document.body-level <div> that stays in the DOM across openings.
 * Uses the theme variables so dark/light palettes work for free.
 * ------------------------------------------------------------------ */
.command-palette {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}

.command-palette[hidden] {
  display: none;
}

.command-palette-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.command-palette-panel {
  position: relative;
  width: min(600px, 90vw);
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg, 0 20px 60px rgba(0, 0, 0, 0.4));
  overflow: hidden;
}

.command-palette-input {
  flex: 0 0 auto;
  padding: 16px 20px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
}

.command-palette-input::placeholder {
  color: var(--color-text-muted);
}

.command-palette-list {
  flex: 1 1 auto;
  list-style: none;
  margin: 0;
  padding: 6px 0;
  overflow-y: auto;
}

.command-palette-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  cursor: pointer;
  color: var(--color-text);
  transition: background var(--transition);
}

.command-palette-item-active,
.command-palette-item:hover {
  background: var(--color-bg-hover);
}

.command-palette-item-label {
  font-size: 0.92rem;
}

.command-palette-item-hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-family: var(--font-mono, monospace);
}

.command-palette-empty {
  padding: 16px 20px;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.command-palette-footer {
  flex: 0 0 auto;
  display: flex;
  gap: 16px;
  padding: 10px 20px;
  border-top: 1px solid var(--color-border);
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.command-palette-footer kbd {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 4px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-family: var(--font-mono, monospace);
  font-size: 0.7rem;
  color: var(--color-text-secondary);
}

body.command-palette-open {
  overflow: hidden;
}

/* ------------------------------------------------------------------
 * Marketplace card, rendered as an <a> so keyboard focus,
 * middle-click-to-open, and right-click-context-menu all work out
 * of the box. The underlying .mp-card rule already carries the
 * card chrome (background, border, cursor:pointer, hover). The
 * link variant only needs to strip the default anchor decoration
 * so the card keeps its original visual look.
 * ------------------------------------------------------------------ */
.mp-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.mp-card-link:hover,
.mp-card-link:focus-visible {
  color: inherit;
  text-decoration: none;
}

.mp-card-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------
 * Generic inline banner for status / hint messages at the top of
 * a page. .banner is the base (padding, radius, border). Variants
 * tint the left border + background. .banner-info for neutral
 * informational hints like the "pick a tenant to create <kind>"
 * message on the tenants page after a marketplace card click.
 * ------------------------------------------------------------------ */
.banner {
  padding: 12px 16px;
  border-left: 3px solid var(--color-border);
  background: var(--color-bg-surface);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--color-text);
}

.banner-info {
  border-left-color: var(--color-primary);
  background: var(--color-primary-bg);
}

/* ------------------------------------------------------------------
 * Inline "Learn more →" link used on profile, byok upload and
 * logs-tab error messages. Styled as a subtle secondary link —
 * visible but not loud, focus-ring for keyboard users.
 * ------------------------------------------------------------------ */
.doc-link {
  color: var(--color-primary);
  text-decoration: none;
  border-bottom: 1px dotted var(--color-primary);
  padding-bottom: 1px;
  transition: color var(--transition), border-color var(--transition);
}

.doc-link:hover {
  color: var(--color-primary-hover, var(--color-primary));
  border-bottom-color: transparent;
}

.doc-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}
