/* ============================================================
   COMPONENTS · Reusable UI patterns
   ============================================================ */

/* ============ BUTTONS ============ */
.btn {
  background: transparent;
  border: 0.5px solid var(--border-strong);
  color: var(--text-1);
  padding: 9px 14px;
  border-radius: 7px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  user-select: none;
}
.btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) {
  color: var(--bg);
  opacity: 0.92;
  border-color: var(--gold);
}
.btn-danger {
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover:not(:disabled) {
  background: var(--red-bg);
  border-color: var(--red);
  color: var(--red);
}
.btn-ghost {
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border);
}
.btn-sm {
  padding: 6px 10px;
  font-size: 11px;
}
.btn-lg {
  padding: 13px 20px;
  font-size: 14px;
}
.btn-block {
  width: 100%;
  justify-content: center;
}

/* ============ FIELDS ============ */
.field {
  margin-bottom: 16px;
}
.field-label {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 1.6px;
  margin-bottom: 7px;
  text-transform: uppercase;
}
.field-label .opt {
  color: var(--text-4);
  margin-left: 6px;
  text-transform: none;
  letter-spacing: 0;
}
.field-label .req {
  color: var(--red);
  margin-left: 4px;
}
.field-input {
  width: 100%;
  background: var(--surface-2);
  border: 0.5px solid var(--border-strong);
  color: var(--text-1);
  padding: 12px 14px;
  border-radius: 6px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.field-input:focus {
  border-color: var(--gold);
}
.field-input::placeholder {
  color: var(--text-4);
}
.field-input.error {
  border-color: var(--red);
}
.field-error {
  font-size: 12px;
  color: var(--red);
  margin-top: 5px;
}
.field-help {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 5px;
}
.field-input-group {
  display: flex;
  border: 0.5px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
}
.field-input-group:focus-within {
  border-color: var(--gold);
}
.field-prefix {
  background: var(--surface-3);
  padding: 12px 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--text-2);
  border-right: 0.5px solid var(--border);
}
.field-input-group .field-input {
  border: none;
  border-radius: 0;
  background: transparent;
}
textarea.field-input {
  font-family: 'Plus Jakarta Sans', sans-serif;
  resize: vertical;
  min-height: 80px;
}
select.field-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* Choice button group */
.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.choice {
  background: var(--surface-2);
  border: 0.5px solid var(--border-strong);
  color: var(--text-2);
  padding: 11px 14px;
  border-radius: 6px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  user-select: none;
}
.choice:hover {
  color: var(--text-1);
  border-color: var(--text-3);
}
.choice.active {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-bg);
}

/* Toggle switch */
.toggle {
  display: inline-block;
  width: 36px;
  height: 20px;
  background: var(--surface-3);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
  vertical-align: middle;
}
.toggle::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left 0.15s;
}
.toggle.on {
  background: var(--gold);
}
.toggle.on::after {
  left: 18px;
}

/* Checkbox */
.cbox {
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  transition: all 0.1s;
  flex-shrink: 0;
}
.cbox.checked {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--bg);
  font-weight: 700;
  font-size: 11px;
}

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.card-h {
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-1);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}
.card-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ============ PILLS ============ */
.pill {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 1.2px;
  padding: 4px 8px;
  border-radius: 3px;
  display: inline-block;
  text-transform: uppercase;
  font-weight: 500;
}
.pill-gold { background: var(--gold-bg-strong); color: var(--gold); }
.pill-teal { background: var(--teal-bg); color: var(--teal); }
.pill-cyan { background: var(--cyan-bg); color: var(--cyan); }
.pill-purple { background: var(--purple-bg); color: var(--purple); }
.pill-orange { background: var(--orange-bg); color: var(--orange); }
.pill-red { background: var(--red-bg); color: var(--red); }
.pill-green { background: var(--green-bg); color: var(--green); }
.pill-mute { background: var(--surface-3); color: var(--text-3); }

/* ============ KPI GRID ============ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.kpi {
  background: var(--bg-2);
  padding: 18px 20px;
}
.kpi-num {
  font-family: 'Manrope', sans-serif;
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  line-height: 1;
}
.kpi-num.empty { color: var(--text-4); }
.kpi-num.gold { color: var(--gold); }
.kpi-num.cyan { color: var(--cyan); }
.kpi-num.purple { color: var(--purple); }
.kpi-num.green { color: var(--green); }
.kpi-num.orange { color: var(--orange); }
.kpi-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 1.4px;
  margin-top: 10px;
  text-transform: uppercase;
}
.kpi-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}

/* ============ TABLE ============ */
.dtable {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.dtable th {
  background: var(--bg-2);
  text-align: left;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-3);
  padding: 12px 14px;
  text-transform: uppercase;
  border-bottom: 0.5px solid var(--border);
  font-weight: 500;
}
.dtable td {
  padding: 14px;
  border-bottom: 0.5px solid var(--border);
  font-size: 13px;
  color: var(--text-1);
}
.dtable tr:last-child td {
  border-bottom: none;
}
.dtable tr:hover td {
  background: var(--bg-2);
}
.dtable td.mono {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-3);
}
.dtable .empty-row td {
  text-align: center;
  color: var(--text-4);
  font-style: italic;
  padding: 32px;
}

/* ============ EMPTY STATE ============ */
.empty {
  background: var(--bg-2);
  border: 0.5px dashed var(--border-strong);
  border-radius: 12px;
  padding: 48px 32px;
  text-align: center;
}
.empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
}
.empty-title {
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--text-1);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.empty-text {
  font-size: 13px;
  color: var(--text-3);
  max-width: 380px;
  margin: 0 auto 22px;
  line-height: 1.6;
}
.empty-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============ SECTION DIVIDER ============ */
.section-h {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 1.8px;
  margin: 26px 0 14px;
  padding-bottom: 8px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-transform: uppercase;
}
.section-h .meta {
  font-size: 11px;
  letter-spacing: 1px;
  font-weight: 400;
}

/* ============ TOAST ============ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 280px;
  max-width: 400px;
  font-size: 13px;
  color: var(--text-1);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: slideIn 0.2s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.info { border-left-color: var(--cyan); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 8000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 14px;
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-2);
}
.modal-h {
  padding: 22px 26px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.modal-h-title {
  font-family: 'Manrope', sans-serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.modal-h-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}
.modal-x {
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-x:hover { color: var(--text-1); }
.modal-body { padding: 22px 26px; }
.modal-foot {
  padding: 16px 26px;
  border-top: 0.5px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

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

/* ============ LOADING ============ */
.loader {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loader.lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.skeleton {
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============ THEME TOGGLE ============ */
.theme-btn {
  background: transparent;
  border: 0.5px solid var(--border-strong);
  color: var(--text-2);
  padding: 7px 12px;
  border-radius: 7px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.theme-btn:hover {
  color: var(--gold);
  border-color: var(--gold);
}

/* ============ UTILITY ============ */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.hidden { display: none !important; }
.opacity-50 { opacity: 0.5; }
