/* ═══════════════════════════════════════════════════════════════
   Miras Design System — Components v2
   Button · Card · Form · Badge · Tab · Table · Accordion ·
   Toast · Skeleton · Tooltip · Chips
   ═══════════════════════════════════════════════════════════════ */

/* ═══ Buttons ═══ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  font-size: var(--text-sm);
  line-height: 1;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: transform var(--dur-instant) var(--ease-out),
              background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn .icon { width: 16px; height: 16px; }

.btn-primary {
  background: var(--brand-600);
  color: var(--text-on-brand);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover {
  background: var(--brand-700);
  color: var(--text-on-brand);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover {
  border-color: var(--brand-400);
  background: var(--surface-2);
}

.btn-ghost { color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-soft {
  background: var(--brand-50);
  color: var(--brand-600);
}
.btn-soft:hover { background: var(--brand-100); color: var(--brand-700); }

.btn-danger-soft { background: var(--rose-50); color: var(--rose-600); }
.btn-danger-soft:hover { background: var(--rose-100); color: var(--rose-600); }

.btn-outline-danger { border-color: var(--rose-500); color: var(--rose-600); }
.btn-outline-danger:hover { background: var(--rose-500); color: var(--text-on-rose); }

.btn-lg { padding: 14px 24px; font-size: var(--text-base); border-radius: var(--radius-lg); }
.btn-sm { padding: 6px 12px; font-size: var(--text-xs); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* Icon button */
.btn-icon {
  width: 44px; height: 44px; padding: 0;
  border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-soft);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon .icon { width: 20px; height: 20px; }

/* Button group */
.btn-group {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.btn-group .btn { flex: 1; border: none; border-radius: 0; }

/* ═══ Cards ═══ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.card-hover {
  transition: box-shadow var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.card-hover:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.card-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm);
}
.card-title {
  display: flex; align-items: center; gap: var(--space-xs);
  font-family: var(--font-display);
  font-weight: var(--fw-semibold); font-size: var(--text-sm); color: var(--text);
}
.card-body { padding: var(--space-lg); }
.card-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* Step card */
.step-card { padding: var(--space-lg); }
.step-head {
  display: flex; align-items: center; gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.step-number {
  width: 32px; height: 32px; flex: 0 0 32px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--brand-50); color: var(--brand-600);
  font-family: var(--font-display);
  font-weight: var(--fw-bold); font-size: var(--text-xs);
}
.step-title {
  font-family: var(--font-display);
  font-weight: var(--fw-semibold); font-size: var(--text-sm);
}
.step-sub { color: var(--text-faint); font-size: var(--text-xs); }

/* ═══ Form Fields ═══ */
.field { display: flex; flex-direction: column; gap: var(--space-xs); margin-bottom: var(--space-md); }
.field-label {
  font-family: var(--font-display);
  font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text);
  display: flex; align-items: center; gap: var(--space-xs);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: var(--text-sm);
  color: var(--text);
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
  appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: var(--shadow-focus);
}
.textarea { resize: vertical; min-height: 84px; }

/* Input group (icon prefix) */
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-left: 40px; padding-right: 48px; }
.input-group .leading-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; flex: 0 0 16px;
  color: var(--text-faint); pointer-events: none;
}
.input-group .suffix {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: var(--text-xs); color: var(--text-faint); font-weight: var(--fw-medium);
  pointer-events: none;
}

.select { background-image: none; }
.select-wrap { position: relative; }
.select-wrap .select { padding-right: 36px; }
.select-wrap .chevron {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-faint); pointer-events: none;
}

/* Checkbox */
.check {
  display: flex; align-items: center; gap: var(--space-sm);
  cursor: pointer; font-size: var(--text-sm); color: var(--text-soft);
  user-select: none;
}
.check input { display: none; }
.check .box {
  width: 26px; height: 26px; flex: 0 0 26px;
  border: 1.5px solid var(--border-strong); border-radius: 6px;
  display: grid; place-items: center; color: transparent;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.check .box .icon { width: 16px; height: 16px; }
.check input:checked ~ .box {
  background: var(--brand-600); border-color: var(--brand-600);
  color: var(--text-on-brand);
}
.check:hover .box { border-color: var(--brand-400); }

/* Help text */
.help { font-size: var(--text-xs); color: var(--text-faint); margin-top: var(--space-3xs); }

/* ═══ Badge / Chip ═══ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: var(--text-2xs); font-weight: var(--fw-semibold);
  line-height: 1.4;
}
.badge .icon { width: 12px; height: 12px; }

.badge-brand   { background: var(--brand-50); color: var(--brand-600); }
.badge-green   { background: var(--brand-100); color: var(--brand-700); }
.badge-gold    { background: var(--gold-100); color: var(--gold-600); }
.badge-rose    { background: var(--rose-50); color: var(--rose-600); }
.badge-sky     { background: var(--sky-50); color: var(--sky-600); }
.badge-neutral { background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border); }
.badge-solid   { background: var(--brand-600); color: var(--text-on-brand); }
.badge-solid-rose { background: var(--rose-500); color: var(--text-on-rose); }

/* Stat card (sources) */
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-lg); text-align: center; box-shadow: var(--shadow-xs);
}
.stat-icon {
  width: 44px; height: 44px; margin: 0 auto var(--space-sm);
  border-radius: var(--radius); display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand-600);
}
.stat-icon .icon { width: 22px; height: 22px; }
.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl); font-weight: var(--fw-bold); line-height: 1.1;
}
.stat-label { color: var(--text-faint); font-size: var(--text-sm); margin-top: 2px; }

/* ═══ Tabs ═══ */
.tabs {
  display: flex; gap: var(--space-3xs);
  background: var(--surface); border: 1px solid var(--border);
  padding: var(--space-3xs); border-radius: var(--radius-lg);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tab-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md); border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: var(--fw-semibold); font-size: var(--text-sm); color: var(--text-soft);
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
  white-space: nowrap; min-width: 0;
}
.tab-btn .icon { width: 16px; height: 16px; }
.tab-btn:hover { background: var(--surface-2); color: var(--text); }
.tab-btn.active {
  background: var(--brand-600); color: var(--text-on-brand);
  box-shadow: var(--shadow-xs);
}

/* Underline tabs */
.tabs-underline {
  display: flex; gap: var(--space-lg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tab-underline {
  padding: var(--space-sm) var(--space-xs);
  font-family: var(--font-display);
  font-weight: var(--fw-semibold); font-size: var(--text-sm);
  color: var(--text-soft); position: relative;
  display: inline-flex; align-items: center; gap: var(--space-xs);
  white-space: nowrap;
}
.tab-underline::after {
  content: ""; position: absolute; left: 0; right: 100%; bottom: -1px; height: 2px;
  background: var(--brand-500); transition: right var(--dur-fast) var(--ease-out);
}
.tab-underline:hover { color: var(--text); }
.tab-underline.active { color: var(--brand-600); }
.tab-underline.active::after { right: 0; }

/* Tab pane */
.pane { display: none; }
.pane.active { display: block; animation: fadeIn var(--dur-fast) var(--ease-out); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ═══ Table ═══ */
.table-wrap {
  overflow: auto; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface);
}
table.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: var(--text-sm);
}
.table thead th {
  text-align: left;
  font-family: var(--font-display);
  font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); font-weight: var(--fw-semibold);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap; vertical-align: middle;
}
.table tbody td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

.table-sort { cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 4px; }
.table-sort .icon { width: 13px; height: 13px; color: var(--text-faint); }
.table-sort:hover { color: var(--text); }

/* ═══ Accordion ═══ */
.accordion { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface); }
.acc { border-bottom: 1px solid var(--border); }
.acc:last-child { border-bottom: none; }
.acc-head {
  width: 100%; display: flex; align-items: center; gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font-display);
  font-weight: var(--fw-semibold); font-size: var(--text-sm); text-align: left;
  background: var(--surface); color: var(--text);
  transition: background var(--dur-fast) var(--ease);
  min-height: 48px;
}
.acc-head:hover { background: var(--surface-2); }
.acc-head:focus-visible { outline: 2px solid var(--brand-500); outline-offset: -2px; }
.acc.open > .acc-head { background: var(--brand-50); }
.acc.open > .acc-head .icon { color: var(--brand-700); }
.acc.open > .acc-head span { color: var(--brand-700); }
.acc-head .icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--brand-500); }
.acc-head span { flex: 1; min-width: 0; font-weight: var(--fw-bold); }
.acc-head .chevron {
  margin-left: auto; flex: 0 0 auto; width: 16px; height: 16px;
  color: var(--text-faint); transition: transform var(--dur-fast) var(--ease-out);
}
.acc.open .acc-head .chevron { transform: rotate(180deg); }
.acc-body { padding: 0 var(--space-lg) var(--space-md); color: var(--text-soft); font-size: var(--text-sm); }
.acc-body { display: none; }
.acc.open .acc-body { display: block; animation: fadeIn var(--dur-fast) var(--ease-out); }

/* ═══ Toast ═══ */
.toast-wrap {
  position: fixed; top: calc(var(--header-h) + var(--space-md));
  right: var(--space-lg); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--space-sm);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--space-sm);
  min-width: 0; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-sm) var(--space-md); box-shadow: var(--shadow-lg);
  animation: toastIn var(--dur-fast) var(--ease-out);
}
.toast .icon { width: 18px; height: 18px; flex: 0 0 18px; }
.toast-success .icon { color: var(--positive); }
.toast-error .icon { color: var(--negative); }
.toast-info .icon { color: var(--info); }
.toast-desc { font-size: var(--text-sm); color: var(--text); font-weight: var(--fw-medium); }
.toast.leaving { animation: toastOut var(--dur-fast) var(--ease-in) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(12px); } }

/* ═══ Skeleton ═══ */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--radius); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--shimmer-color), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skeleton-text { width: 100%; }
.skeleton-card { height: 180px; }
.skeleton-row { height: 20px; margin-bottom: 8px; }

/* ═══ Empty / Error state ═══ */
.state-box { text-align: center; padding: var(--space-2xl) var(--space-lg); color: var(--text-faint); }
.state-box .icon { width: 48px; height: 48px; margin: 0 auto var(--space-md); color: var(--text-faint); opacity: .5; }
.state-box h3 { color: var(--text); margin-bottom: var(--space-xs); font-weight: var(--fw-semibold); }
.error-box {
  display: flex; gap: var(--space-sm); align-items: flex-start;
  background: var(--rose-50); color: var(--rose-600);
  border: 1px solid var(--rose-100); border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
}
.error-box .icon { width: 20px; height: 20px; flex: 0 0 20px; margin-top: 1px; }

/* ═══ Tooltip (CSS-only) ═══ */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-size: var(--text-2xs); font-weight: var(--fw-medium); white-space: nowrap;
  padding: 5px 10px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); z-index: var(--z-tooltip);
}
[data-tooltip]:hover::before {
  content: ""; position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--ink);
}

/* ═══ Spinner ═══ */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--brand-500);
  animation: spin .7s linear infinite; flex: 0 0 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ Divider ═══ */
hr.rule { border: none; border-top: 1px solid var(--border); margin: var(--space-lg) 0; }
