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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 36px; padding: 0 var(--sp-4);
  font-size: var(--fs-base); font-weight: var(--fw-semibold); font-family: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--brand); }
.btn:active { background: var(--brand-subtle); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }

.btn-primary { color: var(--text-inverse); background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-primary:active { background: var(--brand-active); border-color: var(--brand-active); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--neutral-bg); border-color: transparent; }

.btn-danger { color: var(--negative); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--negative-bg); border-color: var(--negative); }

.btn-sm { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-lg { height: 44px; padding: 0 var(--sp-6); font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); }
.label .req { color: var(--negative); }
.hint { font-size: var(--fs-xs); color: var(--text-muted); }

.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 var(--sp-3);
  font-family: inherit; font-size: var(--fs-base); color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.textarea { height: auto; min-height: 80px; padding: var(--sp-3); resize: vertical; }
.select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236A6D70' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--brand-border); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-subtle);
}
.input::placeholder { color: var(--text-muted); }
.input:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
.field.invalid .input { border-color: var(--negative); }
.field.invalid .hint { color: var(--negative); }

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 42px; }
.input-affix {
  position: absolute; right: 4px; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 30px; color: var(--text-muted); background: transparent; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
}
.input-affix:hover { color: var(--text); background: var(--neutral-bg); }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border);
}
.card-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.card-body { padding: var(--sp-5); }
.card-footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); }

/* ---------- Badges / status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 var(--sp-2); font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  border-radius: var(--radius-sm); border: 1px solid transparent; white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-info { color: var(--info); background: var(--info-bg); border-color: var(--brand-border); }
.badge-positive { color: var(--positive); background: var(--positive-bg); border-color: #B7DCC5; }
.badge-warning { color: var(--warning); background: var(--warning-bg); border-color: #F5CFA6; }
.badge-negative { color: var(--negative); background: var(--negative-bg); border-color: #EFBCBC; }
.badge-neutral { color: var(--neutral); background: var(--neutral-bg); border-color: var(--border-strong); }

/* ---------- Table ---------- */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-weight: var(--fw-semibold); color: var(--text-secondary);
  background: var(--surface-2); padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.table tbody td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--brand-subtle); }
.table .col-actions { text-align: right; white-space: nowrap; }
.table td .num { font-size: var(--fs-sm); }

/* ---------- Avatar ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-subtle); color: var(--brand);
  font-weight: var(--fw-bold); font-size: var(--fs-sm); flex: none;
}
.avatar-lg { width: 44px; height: 44px; font-size: var(--fs-md); }

/* ---------- Toast ---------- */
.toast-host {
  position: fixed; top: calc(var(--header-h) + 12px); right: 16px; z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none; max-width: 380px;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); background: var(--surface);
  border: 1px solid var(--border); border-left: 3px solid var(--neutral);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  pointer-events: auto; animation: toast-in var(--dur) var(--ease);
}
.toast.positive { border-left-color: var(--positive); }
.toast.negative { border-left-color: var(--negative); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }
.toast .toast-title { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.toast .toast-msg { font-size: var(--fs-sm); color: var(--text-secondary); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(27, 41, 61, 0.45); display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4); animation: fade-in var(--dur) var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 460px; background: var(--surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: modal-in var(--dur) var(--ease); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
}
.modal.wide { max-width: 620px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); }

/* ---------- Progress ---------- */
.progress { width: 100%; height: 6px; background: var(--neutral-bg); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width 160ms var(--ease); }

/* ---------- Empty / loading ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); padding: var(--sp-12) var(--sp-4); text-align: center; color: var(--text-muted); }
.empty .icon { width: 48px; height: 48px; color: var(--border-strong); }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--brand-border); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.7s linear infinite; }
.spinner-lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Segmented control / tabs ---------- */
.segmented { display: inline-flex; padding: 3px; background: var(--neutral-bg); border-radius: var(--radius-sm); gap: 2px; }
.segmented button { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); background: transparent; border: none; border-radius: 5px; cursor: pointer; }
.segmented button.active { color: var(--brand); background: var(--surface); box-shadow: var(--shadow-xs); font-weight: var(--fw-semibold); }

/* ---------- Detail list (key/value) ---------- */
.detail-list { display: flex; flex-direction: column; }
.detail-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-k { color: var(--text-secondary); font-size: var(--fs-sm); }
.detail-v { font-weight: var(--fw-semibold); text-align: right; }

/* ---------- Divider ---------- */
.divider { height: 1px; background: var(--border); border: none; margin: var(--sp-4) 0; }
