/* ============================================================
   COMPONENTS - Reusable UI elements
   ============================================================ */

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 9px 16px;
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius);
  transition: all var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
  user-select: none;
  line-height: 1;
}

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

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

.btn-primary:disabled {
  background: var(--line-2);
  border-color: var(--line-2);
  color: var(--muted);
}

.btn-secondary {
  background: var(--brand-black);
  color: white;
  border-color: var(--brand-black);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--ink-2);
  border-color: var(--ink-2);
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--line-2);
}

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

.btn-danger:hover:not(:disabled) {
  background: #9A2D2D;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: var(--line);
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn-sm {
  padding: 5px 10px;
  font-size: var(--text-xs);
}

.btn-lg {
  padding: 12px 24px;
  font-size: var(--text-md);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.btn-icon.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-block {
  width: 100%;
}

/* === FORMS === */
.field {
  display: block;
  margin-bottom: var(--space-4);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: var(--text-sm);
  transition: border-color var(--transition);
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
}

.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}

.input::placeholder, .textarea::placeholder {
  color: var(--muted-2);
}

.textarea {
  resize: vertical;
  min-height: 70px;
  font-family: inherit;
}

.input-help {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: 4px;
}

.input-error {
  border-color: var(--danger);
}

.input-error-text {
  font-size: var(--text-xs);
  color: var(--danger);
  margin-top: 4px;
}

/* Checkbox */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
  font-size: var(--text-sm);
}

.checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* === CARDS === */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

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

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

.card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--ink);
}

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

.card-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

/* === BADGES & CHIPS === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-default {
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
}

.badge-primary {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-soft-2);
}

.badge-positive {
  background: var(--positive-soft);
  color: var(--positive);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-info {
  background: var(--info-soft);
  color: var(--info);
}

/* === MODAL === */
#modal-container {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}

#modal-container.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, 0.4);
  backdrop-filter: blur(2px);
  animation: fadeIn 150ms ease;
}

.modal {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 200ms ease;
}

.modal.modal-lg { max-width: 800px; }
.modal.modal-xl { max-width: 1100px; }

.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--ink);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: transparent;
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === TOASTS === */
#toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--brand-black);
  color: white;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 250px;
  max-width: 400px;
  pointer-events: auto;
  animation: slideInRight 200ms ease;
}

.toast.success { background: var(--positive); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }

.toast.removing {
  animation: slideOutRight 200ms ease forwards;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutRight {
  to { opacity: 0; transform: translateX(20px); }
}

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
}

.empty-state-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius-full);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.empty-state-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--ink);
  margin-bottom: var(--space-2);
}

.empty-state-text {
  color: var(--muted);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

/* === TABLES === */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

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

.table tbody tr:hover {
  background: var(--surface-2);
}

.table .text-right { text-align: right; }
.table .num { font-variant-numeric: tabular-nums; text-align: right; }

/* Compact table */
.table-compact th, .table-compact td {
  padding: var(--space-2) var(--space-3);
}

/* === SEGMENT CONTROL === */
.segment {
  display: inline-flex;
  background: var(--surface-2);
  padding: 3px;
  border-radius: var(--radius);
  gap: 2px;
}

.segment-btn {
  padding: 5px 12px;
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: 4px;
  color: var(--muted);
  white-space: nowrap;
}

.segment-btn:hover {
  color: var(--ink);
}

.segment-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* === SEARCH BOX === */
.search-box {
  position: relative;
}

.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-box input {
  padding-left: 34px;
  width: 240px;
}

/* === PROGRESS BAR === */
.progress {
  height: 6px;
  background: var(--line);
  border-radius: var(--radius-full);
  overflow: hidden;
}

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

.progress-bar.positive { background: var(--positive); }
.progress-bar.warn { background: var(--warn); }
