/* ==========================================================================
   Components — buttons, cards, inputs, badges, tables, etc.
   ========================================================================== */

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 500;
  letter-spacing: -0.01em;
  border: 1px solid transparent;
  background: var(--bg-elevated);
  color: var(--text-primary);
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}
.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-default);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

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

.btn-outline {
  background: transparent;
  border-color: var(--border-default);
  color: var(--text-primary);
}
.btn-outline:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

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

.btn-lg {
  height: 44px;
  padding: 0 var(--space-5);
  font-size: var(--text-md);
  border-radius: var(--radius-lg);
}

.btn-sm {
  height: 28px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

.btn-icon {
  width: 36px;
  padding: 0;
}

/* ----- Cards / Surfaces ----- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card-flush {
  padding: 0;
}
.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.card-body {
  padding: var(--space-6);
}
.card-title {
  font-size: var(--text-md);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ----- Inputs ----- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.field-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 500;
}
.input,
.textarea,
.select {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-4);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: all 0.15s ease;
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-tertiary);
}
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea {
  height: auto;
  min-height: 96px;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
  font-family: var(--font-sans);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'><path d='M3 5l3 3 3-3' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: var(--space-8);
}

.input-search {
  padding-left: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'><circle cx='6' cy='6' r='4.5' stroke='%236b7280' stroke-width='1.5'/><path d='M9.5 9.5L12 12' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
}

/* ----- Toggle / Switch ----- */
.switch {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--border-default);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform 0.2s ease;
}
.switch.on {
  background: var(--accent);
}
.switch.on::after {
  transform: translateX(16px);
  background: var(--accent-text);
}

/* ----- Checkbox ----- */
.check {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--bg-input);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.check:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.check:checked::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'><path d='M2.5 6L5 8.5L9.5 4' stroke='%230a0b0f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
}

/* ----- Badges / Pills ----- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 22px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--bg-elevated-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* ----- Tables ----- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}
.table tbody tr:hover {
  background: var(--bg-hover);
}
.table tbody tr:last-child td {
  border-bottom: none;
}
.table .num {
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
}

/* ----- Avatar ----- */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-default);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--text-primary);
  text-transform: uppercase;
  flex-shrink: 0;
  letter-spacing: 0;
}
.avatar-lg { width: 44px; height: 44px; font-size: var(--text-base); }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }

.avatar.tone-1 { background: oklch(0.55 0.12 240 / 0.4); color: oklch(0.85 0.12 240); }
.avatar.tone-2 { background: oklch(0.55 0.12 320 / 0.4); color: oklch(0.85 0.12 320); }
.avatar.tone-3 { background: oklch(0.55 0.12 30 / 0.4); color: oklch(0.85 0.12 30); }
.avatar.tone-4 { background: oklch(0.55 0.12 130 / 0.4); color: oklch(0.85 0.12 130); }
.avatar.tone-5 { background: oklch(0.55 0.12 60 / 0.4); color: oklch(0.85 0.12 60); }
.avatar.tone-6 { background: oklch(0.55 0.12 200 / 0.4); color: oklch(0.85 0.12 200); }

/* ----- Sidebar ----- */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  padding: var(--space-5) var(--space-3);
  gap: var(--space-2);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  margin-bottom: var(--space-6);
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-text);
  font-weight: 700;
  font-size: var(--text-sm);
  letter-spacing: -0.02em;
  position: relative;
}
.brand-mark::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 16px var(--accent-glow);
  opacity: 0.6;
  pointer-events: none;
}
.brand-name {
  font-weight: 600;
  letter-spacing: -0.02em;
  font-size: var(--text-md);
}
.brand-sub {
  font-size: 10px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 1px;
}

.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  font-weight: 500;
  padding: var(--space-3) var(--space-3) var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--bg-elevated-2);
  color: var(--text-primary);
}
.nav-item.active::before {
  content: "";
  width: 3px;
  height: 16px;
  background: var(--accent);
  border-radius: var(--radius-full);
  margin-left: -8px;
  margin-right: 5px;
  box-shadow: 0 0 8px var(--accent-glow);
}
.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 1px 6px;
  font-size: 10px;
  color: var(--text-secondary);
}

/* ----- Topbar ----- */
.topbar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-7);
  gap: var(--space-4);
  background: rgba(10, 11, 15, 0.7);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  font-weight: 600;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
}
.topbar .breadcrumb {
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.topbar .breadcrumb .sep { color: var(--border-strong); }

@media (max-width: 900px) {
  .topbar {
    padding: 0 var(--space-4);
  }
  .sidebar {
    display: none;
  }
}

/* ----- Page header ----- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-7);
  flex-wrap: wrap;
}
.page-title {
  font-size: var(--text-3xl);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.page-subtitle {
  color: var(--text-secondary);
  font-size: var(--text-md);
  margin-top: var(--space-2);
}

/* ----- Stats ----- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}
.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
  overflow: hidden;
}
.stat-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-3xl);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  font-feature-settings: "tnum";
}
.stat-meta {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.stat-meta .delta-up { color: var(--success); }
.stat-meta .delta-down { color: var(--danger); }

/* ----- Tabs ----- */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-6);
}
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text-secondary); }
.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

/* ----- Toast ----- */
.toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-base);
  z-index: 100;
  animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.toast-success { border-left: 3px solid var(--accent); }
.toast.toast-danger { border-left: 3px solid var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ----- Modal ----- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: var(--space-4);
  animation: fade-in 0.15s ease;
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body {
  padding: var(--space-6);
}
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ----- Progress bar ----- */
.progress {
  width: 100%;
  height: 6px;
  background: var(--bg-elevated-2);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.3s ease;
}
.progress-bar.warn { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* ----- Divider ----- */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-5) 0;
}
.divider-vert {
  width: 1px;
  background: var(--border-subtle);
  align-self: stretch;
}

/* ----- Empty state ----- */
.empty {
  text-align: center;
  padding: var(--space-9) var(--space-4);
  color: var(--text-tertiary);
}
.empty-title {
  font-size: var(--text-md);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
  font-weight: 500;
}
