/* ============================================================
   Components — reusable UI primitives
   ============================================================ */

/* ---------- Icons ---------- */
.icon-svg {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.15em;
}
.icon-svg--lg { width: 1.5em; height: 1.5em; }
.icon-svg--xl { width: 2em;   height: 2em; }

/* ---------- Toast notifications ---------- */
.toast-container {
  position: fixed;
  top: var(--s-4);
  right: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  z-index: var(--z-toast);
  pointer-events: none;
  max-width: min(92vw, 420px);
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-elevated);
  color: var(--text);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  max-width: 100%;
  animation: toast-in var(--dur-base) var(--ease);
  position: relative;
  overflow: hidden;
}

.toast::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--gray-400);
}

.toast--success::before { background: var(--success); }
.toast--error::before   { background: var(--danger); }
.toast--warning::before { background: var(--warning); }
.toast--info::before    { background: var(--info); }

.toast__icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
}
.toast--success .toast__icon { color: var(--success); }
.toast--error   .toast__icon { color: var(--danger); }
.toast--warning .toast__icon { color: var(--warning); }
.toast--info    .toast__icon { color: var(--info); }

.toast__body {
  flex: 1;
  min-width: 0;
  font-size: var(--text-base);
  line-height: var(--lh-normal);
  word-wrap: break-word;
}

.toast__close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease);
}
.toast__close:hover { background: var(--surface-muted); }

.toast--leaving {
  animation: toast-out var(--dur-base) var(--ease) forwards;
}

@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(120%); opacity: 0; }
}

/* ---------- Confirm dialog ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface-overlay);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-4);
  animation: fade-in var(--dur-fast) var(--ease);
}

.confirm-dialog {
  background: var(--surface-elevated);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  max-width: 440px;
  width: 100%;
  padding: var(--s-6);
  animation: dialog-in var(--dur-base) var(--ease);
}

.confirm-dialog__icon {
  width: 48px;
  height: 48px;
  border-radius: var(--r-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--s-4);
  background: var(--danger-bg);
  color: var(--danger);
}

.confirm-dialog--info .confirm-dialog__icon    { background: var(--info-bg); color: var(--info); }
.confirm-dialog--warning .confirm-dialog__icon { background: var(--warning-bg); color: var(--warning); }

.confirm-dialog__title {
  font-size: var(--text-xl);
  font-weight: var(--fw-bold);
  color: var(--text);
  margin-bottom: var(--s-2);
}

.confirm-dialog__message {
  font-size: var(--text-base);
  color: var(--text-muted);
  margin-bottom: var(--s-6);
  line-height: var(--lh-relaxed);
}

.confirm-dialog__actions {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  flex-wrap: wrap;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes dialog-in {
  from { opacity: 0; transform: scale(0.94) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  border-radius: var(--r-md);
  font-size: var(--text-base);
  font-weight: var(--fw-semi);
  line-height: 1;
  transition: all var(--dur-fast) var(--ease);
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
  min-height: 40px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--primary);
  color: var(--text-inverse);
}
.btn--primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn--secondary {
  background: var(--surface-muted);
  color: var(--text);
  border-color: var(--border);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--gray-200);
}

.btn--danger {
  background: var(--danger);
  color: var(--text-inverse);
}
.btn--danger:hover:not(:disabled) {
  background: #dc2626;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--surface-muted);
  color: var(--text);
}

.btn--sm { padding: var(--s-2) var(--s-3); font-size: var(--text-sm); min-height: 32px; }
.btn--lg { padding: var(--s-4) var(--s-6); font-size: var(--text-md); min-height: 48px; }
.btn--icon {
  padding: var(--s-2);
  min-height: 36px;
  width: 36px;
}
.btn--block { width: 100%; }

/* ---------- Skeleton loaders ---------- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-muted) 0%,
    var(--gray-200) 50%,
    var(--surface-muted) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--r-md);
  display: block;
}

.skeleton--line {
  height: 12px;
  border-radius: var(--r-full);
  margin-bottom: var(--s-2);
}

.skeleton--title {
  height: 20px;
  width: 60%;
  margin-bottom: var(--s-3);
}

.skeleton--card {
  height: 120px;
  border-radius: var(--r-lg);
}

.skeleton--circle {
  border-radius: var(--r-full);
  width: 40px;
  height: 40px;
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--s-12) var(--s-6);
  color: var(--text-muted);
}

.empty-state__icon {
  width: 64px;
  height: 64px;
  border-radius: var(--r-full);
  background: var(--surface-muted);
  color: var(--text-subtle);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--s-4);
}

.empty-state__icon svg {
  width: 28px;
  height: 28px;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--fw-semi);
  color: var(--text);
  margin-bottom: var(--s-2);
}

.empty-state__message {
  font-size: var(--text-base);
  color: var(--text-muted);
  max-width: 380px;
  line-height: var(--lh-relaxed);
  margin-bottom: var(--s-5);
}

/* ---------- Badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px var(--s-2);
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: var(--fw-semi);
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge--success { background: var(--success-bg); color: var(--success-text); border-color: transparent; }
.badge--warning { background: var(--warning-bg); color: var(--warning-text); border-color: transparent; }
.badge--danger  { background: var(--danger-bg);  color: var(--danger-text);  border-color: transparent; }
.badge--info    { background: var(--info-bg);    color: var(--info-text);    border-color: transparent; }

/* ---------- Theme toggle button ---------- */
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--dur-fast) var(--ease);
}

.theme-toggle:hover {
  background: var(--gray-200);
  color: var(--text);
}

.theme-toggle .icon-svg { width: 18px; height: 18px; }
.theme-toggle .icon-svg--sun  { display: none; }
.theme-toggle .icon-svg--moon { display: block; }

[data-theme="dark"] .theme-toggle .icon-svg--sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-svg--moon { display: none; }

/* ---------- Notification bell ---------- */
.bell {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--dur-fast) var(--ease);
}

.bell:hover {
  background: var(--gray-200);
  color: var(--text);
}

.bell__badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: var(--text-inverse);
  font-size: 10px;
  font-weight: var(--fw-bold);
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.bell--has-unread .bell__badge {
  display: inline-flex;
}

/* ---------- Command palette ---------- */
.cmdk-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface-overlay);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(var(--s-16) + var(--s-4)) var(--s-4) var(--s-4);
  animation: fade-in var(--dur-fast) var(--ease);
}

.cmdk {
  width: 100%;
  max-width: 560px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: dialog-in var(--dur-base) var(--ease);
}

.cmdk__input {
  width: 100%;
  padding: var(--s-4) var(--s-5);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-md);
  color: var(--text);
}

.cmdk__list {
  max-height: min(50vh, 400px);
  overflow-y: auto;
  padding: var(--s-2);
}

.cmdk__item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3);
  border-radius: var(--r-md);
  color: var(--text);
  text-align: left;
  transition: background var(--dur-fast) var(--ease);
}

.cmdk__item:hover,
.cmdk__item[aria-selected="true"] {
  background: var(--surface-muted);
}

.cmdk__item-icon { color: var(--text-muted); }
.cmdk__item-label { flex: 1; }
.cmdk__item-hint { color: var(--text-subtle); font-size: var(--text-sm); }

.cmdk__empty {
  padding: var(--s-8);
  text-align: center;
  color: var(--text-muted);
}

/* ---------- Tabs (ARIA-compliant) ---------- */
[role="tablist"].tabs {
  display: flex;
  gap: var(--s-2);
  overflow-x: auto;
  scrollbar-width: none;
}

[role="tablist"].tabs::-webkit-scrollbar { display: none; }

[role="tab"] {
  -webkit-tap-highlight-color: transparent;
}

[role="tab"][aria-selected="true"] {
  background: var(--primary);
  color: var(--text-inverse);
}

/* ---------- Chart containers (override legacy flex bar layout for ApexCharts) ---------- */
.chart:has(.apexcharts-canvas) {
  display: block !important;
  align-items: initial !important;
}

.apexcharts-canvas {
  font-family: var(--font-sans) !important;
}

/* ---------- Form inputs (consistent) ---------- */
.input,
input[type="text"].input,
input[type="number"].input,
input[type="date"].input,
input[type="month"].input,
input[type="week"].input,
input[type="time"].input,
input[type="password"].input,
input[type="email"].input,
input[type="tel"].input,
input[type="url"].input,
input[type="search"].input,
select.input,
textarea.input {
  width: 100%;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--text-base);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  box-sizing: border-box;
}

/* Single-line form controls: fixed 44px so natively-styled inputs
   (date, month, time, etc.) don't render taller than selects/text inputs. */
input.input,
select.input {
  height: 44px;
}

/* Textareas grow vertically based on content; min-height keeps them
   at least as tall as single-line inputs. */
textarea.input {
  min-height: 44px;
  resize: vertical;
}

.input:focus,
input.input:focus,
select.input:focus,
textarea.input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

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