/*
 * components.css — Bespoke component layer for the Shieldpay portal
 *
 * Loaded after semtx.css. Single file covering both the customer-facing
 * portal shell (public/index.html) and the Shieldpay Ledger admin shell
 * (public/manage/index.html), plus shared error page styling.
 *
 * Scoping convention: rules that apply to a single shell live under a
 * body-class scope (.portal, .admin). Shared rules — design tokens,
 * htmx helpers, flash banners, error pages — sit at the top level
 * with no scope.
 *
 *   <body class="portal">  →  loads .portal scope
 *   <body class="admin">   →  loads .admin scope
 *   <body class="error">   →  loads only top-level rules (.error*)
 *
 * STARBASE-013 supersedes the earlier split into shell-components.css
 * (portal) and manage-components.css (admin).
 */

/* ═══════════════════════════════════════════════════════════════
   1. Design Tokens
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Radius */
  --radius: 0.65rem;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  /* Colour tokens (oklch) */
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --color-selection: var(--primary);
  --color-selection-foreground: var(--primary-foreground);

  /* Typography */
  --font: "Inter", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;

  /* Greys */
  --gray-50: #f7f8fa;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #cdd1d9;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #353c4a;

  /* Admin shell specific */
  --sidebar-bg: #353c4a;
  --sidebar-hover: #2d333f;
  --sidebar-width-open: 12rem;
  --sidebar-width-collapsed: 3.5rem;
  --topbar-height: 3.5rem;
  --transition-duration: 300ms;

  /* Accents */
  --indigo-600: #4f46e5;
  --red-500: #ef4444;
  --blue-100: #dbeafe;
  --green-100: #dcfce7;
}

.dark {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.205 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.922 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);
}

/* ═══════════════════════════════════════════════════════════════
   2. Base / Shared
   ═══════════════════════════════════════════════════════════════ */

:root {
  font-family: var(--font);
  color: #0b1221;
  background: #f8fafc;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--background);
  color: var(--foreground);
}

* {
  border-color: var(--border);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem;
}

button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* HTMX swap transitions */
.htmx-swapping {
  opacity: 0.25;
  transform: translateY(-6px);
}
.htmx-settling {
  transition-property: opacity, transform;
  transition-duration: 200ms;
  transition-timing-function: ease-out;
}

/* Alpine cloak */
[x-cloak] { display: none !important; }

/* Flash banners (forms, status messages) */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.flash--error {
  background: #fee2e2;
  color: #b91c1c;
}
.flash--notice {
  background: #dcfce7;
  color: #166534;
}

#upload-log {
  font-size: 0.85rem;
  margin-top: 1rem;
  min-height: 1rem;
}

/* Error fallback (HTMX OOB error handler injects this; 403/500 pages use it directly) */
.error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
}
.error-body {
  text-align: center;
}
.error-body > * + * {
  margin-top: 0.75rem;
}
.error-title {
  font-size: 1.125rem;
  line-height: 1.75rem;
  font-weight: 600;
  color: var(--gray-700);
}
.error-detail {
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--gray-500);
}

/* ═══════════════════════════════════════════════════════════════
   3. Portal shell — <body class="portal">
   Customer-facing shell with login (aurora + glass card) and
   dashboard (CSS grid template-areas) modes. Mode toggling via
   #shell.login / #shell.dashboard handled by inline <style> in
   public/index.html.
   ═══════════════════════════════════════════════════════════════ */

/* Global HTMX progress bar (lives outside #shell wrapper, hence body scope) */
.portal .progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 0.25rem;
  z-index: 60;
  pointer-events: none;
}

/* Header bar inside #shell */
.portal .header-bar {
  height: 3.5rem;
  display: flex;
  align-items: center;
  padding-left: 1rem;
  padding-right: 1rem;
  gap: 1rem;
}

.portal .logo {
  display: flex;
  align-items: center;
}

.portal .logo-img {
  width: 9rem;
}

.portal .header-spacer {
  flex: 1 1 0%;
}

.portal .topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.portal .crumb {
  padding-left: 1rem;
  padding-right: 1rem;
  padding-bottom: 0.5rem;
  font-size: 0.75rem;
  line-height: 1rem;
  color: var(--gray-500);
}

/* Sliding left sidebar (Alpine: is-open / is-closed) */
.portal .sidebar {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  transition-property: width;
  transition-duration: 200ms;
  overflow: hidden;
}
.portal .sidebar.is-open {
  width: 12rem;
}
.portal .sidebar.is-closed {
  width: 0;
}

/* Hidden utility for nav-trigger elements */
.portal .hidden {
  display: none;
}

/* ═══════════════════════════════════════════════════════════════
   4. Admin shell — <body class="admin">
   Shieldpay Ledger admin shell. Topbar + collapsible sidebar +
   main content + footer.
   ═══════════════════════════════════════════════════════════════ */

.admin {
  background-color: var(--gray-100);
  font-size: 0.875rem;
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  color: var(--gray-900);
}

.admin .topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: #fff;
  border-bottom: 1px solid var(--gray-200);
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding-left: 1rem;
  padding-right: 1rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.admin .topbar-logo {
  width: 9rem;
}

.admin .topbar-nav {
  margin-left: auto;
  display: flex;
  column-gap: 1.5rem;
  align-items: center;
}

.admin .nav-link {
  color: var(--gray-500);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  transition: color 200ms ease;
}
.admin .nav-link:hover {
  color: var(--gray-700);
  text-decoration: none;
}

/* Flex row containing sidebar + content-area */
.admin .body {
  display: flex;
  flex: 1 1 0%;
  overflow: hidden;
}

/* Icon-collapsing left sidebar (Alpine: is-open / is-collapsed) */
.admin .sidebar {
  background-color: var(--sidebar-bg);
  color: #fff;
  padding: 0.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: all var(--transition-duration) ease-in-out;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.admin .sidebar.is-open {
  width: var(--sidebar-width-open);
}
.admin .sidebar.is-collapsed {
  width: var(--sidebar-width-collapsed);
}

.admin .sidebar-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 0.5rem;
  color: #fff;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-duration);
  border-radius: 0;
}
.admin .sidebar-toggle:hover {
  background-color: var(--sidebar-hover);
}
.admin .sidebar-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(17, 24, 39, 0.7);
}
.admin .sidebar-toggle.is-centered {
  justify-content: center;
}
.admin .sidebar-toggle.is-end {
  justify-content: flex-end;
  padding-right: 0.5rem;
}

.admin .sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
  width: 100%;
}

.admin .sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  padding: 0.5rem;
  border-radius: 0.25rem;
  width: 100%;
  color: #fff;
  background: transparent;
  border: none;
  cursor: pointer;
}
.admin .sidebar-link:hover {
  background-color: var(--sidebar-hover);
}

.admin .icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}
.admin .icon--sm {
  width: 1rem;
  height: 1rem;
}

.admin .content-area {
  flex: 1 1 0%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  overflow: hidden;
  max-width: 100%;
}
@media (min-width: 768px) {
  .admin .content-area {
    grid-template-columns: 1fr 320px;
  }
}

.admin .panel {
  order: 1;
  width: 100%;
  padding: 1rem;
  overflow-y: auto;
  min-width: 0;
  background-color: var(--blue-100);
}
@media (min-width: 768px) {
  .admin .panel {
    order: 2;
    width: 20rem;
  }
}

.admin .panel-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.admin .card {
  background-color: var(--gray-50);
  border-radius: 0.75rem;
  border: 1px solid var(--gray-200);
  padding: 1.5rem;
}
.admin .card--alt {
  background-color: var(--gray-100);
}

.admin .card-title {
  font-size: 1.125rem;
  line-height: 1.75rem;
  font-weight: 700;
}
.admin .card-title--accent {
  color: var(--indigo-600);
}

.admin .content {
  order: 2;
  padding: 1rem;
  overflow-y: auto;
  min-width: 0;
  background-color: var(--green-100);
}
@media (min-width: 768px) {
  .admin .content {
    order: 1;
  }
}

.admin .errors {
  color: var(--red-500);
  min-height: 20px;
  margin-top: 1rem;
}

/* Inline progress indicator (admin shell — not the portal global bar) */
.admin .progress {
  margin-top: 0.5rem;
}

.admin .footer {
  text-align: center;
  color: var(--gray-500);
  font-size: 0.75rem;
  line-height: 1rem;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  border-top: 1px solid var(--gray-200);
}
