/* Reusable UI components */
.app-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow-sm);
}

.app-card-body {
  padding: 1.25rem;
}

.app-stat-card {
  text-align: left;
  height: 100%;
}

.app-stat-card .stat-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted-foreground);
  margin-bottom: 0.35rem;
}

.app-stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--foreground);
}

.app-stat-card .stat-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}

.app-stat-card .stat-icon-primary {
  background: var(--primary-soft);
  color: var(--primary);
}

.app-stat-card .stat-icon-accent {
  background: hsla(260, 70%, 52%, 0.12);
  color: var(--accent);
}

.app-stat-card .stat-icon-warning {
  background: hsla(15, 86%, 55%, 0.12);
  color: var(--secondary);
}

.app-page-header {
  margin-bottom: 1.5rem;
}

.app-page-header .page-subtitle {
  color: var(--muted-foreground);
  margin: 0.25rem 0 0;
  font-size: 0.9375rem;
}

.app-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

@media (min-width: 768px) {
  .app-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
  }

  .app-page-header .app-page-actions {
    margin-top: 0;
    flex-shrink: 0;
  }
}

/* Tables */
.app-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--card-border);
  border-radius: calc(var(--radius) + 2px);
  background: var(--card);
}

.app-table {
  margin-bottom: 0;
}

.app-table thead th {
  background: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

.app-table tbody td {
  vertical-align: middle;
  font-size: 0.9rem;
}

/* Forms */
.app-form .form-label {
  font-weight: 500;
  font-size: 0.875rem;
}

.app-form .form-control,
.app-form .form-select {
  max-width: none;
  border-color: var(--border);
  border-radius: var(--radius);
}

.app-form .form-control:focus,
.app-form .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.22);
}

.app-form .validation-summary-errors {
  background: hsla(0, 84%, 60%, 0.08);
  border: 1px solid hsla(0, 84%, 60%, 0.25);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  color: var(--destructive);
  font-size: 0.875rem;
}

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

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

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

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

/* Alerts */
.app-alert {
  border-radius: var(--radius);
  border-width: 1px;
  font-size: 0.9rem;
}

/* Dashboard grid */
.app-dashboard-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 576px) {
  .app-dashboard-grid.cols-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 992px) {
  .app-dashboard-grid.cols-4 {
    grid-template-columns: repeat(4, 1fr);
  }

  .app-dashboard-grid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.app-quick-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.app-quick-links li {
  border-bottom: 1px solid var(--card-border);
}

.app-quick-links li:last-child {
  border-bottom: none;
}

.app-quick-links a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  color: var(--foreground);
  text-decoration: none;
  font-size: 0.9rem;
}

.app-quick-links a:hover {
  color: var(--primary);
}

/* Signing session */
.signing-panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: calc(var(--radius) + 2px);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.signing-meta dt {
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  font-weight: 500;
}

/* User menu */
.app-user-menu .dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.65rem;
  background: var(--card);
  font-size: 0.875rem;
}

.app-user-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: hsla(180, 83%, 46%, 0.2);
  color: var(--primary-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.75rem;
}

.app-user-menu-topbar .app-user-menu-toggle-topbar {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.65rem;
  background: var(--card);
  font-size: 0.875rem;
  max-width: 220px;
}

.app-user-menu-topbar .dropdown-menu {
  min-width: 12rem;
}

/* Sidebar user card + logout (reference layout) */
.app-sidebar-user-panel {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
}

.app-sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: calc(var(--radius) + 2px);
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.app-sidebar-user-card:hover {
  background: var(--muted);
  border-color: hsl(210, 12%, 86%);
  color: inherit;
}

.app-sidebar-user-icon,
.app-sidebar-user-avatar {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 50%;
}

.app-sidebar-user-icon {
  color: var(--muted-foreground);
  font-size: 1.15rem;
}

.app-sidebar-user-avatar {
  background: linear-gradient(145deg, hsl(217, 91%, 58%), hsl(217, 91%, 45%));
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.app-sidebar-user-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.app-sidebar-user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--foreground);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar-user-handle,
.app-sidebar-user-meta,
.app-sidebar-user-org {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar-user-meta {
  font-size: 0.6875rem;
  font-weight: 500;
  color: hsl(217, 45%, 42%);
}

.app-sidebar-user-org {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
}

.app-sidebar-user-org span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar-logout-form {
  margin: 0;
  padding: 0;
}

.app-sidebar-logout-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.5rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: #9f1239;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.app-sidebar-logout-btn i {
  font-size: 1rem;
}

.app-sidebar-logout-btn:hover {
  background: rgba(159, 18, 57, 0.08);
  color: #881337;
}

.app-sidebar-logout-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(159, 18, 57, 0.2);
}

/* Confirm modal styles: see confirm-modal.css (loaded in _Layout for authenticated pages) */
