/* =============================================================
   BASE.CSS — Structural Design System
   Brand-agnostic. Swap in any theme-*.css to change appearance.
   No colors, fonts, or brand values live here.
   ============================================================= */

/* ----- Reset & Box Model ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; height: 100%; }
body { height: 100%; line-height: 1.5; -webkit-font-smoothing: antialiased; background: var(--c-body-bg); color: var(--c-text); }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
a { text-decoration: none; }

/* =============================================================
   SHELL LAYOUT
   ============================================================= */

/* Top Bar */
.shell-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 0;
  z-index: 200;
  padding: 0 1rem;
  background: var(--c-topbar-bg);
  isolation: isolate;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: var(--sidebar-width);
  flex-shrink: 0;
  padding-right: 1rem;
}

.topbar-brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-brand-name {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

/* Topbar Dropdowns */
.topbar-dropdown {
  position: relative;
}

.topbar-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  white-space: nowrap;
}

.topbar-dropdown-trigger:hover { border-color: var(--c-border); }
.topbar-dropdown-trigger:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 1px; }

.topbar-dropdown-trigger .chevron {
  width: 14px;
  height: 14px;
  opacity: 0.5;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.topbar-dropdown.open .chevron { transform: rotate(180deg); }

.topbar-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-dropdown);
  z-index: 500;
  overflow: hidden;
  display: none;
}

.topbar-dropdown.open .topbar-dropdown-menu { display: block; }

.topbar-dropdown-menu-header {
  padding: 0.625rem 0.875rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--c-border-subtle);
}

.topbar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  cursor: pointer;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
}

.topbar-dropdown-item:hover { background: var(--c-hover); }
.topbar-dropdown-item.active { font-weight: 500; }

.topbar-dropdown-item .item-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.6;
}

.topbar-dropdown-divider {
  height: 1px;
  background: var(--c-border-subtle);
  margin: 0.25rem 0;
}

.topbar-user-name {
  font-size: 0.875rem;
  font-weight: 600;
}

.topbar-user-email {
  font-size: 0.8125rem;
  margin-top: 0.125rem;
}

/* Icon used inline in table cells, detail meta etc */
.alert-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 0.0625rem;
}

/* Fix icon display in flex contexts */
i.icon {
  display: inline-block;
  flex-shrink: 0;
}

/* User Avatar */
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

/* Org Badge */
.org-badge {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Left Sidebar Nav */
.shell-sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.25s ease, width 0.22s ease;
  background: var(--c-sidebar-bg);
  isolation: isolate;
}

.nav-section {
  padding: 0.75rem 0.75rem 0.25rem;
}

.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 0.375rem;
  margin-bottom: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.4375rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  text-decoration: none;
  transition: background 0.1s ease;
}

.nav-item:hover { background: var(--c-nav-hover); }
.nav-item.active {
  background: var(--c-nav-active-bg);
  color: var(--c-nav-active-text);
  font-weight: 600;
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-item .nav-badge {
  margin-left: auto;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.0625rem 0.375rem;
  border-radius: 999px;
}

.nav-spacer { flex: 1; }

.nav-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--c-border-subtle);
}

/* Nav label — wrap all nav item text in this span */
.nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}


.shell-sidebar.collapsed {
  width: var(--sidebar-width-collapsed);
  overflow: visible;
}

.shell-sidebar.collapsed .nav-label {
  display: none;
}

.shell-sidebar.collapsed .nav-section-label {
  visibility: hidden;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

.shell-sidebar.collapsed .nav-item {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.shell-sidebar.collapsed .nav-footer {
  padding: 0.5rem 0.25rem;
}

/* Content area responds to collapsed sidebar */
.shell-sidebar.collapsed ~ .shell-content {
  margin-left: var(--sidebar-width-collapsed);
}

#collapseIcon {
  transition: transform 0.22s ease;
}

.shell-sidebar.collapsed #collapseIcon {
  transform: rotate(180deg);
}

/* Shell Content */
.shell-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  display: flex;
  flex-direction: column;
}

.page-container {
  flex: 1;
  padding: var(--page-padding);
  max-width: var(--content-max-width);
  width: 100%;
}

.page-container.full-width { max-width: none; }

/* Page Header */
.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
}

.page-subtitle {
  font-size: 0.875rem;
  margin-top: 0.125rem;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.breadcrumb-item { cursor: pointer; }
.breadcrumb-item:last-child { font-weight: 500; cursor: default; }
.breadcrumb-sep { opacity: 0.35; }

/* =============================================================
   BUTTONS
   ============================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.btn:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* Size Variants */
.btn-sm {
  padding: 0.3125rem 0.625rem;
  font-size: 0.8125rem;
  gap: 0.25rem;
}

.btn-lg {
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
}

.btn-icon {
  padding: 0.4375rem;
  width: 34px;
  height: 34px;
}

.btn-icon.btn-sm { width: 28px; height: 28px; padding: 0.3125rem; }
.btn-icon.btn-lg { width: 42px; height: 42px; padding: 0.625rem; }

/* Style Variants */
.btn-primary {
  background: var(--c-brand);
  color: var(--c-brand-text);
  border-color: var(--c-brand);
}
.btn-primary:hover { background: var(--c-brand-hover); border-color: var(--c-brand-hover); }

.btn-secondary {
  background: var(--c-btn-secondary-bg);
  color: var(--c-btn-secondary-text);
  border-color: var(--c-border);
}
.btn-secondary:hover { background: var(--c-btn-secondary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--c-text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--c-hover); color: var(--c-text); }

.btn-danger {
  background: var(--c-danger);
  color: #fff;
  border-color: var(--c-danger);
}
.btn-danger:hover { background: var(--c-danger-hover); border-color: var(--c-danger-hover); }

.btn-danger-ghost {
  background: transparent;
  color: var(--c-danger);
  border-color: transparent;
}
.btn-danger-ghost:hover { background: var(--c-danger-subtle); }

.btn .btn-icon-left,
.btn .btn-icon-right {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* =============================================================
   FORM ELEMENTS
   ============================================================= */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1.25rem;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
}

.form-label-required::after {
  content: ' *';
  color: var(--c-danger);
}

.form-hint {
  font-size: 0.8125rem;
  margin-top: 0.25rem;
}

.form-error {
  font-size: 0.8125rem;
  color: var(--c-danger);
  margin-top: 0.25rem;
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.4375rem 0.75rem;
  font-size: 0.9375rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  background: var(--c-input-bg);
  color: var(--c-text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
  line-height: 1.5;
}

.form-control::placeholder { color: var(--c-text-placeholder); }
.form-control:hover { border-color: var(--c-border-hover); }
.form-control:focus {
  outline: none;
  border-color: var(--c-brand);
  box-shadow: 0 0 0 3px var(--c-focus-ring);
}
.form-control.is-invalid { border-color: var(--c-danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px var(--c-danger-ring); }
.form-control:disabled { opacity: 0.55; cursor: not-allowed; }

.form-control-sm { padding: 0.3125rem 0.625rem; font-size: 0.875rem; }

textarea.form-control { resize: vertical; min-height: 80px; }

select.form-control { cursor: pointer; padding-right: 2rem; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
}

/* Checkbox & Radio */
.form-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.form-check-input {
  width: 16px;
  height: 16px;
  margin-top: 0.125rem;
  flex-shrink: 0;
  accent-color: var(--c-brand);
  cursor: pointer;
}

.form-check-label {
  font-size: 0.875rem;
  cursor: pointer;
}

/* Form Layout */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 1rem;
}

.form-section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--c-border-subtle);
}

.form-section:last-child { border-bottom: none; margin-bottom: 0; }

.form-section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.form-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--c-border-subtle);
  margin-top: 1.5rem;
}

.form-footer-right { margin-left: auto; }

/* =============================================================
   CARDS
   ============================================================= */

.card {
  background: var(--c-card-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--c-border-subtle);
}

.card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  flex: 1;
}

.card-body { padding: 1.25rem; }
.card-body-sm { padding: 0.875rem 1rem; }

.card-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--c-border-subtle);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Stat / Metric Cards */
.card-stat {
  background: var(--c-card-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 1.125rem 1.25rem;
}

.card-stat-label {
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
}

.card-stat-value {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

.card-stat-change {
  font-size: 0.8125rem;
  margin-top: 0.375rem;
  font-weight: 500;
}

.card-stat-change.up { color: var(--c-success); }
.card-stat-change.down { color: var(--c-danger); }

/* Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.card-grid-4 { grid-template-columns: repeat(4, 1fr); }
.card-grid-3 { grid-template-columns: repeat(3, 1fr); }
.card-grid-2 { grid-template-columns: repeat(2, 1fr); }

/* =============================================================
   TABLES
   ============================================================= */

.table-container {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-card-bg);
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--c-border-subtle);
  flex-wrap: wrap;
}

.table-toolbar-title {
  font-size: 0.9375rem;
  font-weight: 600;
  flex: 1;
}

.table-search {
  position: relative;
}

.table-search-icon {
  position: absolute;
  left: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  pointer-events: none;
  opacity: 0.45;
}

.table-search .form-control {
  padding-left: 2rem;
  width: 220px;
}

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

thead th {
  text-align: left;
  padding: 0.625rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--c-table-head-bg);
}

thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { background: var(--c-table-head-hover); }

thead th .sort-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  vertical-align: middle;
  opacity: 0.35;
  margin-left: 0.25rem;
}

thead th.sort-asc .sort-icon,
thead th.sort-desc .sort-icon { opacity: 1; color: var(--c-brand); }

tbody tr {
  border-bottom: 1px solid var(--c-border-subtle);
  transition: background 0.08s ease;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--c-table-row-hover); }

tbody td {
  padding: 0.625rem 1rem;
  vertical-align: middle;
}

tbody tr.selected { background: var(--c-table-selected); }

/* Cell Types */
.cell-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 0.12s ease;
}

tbody tr:hover .cell-actions { opacity: 1; }

.cell-meta {
  font-size: 0.8125rem;
  color: var(--c-text-muted);
}

.cell-numeric { text-align: right; font-variant-numeric: tabular-nums; }

/* Table Footer / Pagination */
.table-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--c-border-subtle);
  flex-wrap: wrap;
}

.table-count { font-size: 0.8125rem; flex: 1; }

.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
}

.page-btn:hover { background: var(--c-hover); }
.page-btn.active {
  background: var(--c-brand);
  color: var(--c-brand-text);
  border-color: var(--c-brand);
}

.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* =============================================================
   BADGES & STATUS
   ============================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-outline {
  background: transparent;
  border: 1px solid currentColor;
}

.badge-success { background: var(--c-success-subtle); color: var(--c-success-text); }
.badge-warning { background: var(--c-warning-subtle); color: var(--c-warning-text); }
.badge-danger  { background: var(--c-danger-subtle);  color: var(--c-danger-text); }
.badge-info    { background: var(--c-info-subtle);    color: var(--c-info-text); }
.badge-neutral { background: var(--c-neutral-subtle); color: var(--c-neutral-text); }
.badge-brand   { background: var(--c-brand-subtle);   color: var(--c-brand-text-on-subtle); }

/* =============================================================
   DETAIL / VIEW SCREEN
   ============================================================= */

.detail-card {
  background: var(--c-card-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--c-border-subtle);
  flex-wrap: wrap;
}

.detail-header-info { flex: 1; min-width: 0; }

.detail-title {
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
}

.detail-meta {
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.detail-meta-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.detail-body { padding: 1.5rem; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem 2rem;
}

.detail-field {}

.detail-field-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.detail-field-value {
  font-size: 0.9375rem;
}

.detail-field-value.empty { font-style: italic; }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--c-border);
  gap: 0;
  overflow-x: auto;
}

.tab {
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  white-space: nowrap;
  margin-bottom: -1px;
  color: var(--c-text-muted);
  transition: color 0.12s ease, border-color 0.12s ease;
}

.tab:hover { color: var(--c-text); }
.tab.active { color: var(--c-brand); border-bottom-color: var(--c-brand); }

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 0.3125rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  margin-left: 0.375rem;
}

/* =============================================================
   MODALS & DIALOGS
   ============================================================= */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--c-backdrop);
  z-index: 800;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal.show {
  display: flex;
}

.modal-dialog {
  background: var(--c-card-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-dialog.modal-sm { max-width: 380px; }
.modal-dialog.modal-lg { max-width: 720px; }
.modal-dialog.modal-xl { max-width: 960px; }

.modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.125rem 1.375rem;
  border-bottom: 1px solid var(--c-border-subtle);
  flex-shrink: 0;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
}

.modal-body {
  padding: 1.375rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.625rem;
  padding: 1rem 1.375rem;
  border-top: 1px solid var(--c-border-subtle);
  flex-shrink: 0;
}

.modal-danger .modal-header { border-bottom-color: var(--c-danger-subtle); }

.modal-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-icon-danger {
  background: var(--c-danger-subtle);
  color: var(--c-danger);
}

/* =============================================================
   ALERTS & TOASTS
   ============================================================= */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.alert-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 0.0625rem; }
.alert-body { flex: 1; }
.alert-title { font-weight: 600; margin-bottom: 0.125rem; }

.alert-success { background: var(--c-success-subtle); border-color: var(--c-success-border); color: var(--c-success-text); }
.alert-warning { background: var(--c-warning-subtle); border-color: var(--c-warning-border); color: var(--c-warning-text); }
.alert-danger  { background: var(--c-danger-subtle);  border-color: var(--c-danger-border);  color: var(--c-danger-text); }
.alert-info    { background: var(--c-info-subtle);    border-color: var(--c-info-border);    color: var(--c-info-text); }

/* Toast container */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: var(--c-toast-bg);
  color: var(--c-toast-text);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-modal);
  font-size: 0.875rem;
  min-width: 260px;
  max-width: 400px;
  animation: toast-in 0.2s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =============================================================
   EMPTY STATES
   ============================================================= */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 2rem;
  text-align: center;
}

.empty-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.35;
}

.empty-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

.empty-body {
  font-size: 0.875rem;
  max-width: 320px;
  margin-bottom: 1.25rem;
}

/* =============================================================
   LOADING
   ============================================================= */

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-brand);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-sm { width: 14px; height: 14px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: var(--c-skeleton);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.4s ease infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* =============================================================
   UTILITIES
   ============================================================= */

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.flex-1 { flex: 1; }
.ml-auto { margin-left: auto; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.text-muted { color: var(--c-text-muted); }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.text-right { text-align: right; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.d-none { display: none !important; }

/* =============================================================
   MOBILE RESPONSIVE
   ============================================================= */

@media (max-width: 768px) {
  .shell-hamburger {
    display: inline-flex !important;
  }

  .shell-sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
    z-index: 300;
  }

  .shell-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-modal);
  }

  .shell-content { margin-left: 0 !important; }

  .shell-sidebar.collapsed {
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }
  .shell-sidebar.collapsed .nav-label { display: inline; }
  .shell-sidebar.collapsed .nav-section-label {
    visibility: visible;
    height: auto;
    padding: 0 0.375rem;
    margin-bottom: 0.25rem;
    overflow: visible;
  }
  .shell-sidebar.collapsed .nav-item {
    justify-content: flex-start;
    padding: 0.4375rem 0.625rem;
  }
  .shell-sidebar.collapsed .nav-footer { padding: 0.75rem; }
  .sidebar-collapse-btn { display: none !important; }

  .topbar-brand { width: auto; }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--c-backdrop);
    z-index: 299;
  }

  .shell-sidebar.mobile-open ~ .sidebar-overlay { display: block; }

  .table-search .form-control { width: 160px; }

  .card-grid-4,
  .card-grid-3 { grid-template-columns: repeat(2, 1fr); }

  .card-grid-2 { grid-template-columns: 1fr; }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }

  .form-row { grid-template-columns: 1fr; }

  .detail-grid { grid-template-columns: 1fr; }

  .toast-container { left: 1rem; right: 1rem; bottom: 1rem; }
  .toast { min-width: 0; max-width: none; }
}

@media (max-width: 480px) {
  .card-grid-4,
  .card-grid-3,
  .card-grid-2 { grid-template-columns: 1fr; }

  .page-container { padding: 1rem; }
}

/* =============================================================
   JUSTBEHAVE CONVENTIONS
   CSS required for JustBehave behaviors to function correctly.
   ============================================================= */

.jb-dropdown-menu { display: none; }
.topbar-dropdown.open .jb-dropdown-menu { display: block; }
.topbar-dropdown.open .chevron { transform: rotate(180deg); }

.shell-sidebar.mobile-open {
  transform: translateX(0);
  box-shadow: var(--shadow-modal);
}

/* =============================================================
   DRAG HANDLE
   ============================================================= */

.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  flex-shrink: 0;
  color: var(--c-text-muted);
  cursor: grab;
  opacity: 0.4;
  transition: opacity 0.12s ease;
  touch-action: none;
}

.drag-handle:hover { opacity: 1; }
.drag-handle:active { cursor: grabbing; }

.drag-handle::before {
  content: '';
  display: block;
  width: 6px;
  height: 16px;
  background-image: radial-gradient(circle, var(--c-text-muted) 1px, transparent 1px);
  background-size: 3px 4px;
}

.dragging {
  opacity: 0.5;
  background: var(--c-brand-subtle);
  border-color: var(--c-brand);
}

/* =============================================================
   LOADING STATES
   ============================================================= */

.loading-spinner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.loading-spinner::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--c-border);
  border-top-color: var(--c-brand);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

/* =============================================================
   TOAST VARIANTS
   ============================================================= */

.toast-success { border-left: 3px solid var(--c-success); }
.toast-warning { border-left: 3px solid var(--c-warning); }
.toast-danger  { border-left: 3px solid var(--c-danger); }
.toast-info    { border-left: 3px solid var(--c-brand); }

/* =============================================================
   COPY BUTTON
   ============================================================= */

.btn-copy.copied {
  color: var(--c-success);
  border-color: var(--c-success-border);
  background: var(--c-success-subtle);
  pointer-events: none;
}

/* =============================================================
   PROGRESS BAR
   ============================================================= */

.progress {
  height: 6px;
  background: var(--c-neutral-subtle);
  border-radius: 999px;
  overflow: hidden;
  width: 100%;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--c-brand);
  transition: width 0.4s ease;
}

.progress-bar-success { background: var(--c-success); }
.progress-bar-warning { background: var(--c-warning); }
.progress-bar-danger  { background: var(--c-danger); }
