/**
 * Shared layout for the Clients/Sites/Assets/Inventory/Tickets app pages (code_standards.md §2.1/§2.5)
 * — loaded in addition to base.css. Same theming convention as base.css (see its header comment and
 * code_standards.md §2.7): every color that represents one of the fixed 12 roles is `var(--color-x)`,
 * never a hardcoded hex.
 */

/**
 * Phase 4.8 width constraint: widened from a fixed 960px to the shared 90%/1728px spec
 * (base.css's .app-shell) so old-style pages not yet retrofitted onto the new layout shell
 * (scripts/lib/layout.js, sub-task 2's job) still get the same overall width as every new
 * shell-built page, with zero HTML changes needed on this round -- these two class names are
 * reused as-is by layout.js's own generated markup (.app-header/.app-nav/.app-nav-link/.app-nav-user),
 * so both old and new pages share one visual language for the navbar.
 */
.page-shell-wide {
  width: 90%;
  max-width: 1728px;
  margin: 32px auto;
  padding: 24px 32px 32px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 90%;
  max-width: 1728px;
  margin: 0 auto;
  padding: 12px 32px;
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

/**
 * Phase 4.8: the new layout shell (scripts/lib/layout.js) renders a genuinely full-bleed navbar (no
 * boxed max-width of its own -- the outer #shell-sticky-header spans the entire viewport width) with
 * its brand/links/identity constrained to the shared .app-shell width instead, so the bar's colored
 * background reaches the screen edges while its content visually aligns with the page content below it
 * (same pattern most modern SaaS apps use). Old-style pages (not yet retrofitted, still using a plain
 * `.app-header` with no `.app-header-shell` modifier) keep the boxed look above, unchanged in kind, just
 * widened to match. `#shell-sticky-header` is what actually pins the whole bar (banner + navbar) to the
 * viewport top on scroll -- see layout.js's `buildShellSkeleton()` and nav.js's
 * `injectImpersonationBanner()` for why the banner is nested inside it rather than independently sticky.
 */
#shell-sticky-header {
  position: sticky;
  top: 0;
  z-index: 1000;
}

.app-header-shell {
  width: 100%;
  max-width: none;
  margin: 0;
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.app-nav-brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: var(--color-text-primary);
}

.app-nav-link {
  color: var(--color-text-primary);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.app-nav-link:hover {
  color: var(--color-primary);
}

.app-nav-link.active {
  border-bottom-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 600;
}

.app-nav-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

/**
 * Phase 4.8 layout shell -- body region (sidebar + main), sibling of #shell-sticky-header, both wrapped
 * in the same shared .app-shell width (base.css) so the sidebar/main region aligns with the navbar's
 * own constrained inner row above it.
 */
.app-body {
  display: flex;
  align-items: flex-start;
  gap: 32px;
  padding-top: 24px;
}

.app-sidebar {
  flex: 0 0 220px;
  width: 220px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 180px);
  padding: 8px 0 16px;
}

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

.app-sidebar-nav a {
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--color-text-primary);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar-nav a:hover {
  background-color: var(--color-background);
}

.app-sidebar-nav a.active {
  background-color: color-mix(in srgb, var(--color-primary) 12%, var(--color-surface));
  color: var(--color-primary);
  font-weight: 600;
}

/**
 * Phase 4.8 layout shell -- persistent version footer row, sibling of #shell-sticky-header/.app-body
 * (not nested inside .app-sidebar) so it stays visible on sections with no sidebar items, e.g.
 * `dashboard` (renderSidebar() hides #shell-sidebar entirely in that case).
 */
.app-footer-row {
  padding: 16px 0 24px;
}

.app-shell-version {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.app-main {
  flex: 1;
  min-width: 0;
  padding-bottom: 48px;
}

/* Dashboard landing pages (dashboard.html, admin-dashboard.html) -- at-a-glance summary cards. */
.dashboard-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.dashboard-card {
  display: block;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 20px;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.15s ease, transform 0.1s ease;
}

a.dashboard-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.dashboard-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.2;
}

.dashboard-card-label {
  margin-top: 4px;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.dashboard-card-loading .dashboard-card-value {
  color: var(--color-text-secondary);
}

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

.page-header-row h1 {
  margin: 0;
}

.toolbar-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 16px;
}

.toolbar-row .field {
  flex: 1;
  max-width: 320px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-bottom: 16px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

th {
  color: var(--color-text-secondary);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  background-color: var(--color-background);
}

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

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

td a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: none;
}

td a:hover {
  text-decoration: underline;
}

.empty-state {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  padding: 16px 0;
}

.pagination-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 0.85rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  row-gap: 10px;
  column-gap: 16px;
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.detail-grid dt {
  color: var(--color-text-secondary);
  font-weight: 600;
}

.detail-grid dd {
  margin: 0;
}

.actions-row {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.actions-row button,
.actions-row a.button-link {
  width: auto;
}

button.danger {
  background-color: var(--color-surface);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

button.danger:hover {
  background-color: color-mix(in srgb, var(--color-danger) 12%, var(--color-surface));
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.section-heading-plain {
  margin: 24px 0 12px;
  font-size: 1rem;
}

.field-error {
  color: var(--color-danger);
  font-size: 0.8rem;
  margin: 0;
}

/* Phase 7: provider-conditional credential field groups (payment-providers.html) -- swapped in/out via
   the `hidden` attribute as the provider <select> changes, one .field per credential input inside. */
.provider-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 32px 0;
}

.readonly-value {
  padding: 8px 10px;
  background-color: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 0.95rem;
  color: var(--color-text-secondary);
}

/* Phase 8: pretty-printed audit-log metadata JSON block (admin-audit-log.html / tenant-audit-log.html
   expandable detail rows). */
.audit-metadata-pre {
  margin: 0;
  padding: 10px 12px;
  background-color: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  color: var(--color-text-primary);
  overflow-x: auto;
  white-space: pre;
  max-width: 100%;
}

/* Phase 8: Plan/Feature override management table (admin-tenant-detail.html). */
.feature-overrides-table td .field {
  gap: 8px;
}

.feature-overrides-table input[type='number'] {
  width: 90px;
}

.feature-overrides-table .actions-row {
  margin-bottom: 0;
  flex-wrap: wrap;
  gap: 8px;
}

/* Photo gallery (assets-detail.html / inventory-detail.html) */
.photo-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0;
}

.photo-tile {
  width: 140px;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 6px;
  background-color: var(--color-surface);
  text-align: center;
}

.photo-tile img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 2px;
  background-color: var(--color-background);
  display: block;
  margin-bottom: 6px;
}

.photo-tile button {
  width: 100%;
  font-size: 0.8rem;
  padding: 6px 8px;
}

.photo-count-row {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* Phase 5 — reusable status badge (Invoices list/detail; same color-role convention as
   .theme-preview-badge above, but not scoped to the theme editor since Invoices needs it on real
   pages). Variant classes map directly to the fixed 12-role set -- no hardcoded hex anywhere here. */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge.neutral {
  background-color: color-mix(in srgb, var(--color-secondary) 15%, var(--color-surface));
  color: var(--color-secondary);
  border: 1px solid var(--color-secondary);
}

.badge.success {
  background-color: color-mix(in srgb, var(--color-success) 15%, var(--color-surface));
  color: var(--color-success);
  border: 1px solid var(--color-success);
}

.badge.warning {
  background-color: color-mix(in srgb, var(--color-warning) 15%, var(--color-surface));
  color: var(--color-warning);
  border: 1px solid var(--color-warning);
}

.badge.danger {
  background-color: color-mix(in srgb, var(--color-danger) 15%, var(--color-surface));
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.badge.info {
  background-color: color-mix(in srgb, var(--color-info) 15%, var(--color-surface));
  color: var(--color-info);
  border: 1px solid var(--color-info);
}

/* Phase 5 -- dynamic line-items mini-table (invoices-form.html) and the invoice pay summary
   (invoice-pay.html, public page, still styled via var(--color-x) -- Phase 4.8: /api/v1/theme/
   current.css supplies the values even pre-auth now, same endpoint every other page uses). */
.line-items-table input[type='text'],
.line-items-table input[type='number'] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 0.9rem;
}

.line-items-table td {
  vertical-align: top;
}

.totals-summary {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  margin: 12px 0 24px;
  font-size: 0.95rem;
}

.totals-summary .totals-row {
  display: flex;
  gap: 24px;
  min-width: 240px;
  justify-content: space-between;
}

.totals-summary .totals-row.grand-total {
  font-weight: 700;
  font-size: 1.05rem;
  border-top: 1px solid var(--color-border);
  padding-top: 6px;
}

.pay-link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.pay-link-row input[type='text'] {
  flex: 1;
  min-width: 240px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 0.9rem;
  background-color: var(--color-background);
}

/* Public invoice-pay page uses .page-shell (base.css) at a wider width for the line-items table. */
.pay-page-shell {
  max-width: 640px;
  margin: 48px auto;
  padding: 32px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

/* 3-way segmented toggle (admin-themes-list.html's Color Mode control -- Light/System/Dark). A group
   of connected plain <button>s; the active segment gets --color-primary background, inactive segments
   stay neutral (--color-surface background, --color-text-secondary text, --color-border divider). */
.segmented-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
}

.segmented-toggle-option {
  padding: 8px 18px;
  border: none;
  border-right: 1px solid var(--color-border);
  border-radius: 0;
  background-color: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented-toggle-option:last-child {
  border-right: none;
}

.segmented-toggle-option:hover:not(.active):not(:disabled) {
  background-color: var(--color-background);
  color: var(--color-text-primary);
}

.segmented-toggle-option.active {
  background-color: var(--color-primary);
  /* Same non-role foreground carve-out as button/.button-link's `color` in base.css -- only needs to
     contrast against --color-primary. */
  color: #ffffff;
}

.segmented-toggle-option:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}

.segmented-toggle-option:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

/* Theme editor (admin-themes-form.html) -- page chrome itself stays var(--color-x) as usual; only the
   role inputs' own values and the live-preview panel legitimately carry raw hex (code_standards.md
   §2.7's explicit carve-out -- this IS the content being edited, not page chrome). */
.theme-color-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.theme-color-row {
  display: grid;
  grid-template-columns: 200px auto 110px 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}

.theme-color-row label {
  font-weight: 600;
}

.theme-color-row input[type='color'] {
  width: 44px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  cursor: pointer;
}

.theme-color-row input[type='text'] {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 0.9rem;
  font-family: monospace;
}

.theme-color-row .help-text {
  margin: 0;
}

/* Phase 4.9: light + dark previews shown side by side so a Super Admin can see both without toggling
   their OS/browser color scheme. Stacks on narrow viewports. */
.theme-preview-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.theme-preview-row > div {
  flex: 1;
  min-width: 260px;
}

.theme-preview {
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 24px;
  background-color: var(--color-background);
}

.theme-preview-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  margin-bottom: 12px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 3px;
}

.theme-preview-nav-brand {
  font-weight: 700;
  color: var(--color-text-primary);
}

.theme-preview-card {
  padding: 14px;
  margin-bottom: 12px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  color: var(--color-text-primary);
}

.theme-preview-card p {
  margin: 4px 0 12px;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

.theme-preview-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.theme-preview-button {
  padding: 8px 12px;
  border-radius: 3px;
  font-size: 0.85rem;
  border: 1px solid var(--color-primary);
  background-color: var(--color-primary);
  color: #ffffff;
}

.theme-preview-button.secondary {
  background-color: var(--color-surface);
  color: var(--color-secondary);
  border-color: var(--color-secondary);
}

.theme-preview-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-preview-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
}

.theme-preview-badge.success {
  background-color: color-mix(in srgb, var(--color-success) 15%, var(--color-surface));
  color: var(--color-success);
  border: 1px solid var(--color-success);
}

.theme-preview-badge.warning {
  background-color: color-mix(in srgb, var(--color-warning) 15%, var(--color-surface));
  color: var(--color-warning);
  border: 1px solid var(--color-warning);
}

.theme-preview-badge.danger {
  background-color: color-mix(in srgb, var(--color-danger) 15%, var(--color-surface));
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.theme-preview-badge.info {
  background-color: color-mix(in srgb, var(--color-info) 15%, var(--color-surface));
  color: var(--color-info);
  border: 1px solid var(--color-info);
}

/**
 * Client Portal shell (Phase 6, scripts/lib/portal-nav.js) — a deliberately simpler, single-level
 * header (no sidebar, no top-level section switcher beyond a flat 4-link nav) so the portal reads as
 * visibly distinct in structure from the staff app's navbar+sidebar shell, while still reusing
 * .app-header/.app-nav/.app-nav-link/.app-nav-user (base.css/app.css above) so both shells track the
 * one active app-wide theme identically -- no separate stylesheet, no hardcoded colors.
 */
.portal-header {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

.portal-header-inner {
  padding: 12px 32px;
}

.portal-main {
  padding-top: 24px;
  padding-bottom: 48px;
}

.portal-not-available {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  padding: 16px 0;
}
