/* ============================================================
   SCREENFLOW BACKOFFICE — COMPONENTS.CSS
   Buttons, Cards, Badges, Forms, Tables, Modals, Dropdowns...
   ============================================================ */

/* ============================================================
   AVATAR
   ============================================================ */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--brand-primary-muted);
  color: var(--brand-primary);
  letter-spacing: 0.02em;
  font-family: var(--font-display);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-xs  { width: 24px; height: 24px; font-size: 10px; }
.avatar-sm  { width: 32px; height: 32px; font-size: 12px; }
.avatar-md  { width: 40px; height: 40px; font-size: 14px; }
.avatar-lg  { width: 48px; height: 48px; font-size: 16px; }
.avatar-xl  { width: 64px; height: 64px; font-size: 20px; }
.avatar-2xl { width: 80px; height: 80px; font-size: 24px; }

.avatar-green   { background: var(--color-success-bg); color: var(--color-success); }
.avatar-blue    { background: var(--color-info-bg); color: var(--color-info); }
.avatar-purple  { background: rgba(98,59,215,0.10); color: var(--brand-accent); }
.avatar-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.avatar-red     { background: var(--color-danger-bg); color: var(--color-danger); }

.avatar-group {
  display: flex;
  align-items: center;
}

.avatar-group .avatar {
  border: 2px solid var(--color-bg-surface);
  margin-left: -8px;
}

.avatar-group .avatar:first-child { margin-left: 0; }

/* ============================================================
   STATUS INDICATOR
   ============================================================ */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.status-dot.online    { background: var(--color-success); box-shadow: 0 0 0 2px var(--color-success-bg); }
.status-dot.offline   { background: var(--color-text-disabled); }
.status-dot.warning   { background: var(--color-warning-border); box-shadow: 0 0 0 2px var(--color-warning-bg); }
.status-dot.danger    { background: var(--color-danger-border); box-shadow: 0 0 0 2px var(--color-danger-bg); }
.status-dot.info      { background: var(--color-info-border); }
.status-dot.pulse {
  animation: pulse-dot 2s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(54,145,95,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(54,145,95,0); }
}

/* ============================================================
   BADGE
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.badge svg { width: 10px; height: 10px; }

.badge-primary  { background: var(--brand-primary-light); color: var(--brand-primary); }
.badge-success  { background: var(--color-success-bg);    color: var(--color-success); }
.badge-warning  { background: var(--color-warning-bg);    color: var(--color-warning); }
.badge-danger   { background: var(--color-danger-bg);     color: var(--color-danger); }
.badge-info     { background: var(--color-info-bg);       color: var(--color-info); }
.badge-default  { background: var(--color-bg-subtle);     color: var(--color-text-secondary); }
.badge-dark     { background: var(--color-text-primary);  color: white; }
.badge-purple   { background: rgba(98,59,215,0.10);       color: var(--brand-accent); }

.badge-sm { padding: 1px 6px; font-size: 10px; }
.badge-lg { padding: 4px 10px; font-size: var(--text-sm); }

.badge-outline-success { background: transparent; border: 1px solid var(--color-success-border); color: var(--color-success); }
.badge-outline-danger  { background: transparent; border: 1px solid var(--color-danger-border);  color: var(--color-danger); }
.badge-outline-warning { background: transparent; border: 1px solid var(--color-warning-border); color: var(--color-warning); }
.badge-outline-info    { background: transparent; border: 1px solid var(--color-info-border);    color: var(--color-info); }

/* Device status badges */
.badge-online  { background: var(--color-success-bg); color: var(--color-success); }
.badge-offline { background: var(--color-bg-subtle);  color: var(--color-text-tertiary); }
.badge-maintenance { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-error   { background: var(--color-danger-bg);  color: var(--color-danger); }

/* Role badges */
.badge-role-superadmin { background: rgba(98,59,215,0.10); color: var(--brand-accent); }
.badge-role-admin      { background: var(--brand-primary-light); color: var(--brand-primary); }
.badge-role-user       { background: var(--color-bg-subtle); color: var(--color-text-secondary); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.5;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  vertical-align: middle;
  position: relative;
  overflow: hidden;
}

.btn:focus-visible { box-shadow: var(--shadow-focus); outline: none; }

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-xs  { padding: 2px 10px; font-size: var(--text-xs); }
.btn-sm  { padding: 5px 12px; font-size: var(--text-sm); }
.btn-lg  { padding: 10px 20px; font-size: var(--text-base); }
.btn-xl  { padding: 13px 24px; font-size: var(--text-md); }
.btn-icon { padding: var(--space-2); aspect-ratio: 1; }
.btn-icon-sm { padding: 6px; aspect-ratio: 1; }

.btn-primary {
  background: var(--brand-primary);
  color: white;
  border-color: var(--brand-primary);
}
.btn-primary:hover   { background: var(--brand-primary-hover); border-color: var(--brand-primary-hover); }
.btn-primary:active  { transform: scale(0.98); }

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

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--color-bg-subtle); color: var(--color-text-primary); }

.btn-danger {
  background: var(--color-danger);
  color: white;
  border-color: var(--color-danger);
}
.btn-danger:hover { background: #a32700; }

.btn-danger-soft {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: transparent;
}
.btn-danger-soft:hover { background: var(--color-danger-border); color: white; }

.btn-success {
  background: var(--color-success);
  color: white;
  border-color: var(--color-success);
}
.btn-success:hover { background: #2d7a51; }

.btn-dark {
  background: var(--color-text-primary);
  color: white;
  border-color: var(--color-text-primary);
}
.btn-dark:hover { opacity: 0.88; }

.btn-purple {
  background: var(--brand-accent);
  color: white;
  border-color: var(--brand-accent);
}
.btn-purple:hover { background: #4423A9; }

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

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

.btn.loading .btn-label { opacity: 0; }
.btn.loading::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
}

/* ============================================================
   CARD
   ============================================================ */
.card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: var(--transition-base);
  overflow: hidden;
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.card-body {
  padding: var(--space-5);
}

.card-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.card-flush .card-body { padding: 0; }

/* KPI / Stat Card */
.stat-card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
}

.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--stat-accent, var(--brand-primary));
  border-radius: var(--radius-full) var(--radius-full) 0 0;
}

.stat-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--stat-bg, var(--brand-primary-muted));
  color: var(--stat-accent, var(--brand-primary));
  margin-bottom: var(--space-3);
  flex-shrink: 0;
}

.stat-card-icon svg { width: 22px; height: 22px; }

.stat-card-value {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 800;
  color: var(--color-text-primary);
  line-height: 1;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-1);
}

.stat-card-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
}

.stat-card-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-xs);
  font-weight: 600;
  margin-top: var(--space-2);
}

.stat-card-trend.up   { color: var(--color-success); }
.stat-card-trend.down { color: var(--color-danger); }
.stat-card-trend svg  { width: 12px; height: 12px; }

.stat-card-trend-label {
  color: var(--color-text-tertiary);
  font-weight: 400;
  margin-left: 2px;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-label .required {
  color: var(--color-danger);
  font-size: var(--text-xs);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.form-error svg { width: 12px; height: 12px; }

.form-control {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  transition: var(--transition-fast);
  outline: none;
  line-height: 1.5;
}

.form-control:hover { border-color: var(--color-border-hover); }

.form-control:focus {
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-focus);
}

.form-control::placeholder { color: var(--color-text-tertiary); }
.form-control:disabled     { background: var(--color-bg-subtle); cursor: not-allowed; opacity: 0.7; }

.form-control.is-error   { border-color: var(--color-danger-border); }
.form-control.is-success { border-color: var(--color-success-border); }

.form-control.form-control-lg {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
}

textarea.form-control {
  resize: vertical;
  min-height: 90px;
}

.input-group {
  position: relative;
  display: flex;
  align-items: stretch;
}

.input-group .form-control {
  flex: 1;
}

.input-group-prefix,
.input-group-suffix {
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border-strong);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.input-group-prefix {
  border-right: none;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.input-group-suffix {
  border-left: none;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.input-group .form-control:not(:first-child) { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.input-group .form-control:not(:last-child)  { border-radius: var(--radius-md) 0 0 var(--radius-md); }

.input-icon-wrapper {
  position: relative;
}

.input-icon-wrapper .form-control {
  padding-left: 36px;
}

.input-icon-wrapper .input-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  display: flex;
  align-items: center;
  pointer-events: none;
}

.input-icon-wrapper .input-icon svg { width: 15px; height: 15px; }

.input-icon-wrapper.input-icon-right .form-control { padding-left: var(--space-3); padding-right: 36px; }
.input-icon-wrapper.input-icon-right .input-icon   { left: auto; right: 11px; }

/* Select */
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23A3ACB6'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  padding-right: 32px;
}

/* Checkbox & Radio */
.form-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  cursor: pointer;
}

.form-check-input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--brand-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.form-check-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
}

/* Switch */
.form-switch {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.switch-input { display: none; }

.switch-track {
  width: 40px;
  height: 22px;
  background: var(--color-bg-muted);
  border-radius: var(--radius-full);
  position: relative;
  transition: var(--transition-base);
  border: 2px solid transparent;
  flex-shrink: 0;
  cursor: pointer;
}

.switch-track::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  background: white;
  border-radius: var(--radius-full);
  transition: var(--transition-spring);
  box-shadow: var(--shadow-xs);
}

.switch-input:checked + .switch-track {
  background: var(--brand-primary);
}

.switch-input:checked + .switch-track::after {
  left: calc(100% - 18px);
}

.switch-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
}

/* ============================================================
   TABLE
   ============================================================ */
.table-container {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-toolbar {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  background: var(--color-bg-surface);
}

.table-toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
}

.table-toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.table-search {
  position: relative;
  min-width: 220px;
}

.table-search .form-control {
  padding-left: 34px;
  background: var(--color-bg-subtle);
  border-color: transparent;
}

.table-search .form-control:focus {
  background: var(--color-bg-surface);
  border-color: var(--brand-primary);
}

.table-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  display: flex;
}

.table-search .search-icon svg { width: 14px; height: 14px; }

.bulk-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-fast);
}

.bulk-actions.active {
  opacity: 1;
  pointer-events: auto;
}

.bulk-count {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--brand-primary);
}

.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
}

table.data-table thead th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-tertiary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--color-bg-subtle);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: var(--transition-fast);
}

table.data-table thead th:hover { color: var(--color-text-secondary); }

table.data-table thead th.sortable::after {
  content: '↕';
  margin-left: var(--space-1);
  opacity: 0.4;
  font-size: 10px;
}

table.data-table thead th.sort-asc::after  { content: '↑'; opacity: 1; color: var(--brand-primary); }
table.data-table thead th.sort-desc::after { content: '↓'; opacity: 1; color: var(--brand-primary); }

table.data-table thead th:first-child { padding-left: var(--space-5); }
table.data-table thead th:last-child  { padding-right: var(--space-5); text-align: right; }

table.data-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: var(--transition-fast);
}

table.data-table tbody tr:last-child { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--color-bg-subtle); }
table.data-table tbody tr.selected { background: var(--brand-primary-muted); }

table.data-table tbody td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  vertical-align: middle;
}

table.data-table tbody td:first-child { padding-left: var(--space-5); }
table.data-table tbody td:last-child  { padding-right: var(--space-5); }

table.data-table tbody td strong {
  color: var(--color-text-primary);
  font-weight: 600;
}

.td-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  color: var(--color-text-tertiary);
  transition: var(--transition-fast);
  cursor: pointer;
}

.action-btn:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text-primary);
}

.action-btn.danger:hover { color: var(--color-danger); background: var(--color-danger-bg); }
.action-btn svg { width: 15px; height: 15px; }

.table-pagination {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  background: var(--color-bg-surface);
}

.table-pagination-info {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.pagination-btn {
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  padding: 0 var(--space-2);
  background: var(--color-bg-surface);
}

.pagination-btn:hover      { border-color: var(--brand-primary); color: var(--brand-primary); }
.pagination-btn.active     { background: var(--brand-primary); border-color: var(--brand-primary); color: white; }
.pagination-btn:disabled   { opacity: 0.4; pointer-events: none; }
.pagination-btn svg        { width: 14px; height: 14px; }
.pagination-dots           { color: var(--color-text-tertiary); padding: 0 var(--space-1); }

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

.dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  min-width: 180px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  padding: var(--space-1);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px) scale(0.97);
  transform-origin: top right;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.dropdown-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.dropdown-menu.align-left { right: auto; left: 0; transform-origin: top left; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.dropdown-item:hover { background: var(--color-bg-subtle); color: var(--color-text-primary); }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-item.danger:hover { background: var(--color-danger-bg); }
.dropdown-item svg { width: 15px; height: 15px; flex-shrink: 0; color: var(--color-text-tertiary); }
.dropdown-item.danger svg { color: var(--color-danger); }

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

.dropdown-header {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop,
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg-overlay);
  z-index: var(--z-modal-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  backdrop-filter: blur(3px);
  animation: backdrop-in 0.18s ease;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.modal-backdrop.open,
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - var(--space-8));
  display: flex;
  flex-direction: column;
  transform: translateY(20px) scale(0.97);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.modal-backdrop.open .modal,
.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-sm { max-width: 400px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 900px; }

.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.02em;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-tertiary);
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.modal-close:hover { background: var(--color-bg-subtle); color: var(--color-text-primary); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body {
  padding: var(--space-5) var(--space-6);
  overflow-y: auto;
  flex: 1;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
}

.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ============================================================
   ALERT
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  border: 1px solid transparent;
}

.alert-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-icon svg { width: 16px; height: 16px; }

.alert-content { flex: 1; }
.alert-title { font-weight: 700; margin-bottom: 2px; }
.alert-close { flex-shrink: 0; cursor: pointer; opacity: 0.6; transition: opacity 0.15s; }
.alert-close:hover { opacity: 1; }

.alert-info    { background: var(--color-info-bg);    border-color: var(--color-info-border);    color: var(--color-info); }
.alert-success { background: var(--color-success-bg); border-color: var(--color-success-border); color: var(--color-success); }
.alert-warning { background: var(--color-warning-bg); border-color: var(--color-warning-border); color: var(--color-warning); }
.alert-danger  { background: var(--color-danger-bg);  border-color: var(--color-danger-border);  color: var(--color-danger); }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 340px;
  pointer-events: auto;
  animation: toast-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

.toast.hiding {
  opacity: 0;
  transform: translateX(20px) scale(0.95);
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.toast-icon svg { width: 18px; height: 18px; }

.toast.success .toast-icon { color: var(--color-success); }
.toast.error   .toast-icon { color: var(--color-danger); }
.toast.warning .toast-icon { color: var(--color-warning); }
.toast.info    .toast-icon { color: var(--color-info); }

.toast-content { flex: 1; min-width: 0; }
.toast-title   { font-size: var(--text-sm); font-weight: 700; color: var(--color-text-primary); }
.toast-message { font-size: var(--text-xs); color: var(--color-text-secondary); margin-top: 2px; }
.toast-close   { flex-shrink: 0; color: var(--color-text-tertiary); cursor: pointer; padding: 2px; }
.toast-close:hover { color: var(--color-text-primary); }
.toast-close svg { width: 14px; height: 14px; }

/* ============================================================
   TABS
   ============================================================ */
.tabs {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.tabs-nav {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
}

.tab-btn {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-tertiary);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: var(--transition-fast);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.tab-btn:hover { color: var(--color-text-secondary); }

.tab-btn.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
}

.tab-btn .tab-count {
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  padding: 1px 6px;
  border-radius: var(--radius-full);
}

.tab-btn.active .tab-count {
  background: var(--brand-primary-muted);
  color: var(--brand-primary);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fade-in 0.18s ease; }

/* Pill tabs variant */
.tabs-nav.tabs-pills {
  border-bottom: none;
  background: var(--color-bg-subtle);
  padding: var(--space-1);
  border-radius: var(--radius-md);
  gap: var(--space-1);
  display: inline-flex;
}

.tabs-nav.tabs-pills .tab-btn {
  border-bottom: none;
  margin-bottom: 0;
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-3);
}

.tabs-nav.tabs-pills .tab-btn.active {
  background: var(--color-bg-surface);
  box-shadow: var(--shadow-sm);
  color: var(--color-text-primary);
}

/* ============================================================
   PROGRESS & LOADER
   ============================================================ */
.progress {
  height: 6px;
  background: var(--color-bg-muted);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--brand-primary);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

.progress-success .progress-bar { background: var(--color-success); }
.progress-warning .progress-bar { background: var(--color-warning-border); }
.progress-danger  .progress-bar { background: var(--color-danger); }

.progress-sm { height: 4px; }
.progress-lg { height: 8px; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-bg-muted);
  border-top-color: var(--brand-primary);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
}

.spinner-sm { width: 14px; height: 14px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
.spinner-xl { width: 48px; height: 48px; border-width: 3px; }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--color-bg-subtle) 25%, var(--color-bg-muted) 50%, var(--color-bg-subtle) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text    { height: 14px; border-radius: var(--radius-sm); }
.skeleton-title   { height: 22px; border-radius: var(--radius-sm); }
.skeleton-circle  { border-radius: var(--radius-full); }
.skeleton-card    { height: 120px; border-radius: var(--radius-lg); }
.skeleton-avatar  { width: 40px; height: 40px; border-radius: var(--radius-full); }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-8);
  gap: var(--space-4);
}

.empty-state-icon {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-xl);
  background: var(--color-bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-2);
}

.empty-state-icon svg { width: 36px; height: 36px; }

.empty-state-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.02em;
}

.empty-state-description {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  max-width: 360px;
  line-height: var(--leading-relaxed);
}

/* ============================================================
   TIMELINE
   ============================================================ */
.timeline { display: flex; flex-direction: column; }

.timeline-item {
  display: flex;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  position: relative;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-line {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--brand-primary);
  border: 2px solid var(--color-bg-surface);
  box-shadow: 0 0 0 2px var(--brand-primary-muted);
  flex-shrink: 0;
  margin-top: 4px;
  z-index: 1;
}

.timeline-dot.success { background: var(--color-success); box-shadow: 0 0 0 2px var(--color-success-bg); }
.timeline-dot.warning { background: var(--color-warning-border); box-shadow: 0 0 0 2px var(--color-warning-bg); }
.timeline-dot.danger  { background: var(--color-danger); box-shadow: 0 0 0 2px var(--color-danger-bg); }
.timeline-dot.offline { background: var(--color-text-disabled); box-shadow: none; }

.timeline-connector {
  flex: 1;
  width: 1px;
  background: var(--color-border);
  margin: var(--space-1) 0;
}

.timeline-content { flex: 1; min-width: 0; }
.timeline-title   { font-size: var(--text-sm); font-weight: 600; color: var(--color-text-primary); }
.timeline-text    { font-size: var(--text-xs); color: var(--color-text-secondary); margin-top: 2px; line-height: var(--leading-relaxed); }
.timeline-time    { font-size: var(--text-xs); color: var(--color-text-tertiary); margin-top: var(--space-1); }

/* ============================================================
   FILE UPLOAD
   ============================================================ */
.upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  cursor: pointer;
  transition: var(--transition-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--brand-primary);
  background: var(--brand-primary-muted);
}

.upload-area-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  background: var(--color-bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-tertiary);
  transition: var(--transition-base);
}

.upload-area:hover .upload-area-icon {
  background: var(--brand-primary-muted);
  color: var(--brand-primary);
}

.upload-area-icon svg { width: 24px; height: 24px; }
.upload-area-title { font-weight: 600; font-size: var(--text-base); color: var(--color-text-primary); }
.upload-area-subtitle { font-size: var(--text-sm); color: var(--color-text-tertiary); }
.upload-area-subtitle span { color: var(--brand-primary); font-weight: 600; }

/* ============================================================
   TOOLTIP
   ============================================================ */
[data-tooltip] {
  position: relative;
  cursor: default;
}

[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: var(--color-text-primary);
  color: white;
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: var(--z-tooltip);
}

[data-tooltip]:hover::before {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ============================================================
   BREADCRUMBS
   ============================================================ */
.breadcrumb-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-4);
}

.breadcrumb-nav a { color: var(--color-text-tertiary); transition: var(--transition-fast); }
.breadcrumb-nav a:hover { color: var(--brand-primary); }
.breadcrumb-nav .bc-sep { color: var(--color-text-disabled); }
.breadcrumb-nav .bc-current { color: var(--color-text-primary); font-weight: 500; }

/* ============================================================
   ACCORDION
   ============================================================ */
.accordion { display: flex; flex-direction: column; gap: var(--space-2); }

.accordion-item {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  cursor: pointer;
  user-select: none;
  transition: var(--transition-fast);
  gap: var(--space-3);
}

.accordion-header:hover { background: var(--color-bg-subtle); }

.accordion-title { font-weight: 600; font-size: var(--text-sm); color: var(--color-text-primary); }

.accordion-arrow {
  width: 18px;
  height: 18px;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
  transition: transform 0.22s ease;
}

.accordion-item.open .accordion-arrow { transform: rotate(180deg); }

.accordion-body {
  display: none;
  padding: 0 var(--space-4) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
}

.accordion-item.open .accordion-body { display: block; animation: fade-in 0.18s ease; }

/* ============================================================
   OFFCANVAS
   ============================================================ */
.offcanvas-backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-bg-overlay);
  z-index: var(--z-offcanvas);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.offcanvas-backdrop.open { opacity: 1; pointer-events: auto; }

.offcanvas {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: calc(100vw - 40px);
  height: 100vh;
  background: var(--color-bg-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-xl);
  z-index: calc(var(--z-offcanvas) + 1);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.offcanvas.open { transform: translateX(0); }

.offcanvas-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-shrink: 0;
}

.offcanvas-title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.02em; }
.offcanvas-body  { flex: 1; overflow-y: auto; padding: var(--space-5) var(--space-6); }
.offcanvas-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}
