/* GENERATED by build.py from static/css/src/*.css. Edit those files, then run: python build.py */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-sizing: border-box;
  height: 32px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-bg-dark), 0 0 0 4px var(--color-primary);
}

.btn-primary,
.btn-danger,
.btn-success {
  color: white;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 1px 2px rgba(15, 23, 42, 0.18);
}

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

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

.btn-secondary {
  background: var(--color-bg-dark);
  color: var(--color-text);
  border-color: var(--color-border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

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

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

.btn-ghost:hover {
  background: rgba(37, 99, 235, 0.09);
}

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

.btn-danger:hover {
  background: #b91c1c;
}

.btn-success {
  background: #15803d;
  border-color: #166534;
}

.btn-success:hover {
  background: #166534;
}

.btn-sm {
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 5px;
}

.btn-lg {
  height: 40px;
  padding: 0 20px;
  font-size: 14px;
  border-radius: 7px;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Link Buttons - Style links as buttons */
a.btn {
  text-decoration: none;
  display: inline-flex;
}

a.btn:visited {
  color: inherit;
}

a.btn-primary:visited,
a.btn-danger:visited,
a.btn-success:visited {
  color: white;
}

a.btn-ghost:visited {
  color: var(--color-primary-hover);
}

/* Forms: one standard look for every control */
.form-grid {
  display: grid;
  gap: 0 var(--spacing-xl);
  grid-template-columns: 1fr;
}

.form-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3,
.form-grid .span-full,
.form-grid .form-section { grid-column: 1 / -1; }

@media (max-width: 640px) {
  .form-cols-2, .form-cols-3 { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: auto; }
}

.form-group {
  margin-bottom: var(--spacing-xl);
}

.form-section {
  margin: var(--spacing-lg) 0 var(--spacing-xl);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--color-border);
}

.form-section-title {
  font-size: 13px;
  font-weight: 600;
}

.form-actions {
  margin-top: var(--spacing-lg);
}

label {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
  font-size: var(--font-md);
}

/* Text-like controls */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]),
select,
textarea {
  width: 100%;
  min-height: 30px;
  padding: 5px 8px;
  background: var(--color-bg-dark);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: var(--font-md);
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-light);
  opacity: 0.7;
}

input:hover:not(:disabled):not(:focus),
select:hover:not(:disabled):not(:focus),
textarea:hover:not(:disabled):not(:focus) {
  border-color: var(--color-text-light);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--color-bg);
}

input[readonly],
textarea[readonly] {
  background: var(--color-bg);
}

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

select {
  appearance: none;
  padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text-light) 50%),
                    linear-gradient(135deg, var(--color-text-light) 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 8px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

select[multiple] {
  padding-right: 8px;
  background-image: none;
}

/* Sizes */
.form-sm input:not([type="checkbox"]):not([type="radio"]),
.form-sm select { min-height: 24px; padding: 2px 6px; font-size: var(--font-sm); }
.form-lg input:not([type="checkbox"]):not([type="radio"]),
.form-lg select { min-height: 38px; padding: 8px 10px; font-size: 14px; }

/* Prefix / suffix (e.g. $ 100, 5 %) */
.input-wrap {
  display: flex;
  align-items: stretch;
}

.input-wrap.has-affix input {
  flex: 1;
  min-width: 0;
}

.input-affix {
  display: flex;
  align-items: center;
  padding: 0 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-light);
  font-size: var(--font-md);
  white-space: nowrap;
}

.input-affix:first-child { border-right: none; border-radius: var(--radius) 0 0 var(--radius); }
.input-affix:last-child { border-left: none; border-radius: 0 var(--radius) var(--radius) 0; }
.input-wrap.has-affix input:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-wrap.has-affix input:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* File, range, color */
input[type="file"] {
  width: 100%;
  font-size: var(--font-md);
  color: var(--color-text-light);
}

input[type="file"]::file-selector-button {
  margin-right: 8px;
  padding: 5px 10px;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  border-color: var(--color-text-light);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
}

input[type="color"] {
  width: 44px;
  height: 30px;
  padding: 2px;
  background: var(--color-bg-dark);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
}

/* Checkbox / radio / switch */
input[type="checkbox"],
input[type="radio"] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-weight: 400;
  font-size: var(--font-md);
  cursor: pointer;
}

.choice-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.choice-group.inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px var(--spacing-xl);
}

.choice-group .check-label { margin-bottom: 0; }

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch {
  position: relative;
}

.switch-track {
  position: relative;
  flex: none;
  width: 30px;
  height: 16px;
  background: var(--color-border);
  border-radius: 999px;
  transition: background 0.15s;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}

.switch input:checked + .switch-track { background: var(--color-primary); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus-ring); }
.switch input:disabled + .switch-track { opacity: 0.5; }

/* Messages and states */
.form-label {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
  font-size: var(--font-md);
}

.form-help {
  margin-top: 3px;
  color: var(--color-text-light);
  font-size: var(--font-sm);
}

.form-error {
  margin-top: 3px;
  color: var(--color-danger);
  font-size: var(--font-sm);
}

.required-mark {
  color: var(--color-danger);
}

.has-error input:not([type="checkbox"]):not([type="radio"]),
.has-error select,
.has-error textarea {
  border-color: var(--color-danger);
}

.has-error input:focus,
.has-error select:focus,
.has-error textarea:focus {
  box-shadow: var(--focus-ring-danger);
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-bg-dark);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table thead {
  background: color-mix(in srgb, var(--color-text) 8%, var(--color-bg-dark));
  border-bottom: 1px solid var(--color-border);
}

.table th {
  padding: var(--spacing-md);
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text-light);
}

.table td {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

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

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

/* Rows with children. A parent is a plain bold row with a chevron toggle; its children sit
   indented under a guide line on the same surface (no tints). See "Nested child table" below. */
.table-parent-row { font-weight: 600; }

.table-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: var(--spacing-lg);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--color-text-light);
  vertical-align: middle;
  cursor: pointer;
}

.table-toggle[hidden] { display: none; }
.table-toggle:hover { background: var(--color-bg); color: var(--color-text); }
.table-toggle:focus-visible { outline: var(--focus-outline); outline-offset: 1px; }
.table-toggle svg { transition: transform 0.15s; }
.table-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }

/* Legacy child rows (no child_headers): same columns as the parent */
.table-child-row {
  font-size: var(--font-sm);
  font-weight: 400;
}

.table-child-indent {
  padding-left: var(--spacing-lg);
  color: var(--color-text-light);
}

/* Table interactive (filter + sort) */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-toolbar {
  display: flex;
  align-items: center;
  padding: var(--spacing-sm) 0 var(--spacing-md) 0;
}

.table-filter-input {
  padding: var(--spacing-xs) var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: var(--font-sm);
  width: 220px;
  outline: none;
  font-family: inherit;
  background: var(--color-bg-dark);
  color: var(--color-text);
}

.table-filter-input:focus {
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}

.table-th-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.table-th-sortable:hover {
  background: var(--color-bg);
}

.sort-icon {
  color: var(--color-text-light);
  font-size: 10px;
  margin-left: 3px;
}

.sort-asc .sort-icon::after {
  content: ' ↑';
  color: var(--color-primary);
}

.sort-desc .sort-icon::after {
  content: ' ↓';
  color: var(--color-primary);
}

.sort-asc .sort-icon,
.sort-desc .sort-icon {
  display: none;
}

/* Table pagination */
.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-md) 0 var(--spacing-xs) 0;
  font-size: var(--font-sm);
}

.pagination-info {
  color: var(--color-text-light);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.pagination-pages {
  display: flex;
  gap: var(--spacing-sm);
}

/* Page buttons are the one place with roomier click targets */
.table-pagination .btn,
.pagination .btn {
  min-width: 32px;
  min-height: 32px;
  padding: var(--spacing-lg) var(--spacing-xl);
}

.pagination-ellipsis {
  display: flex;
  align-items: center;
  padding: 0 var(--spacing-xs);
  color: var(--color-text-light);
}

/* Nested child table: its own header, indented under a guide line */
.table .table-child-container-row:hover { background: none; }

.table-child-container-row > td {
  padding: 0 0 var(--spacing-lg) 26px;
  border-bottom: 1px solid var(--color-border);
}

.table-nested {
  width: 100%;
  border-collapse: collapse;
  border-left: 2px solid var(--color-border);
}

.table-nested thead {
  background: none;
  border-bottom: 0;
}

.table-nested thead th {
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-light);
}

.table-nested tbody td {
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--font-sm);
  font-weight: 400;
}

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

.table-nested tbody tr:hover {
  background: color-mix(in srgb, var(--color-text) 4%, var(--color-bg-dark));
}

/* Cards */
.card {
  background: var(--color-bg-dark);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow);
}

.card-header {
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

.card-body {
  margin-bottom: var(--spacing-md);
}

.card-footer {
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--color-border);
}

/* Card height support - when height is set on card */
.card[style*="height"] {
  display: flex;
  flex-direction: column;
}

.card[style*="height"] .card-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* Card Grid - displays multiple cards side-by-side */
.card-grid {
  max-width: 100%; /* a grid_width larger than its container never overflows it */
  display: grid;
  grid-template-columns: repeat(var(--grid-columns, 3), 1fr);
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
}

/* Automatic grid (default): cards sit side by side and wrap to the next row when
   they would get narrower than --card-min. No breakpoints needed.
   .card-row does the same for hand-written <div class="card"> children. */
.card-grid-auto,
.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--card-min, 280px), 100%), var(--card-max, 360px)));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
  align-items: start;
}

.card-row > .card {
  min-width: 0;
}

/* Card sizing on a page: a card directly inside .content is card-sized
   (--card-width, default 360px) and sits beside the next card until the row is full.
   Add .card-wide (or card(wide=True)) for a full-width card, e.g. one holding a table. */
.content > .card:not(.card-wide) {
  flex: 0 1 var(--card-width, 360px);
}

/* Card grid height support - when height is set on grid */
.card-grid[style*="height"] {
  align-content: start;
}

.card-grid-item {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Stat card */
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  color: var(--color-text-light);
  font-size: var(--font-sm);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: var(--font-sm);
}

.stat-delta {
  font-weight: 600;
  color: var(--color-text-light);
}

.stat-good { color: var(--color-success); }
.stat-bad { color: var(--color-danger); }

/* Hamburger Toggle Button */
.sidebar-toggle {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 24px;
  height: 18px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-right: var(--spacing-lg);
}

.sidebar-toggle span {
  display: block;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* Sidebar Mobile Overlay */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  pointer-events: none;
}

#sidebar-overlay.active {
  display: block;
}

/* Sidebar Navigation */
.nav {
  list-style: none;
}

.nav-item {
  margin-bottom: var(--spacing-sm);
}

.nav-link {
  display: block;
  padding: var(--spacing-sm) var(--spacing-md);
  color: var(--color-text);
  text-decoration: none;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.nav-link:hover {
  background: var(--color-bg);
}

.nav-link.active {
  background: var(--color-primary);
  color: white;
}

.nav-group {
  margin-bottom: var(--spacing-sm);
}

.nav-group-title {
  display: block;
  padding: var(--spacing-sm) var(--spacing-md);
  padding-bottom: var(--spacing-md);
  margin-bottom: var(--spacing-md);
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--color-primary);
}

.nav-submenu {
  list-style: none;
}

.nav-sublink {
  padding-left: calc(var(--spacing-md) * 2 + 4px) !important;
  font-size: var(--font-md);
  color: var(--color-text-light);
}

.nav-sublink:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

/* Auth pages (login, errors) */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--spacing-xl);
}

.auth-box {
  width: 100%;
  max-width: 360px;
}

.auth-brand {
  margin-bottom: var(--spacing-xl);
  text-align: center;
  font-size: 16px;
  font-weight: 700;
}

.auth-box .card { padding: var(--spacing-xl) 16px; }

.error-code {
  font-size: 48px;
  font-weight: 700;
  line-height: 1;
  color: var(--color-text-light);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--color-bg-dark);
  border-radius: var(--radius);
  padding: var(--spacing-lg);
  max-width: 500px;
  width: 90%;
  box-shadow: var(--shadow-md);
}

.modal-header {
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

.modal-close {
  float: right;
  background: none;
  border: none;
  padding: 0;
  line-height: 1;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  color: var(--color-text-light);
}

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

.modal-body {
  margin-bottom: var(--spacing-md);
}

.modal-footer {
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--color-border);
  text-align: right;
}

.modal-footer .btn {
  margin-left: var(--spacing-md);
}

/* Alerts */
.alert {
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
  border-left: 4px solid;
  border-radius: var(--radius);
}

.alert-info {
  background: var(--alert-info-bg);
  border-color: var(--color-primary);
  color: var(--alert-info-text);
}

.alert-success {
  background: var(--alert-success-bg);
  border-color: var(--color-success);
  color: var(--alert-success-text);
}

.alert-warning {
  background: var(--alert-warning-bg);
  border-color: var(--color-warning);
  color: var(--alert-warning-text);
}

.alert-danger {
  background: var(--alert-danger-bg);
  border-color: var(--color-danger);
  color: var(--alert-danger-text);
}

/* Toasts */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: calc(100vw - 40px);
}

.toast-stack .alert {
  min-width: 260px;
  margin: 0;
  box-shadow: var(--shadow-md);
}

/* Empty / loading states */
.empty-state {
  padding: 32px var(--spacing-xl);
  text-align: center;
}

.empty-state-title {
  margin-bottom: var(--spacing-sm);
  font-size: 14px;
  font-weight: 600;
}

.empty-state .btn {
  margin-top: var(--spacing-lg);
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

.spinner-sm { width: 12px; height: 12px; }
.spinner-lg { width: 30px; height: 30px; border-width: 3px; }

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

.skeleton-line {
  height: 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-bg) 50%, var(--color-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.is-loading {
  position: relative;
  pointer-events: none;
}

.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--color-bg-dark) 70%, transparent);
  border-radius: inherit;
}

.is-loading::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  z-index: 1;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .spinner, .skeleton-line, .is-loading::before { animation-duration: 3s; }
}

/* Badges */
.badge {
  --badge-color: var(--color-text-light);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: var(--font-sm);
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  color: var(--badge-color);
  background: color-mix(in srgb, var(--badge-color) 14%, transparent);
}

.badge-info { --badge-color: var(--color-primary); }
.badge-success { --badge-color: var(--color-success); }
.badge-warning { --badge-color: var(--color-warning); }
.badge-danger { --badge-color: var(--color-danger); }

.badge-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--badge-color);
}

/* Tabs (Chrome style) */
.tabs {
  --tab-flare: 8px;
  width: 100%;
}

.tab-list {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: var(--spacing-lg) var(--tab-flare) 0;
  background: var(--color-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* tabs scroll sideways when they do not fit; no bar needed */
}

.tab-list::-webkit-scrollbar { display: none; }

.tab-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: transparent;
  border: none;
  border-radius: 8px 8px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-light);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover:not(:disabled):not(.active) {
  background: color-mix(in srgb, var(--color-text) 8%, transparent);
  color: var(--color-text);
}

.tab-btn.active {
  background: var(--color-bg-dark);
  color: var(--color-text);
  z-index: 1;
}

/* Inverted corner flares that blend the active tab into the panel */
.tab-btn.active::before,
.tab-btn.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: var(--tab-flare);
  height: var(--tab-flare);
  pointer-events: none;
}

.tab-btn.active::before {
  left: calc(var(--tab-flare) * -1);
  background: radial-gradient(circle at top left, transparent var(--tab-flare), var(--color-bg-dark) var(--tab-flare));
}

.tab-btn.active::after {
  right: calc(var(--tab-flare) * -1);
  background: radial-gradient(circle at top right, transparent var(--tab-flare), var(--color-bg-dark) var(--tab-flare));
}

.tab-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tab-btn:focus-visible {
  outline: var(--focus-outline);
  outline-offset: -2px;
}

.tab-badge {
  background: var(--color-border);
  border-radius: 10px;
  padding: 0 6px;
  font-size: var(--font-sm);
  color: var(--color-text-light);
}

.tab-btn.active .tab-badge {
  background: var(--color-primary);
  color: white;
}

.tab-panel {
  display: none;
  padding: var(--spacing-xl);
  background: var(--color-bg-dark);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.tab-panel.active {
  display: block;
}

/* Card with tabs: the card supplies the surface, so panels are borderless */
.card-tabs .tab-panel {
  padding: var(--spacing-lg) 0 0;
  background: transparent;
  border: none;
  border-radius: 0;
}

/* Accordion */
.accordion {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg-dark);
}

.accordion-item + .accordion-item {
  border-top: 1px solid var(--color-border);
}

.accordion-item summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.accordion-item summary::-webkit-details-marker { display: none; }

.accordion-item summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--color-text-light);
  border-bottom: 2px solid var(--color-text-light);
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.accordion-item[open] summary::after { transform: rotate(-135deg); }

.accordion-item summary:hover { background: var(--color-bg); }
.accordion-item summary:focus-visible { outline: var(--focus-outline); outline-offset: -2px; }

.accordion-body {
  padding: 4px 12px 12px;
}

/* Breadcrumbs */
.breadcrumbs {
  margin-bottom: var(--spacing-lg);
  font-size: var(--font-md);
}

.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  gap: 6px;
}

.breadcrumbs li + li::before {
  content: "/";
  margin-right: 6px;
  color: var(--color-text-light);
}

.breadcrumbs a {
  color: var(--color-primary);
  text-decoration: none;
}

.breadcrumbs a:hover {
  text-decoration: underline;
}

.breadcrumbs [aria-current="page"] {
  color: var(--color-text-light);
}

/* Server-side pagination */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: var(--spacing-lg) 0;
}

.pagination .btn.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.pagination-gap {
  padding: 0 4px;
  color: var(--color-text-light);
}

/* Page header */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--spacing-lg);
}

.page-header .breadcrumbs {
  margin-bottom: 2px;
}

.page-header-title {
  margin: 0;
  font-size: 18px;
}

.page-header-sub {
  margin: 2px 0 0;
}

.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-lg);
}

/* Segmented filter */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
}

.segmented-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px;
  background: none;
  border: none;
  border-radius: 999px;
  color: var(--color-text-light);
  font: inherit;
  font-size: var(--font-md);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.segmented-item:hover:not(.active) { color: var(--color-text); }

.segmented-item.active {
  background: var(--color-bg-dark);
  color: var(--color-text);
  box-shadow: var(--shadow);
}

.segmented-item:focus-visible { outline: var(--focus-outline); outline-offset: 1px; }

/* Dropdown */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  z-index: 500;
  min-width: 160px;
  padding: 4px 0;
  background: var(--color-bg-dark);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.dropdown-left { left: 0; }
.dropdown-right { right: 0; }

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 6px 12px;
  background: none;
  border: none;
  text-align: left;
  font: inherit;
  font-size: var(--font-md);
  color: var(--color-text);
  text-decoration: none;
  cursor: pointer;
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
  background: var(--color-bg);
  outline: none;
}

.dropdown-item.danger {
  color: var(--color-danger);
}

.dropdown-divider {
  height: 1px;
  margin: 4px 0;
  background: var(--color-border);
}

.btn-icon {
  background: transparent;
  color: var(--color-text-light);
  border-color: transparent;
}

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

/* Tooltip (any element with data-tooltip) */
[data-tooltip] {
  position: relative;
}

.tooltip {
  border-bottom: 1px dotted var(--color-text-light);
  cursor: help;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  z-index: 600;
  width: max-content;
  max-width: 240px;
  padding: 4px 8px;
  background: #111827;
  color: #f9fafb;
  border-radius: var(--radius);
  font-size: var(--font-sm);
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
}

[data-tooltip]:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
}

/* Popover (reuses dropdown behavior) */
.popover-body {
  min-width: 220px;
  padding: 10px 12px;
  font-size: var(--font-md);
}

/* Avatar and user menu */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: hsl(var(--avatar-hue, 220), 55%, 45%);
  color: #fff;
  font-size: var(--font-sm);
  font-weight: 600;
  object-fit: cover;
}

.avatar-sm { width: 22px; height: 22px; font-size: 10px; }
.avatar-lg { width: 40px; height: 40px; font-size: 14px; }

.user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px 2px 2px;
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--color-text);
  font: inherit;
  cursor: pointer;
}

.user-trigger:hover { background: var(--color-bg); border-color: var(--color-border); }

.user-menu-head {
  padding: 6px 12px;
  font-size: var(--font-md);
}

@media (max-width: 640px) {
  .user-name { display: none; }
}

/* Sidebar brand, footer and badge (neutral, work in the default sidebar too) */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 6px 10px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  background: var(--color-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.sidebar-brand-text small {
  font-size: 10px;
  color: var(--color-text-light);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: var(--spacing-lg);
  padding: 8px 6px 2px;
  border-top: 1px solid var(--color-border);
}

.sidebar-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-bg);
  font-size: 9px;
  font-weight: 700;
}

.sidebar-footer-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.sidebar-footer-text small {
  font-size: 10px;
  color: var(--color-text-light);
}

.nav-badge {
  margin-left: auto;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--color-border);
  color: var(--color-text);
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
}

/* Sidebar: Slate (opt-in)
   Add class "sidebar-slate" to <aside class="sidebar">: dark surface, quiet group titles,
   tinted active row with an accent bar. Override the --sidebar-* values in your app CSS to retheme. */
.sidebar-slate {
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #94a3b8;
  --sidebar-strong: #ffffff;
  --sidebar-hover: #273449;
  --sidebar-active-bg: #1d3a6e;
  --sidebar-accent: #60a5fa;
  --sidebar-line: #334155;

  display: flex;
  flex-direction: column;
  padding: var(--spacing-xl) var(--spacing-lg);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right-color: var(--sidebar-line);
}

.sidebar-slate nav { flex: 1; }

.sidebar-slate h3,
.sidebar-slate .sidebar-brand-text strong { color: var(--sidebar-strong); }

.sidebar-slate .sidebar-brand-text small,
.sidebar-slate .sidebar-footer-text small { color: var(--sidebar-muted); }

.sidebar-slate .nav-link {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
  color: var(--sidebar-text);
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.sidebar-slate .nav-link:hover,
.sidebar-slate .nav-sublink:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-strong);
}

.sidebar-slate .nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-strong);
  border-left-color: var(--sidebar-accent);
  font-weight: 600;
}

.sidebar-slate .nav-link:focus-visible {
  outline: 2px solid var(--sidebar-accent);
  outline-offset: -2px;
}

.sidebar-slate .nav-sublink {
  padding-left: 14px !important;
  color: var(--sidebar-text);
}

.sidebar-slate .nav-group-title {
  margin-bottom: 0;
  padding: 12px 8px 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
  border-bottom: 0;
}

.sidebar-slate .nav-badge {
  background: var(--sidebar-line);
  color: var(--sidebar-strong);
}

.sidebar-slate .sidebar-footer { border-top-color: var(--sidebar-line); }

.sidebar-slate .sidebar-avatar {
  background: var(--sidebar-line);
  color: var(--sidebar-strong);
}

.sidebar-slate .sidebar-footer-text strong { color: var(--sidebar-strong); }

/* Stay in view while the page scrolls (on mobile the sidebar is an off-canvas drawer: see mobile.css) */
@media (min-width: 769px) {
  .sidebar-slate {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
  }
}
