/* ============================================================
   LOOM — Components
   Uses tokens from tokens.css. Theme-agnostic (brand-* tokens).
   ============================================================ */

/* ---------- BUTTON ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  font-family: inherit;
  font-size: var(--text-label);
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition:
    background var(--motion-instant) var(--ease-default),
    color var(--motion-instant) var(--ease-default),
    border-color var(--motion-instant) var(--ease-default),
    transform var(--motion-instant) var(--ease-default);
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--sm { height: 32px; padding: 0 var(--space-3); font-size: var(--text-label); }
.btn--md { height: 40px; padding: 0 var(--space-4); font-size: var(--text-body-md); }
.btn--lg { height: 48px; padding: 0 var(--space-5); font-size: var(--text-body-lg); }

.btn--primary {
  background: var(--brand-500);
  color: #fff;
}
.btn--primary:hover:not(:disabled) { background: var(--brand-300); }
.btn--primary:active:not(:disabled) { background: var(--brand-700); }

.btn--secondary {
  background: var(--gray-100);
  color: var(--grayMain2c-800);
  border-color: var(--gray-200);
}
.btn--secondary:hover:not(:disabled) { background: var(--gray-200); }
.btn--secondary:active:not(:disabled) { background: var(--gray-300); color: var(--grayMain2c-900); }

.btn--tertiary {
  background: transparent;
  color: var(--brand-500);
}
.btn--tertiary:hover:not(:disabled) { background: var(--brand-100); }
.btn--tertiary:active:not(:disabled) { color: var(--brand-700); }

.btn--danger {
  background: var(--danger-500);
  color: #fff;
}
.btn--danger:hover:not(:disabled) { background: var(--danger-700); }

.btn--ghost {
  background: transparent;
  color: var(--grayMain2c-700);
}
.btn--ghost:hover:not(:disabled) { background: var(--gray-100); }

.btn--icon { width: 40px; padding: 0; }
.btn--icon.btn--sm { width: 32px; }
.btn--icon.btn--lg { width: 48px; }

/* ---------- INPUT ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field__label {
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--grayMain2c-700);
}
.field__hint {
  font-size: var(--text-caption);
  color: var(--grayMain2c-500);
}
.field__hint--error { color: var(--danger-500); }

.input {
  height: 40px;
  padding: 0 var(--space-3);
  font-family: inherit;
  font-size: var(--text-body-md);
  color: var(--grayMain2c-800);
  background: var(--background);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  transition: border-color var(--motion-instant) var(--ease-default),
              box-shadow var(--motion-instant) var(--ease-default);
  width: 100%;
}
.input::placeholder { color: var(--grayMain2c-400); }
.input:hover { border-color: var(--grayMain2c-300); }
.input:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100-a50);
}
.input--error { border-color: var(--danger-500); }
.input--error:focus { box-shadow: 0 0 0 3px rgba(221, 95, 95, 0.15); }
.input:disabled { background: var(--gray-100); color: var(--grayMain2c-400); cursor: not-allowed; }

/* ---------- CARD ---------- */
.card {
  background: var(--background);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.card--prominent { padding: var(--space-6); }
.card--flat { box-shadow: none; }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn var(--motion-default) var(--ease-out);
}
.modal {
  background: var(--background);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  box-shadow: var(--shadow-xl);
  max-width: 480px;
  width: calc(100% - var(--space-8));
  animation: modalIn var(--motion-default) var(--ease-out);
}
.modal--md { max-width: 640px; }
.modal--lg { max-width: 800px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------- TABLE ---------- */
.ltable {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-sm);
  background: var(--background);
}
.ltable thead th {
  background: var(--gray-50);
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--grayMain2c-600);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
}
.ltable tbody td {
  padding: var(--row-pad-y) var(--space-4);
  border-bottom: 1px solid var(--gray-200);
  height: var(--row-height);
  color: var(--grayMain2c-800);
  vertical-align: middle;
}
.ltable tbody tr { transition: background var(--motion-instant) var(--ease-default); }
.ltable tbody tr:hover { background: var(--gray-50); }
.ltable tbody tr.is-selected { background: var(--brand-100); }

/* ---------- SIDEBAR NAV ---------- */
.sidebar {
  width: 240px;
  background: var(--gray-50);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  transition: width var(--motion-default) var(--ease-default);
}
.sidebar--collapsed { width: 64px; }
.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 40px;
  padding: 0 var(--space-4);
  margin: 2px var(--space-2);
  color: var(--grayMain2c-700);
  font-size: var(--text-body-md);
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  transition: background var(--motion-instant) var(--ease-default),
              color var(--motion-instant) var(--ease-default);
}
.sidebar__item:hover { background: var(--gray-100); }
.sidebar__item.is-active {
  background: var(--brand-100);
  color: var(--brand-500);
}
.sidebar__item.is-active::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--space-2));
  top: 8px; bottom: 8px;
  width: 3px;
  background: var(--brand-500);
  border-radius: 0 2px 2px 0;
}

/* ---------- AVATAR ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--brand-500);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  position: relative;
  overflow: visible;
}
.avatar--xs { width: 24px; height: 24px; font-size: 10px; }
.avatar--sm { width: 32px; height: 32px; font-size: 12px; }
.avatar--md { width: 40px; height: 40px; font-size: 14px; }
.avatar--lg { width: 48px; height: 48px; font-size: 16px; }
.avatar--xl { width: 64px; height: 64px; font-size: 22px; }

.avatar__status {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  border: 2px solid var(--background);
}
.avatar--lg .avatar__status, .avatar--xl .avatar__status { width: 12px; height: 12px; }
.avatar__status--online  { background: var(--success-500); }
.avatar__status--away    { background: var(--warning-away); }
.avatar__status--offline { background: var(--gray-400); }

/* ---------- BADGE / CHIP ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 24px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-tiny);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}
.badge--sm { height: 20px; padding: 0 var(--space-2); font-size: var(--text-tiny); }

.badge--neutral { background: var(--gray-200); color: var(--grayMain2c-700); }
.badge--success { background: var(--success-200); color: var(--success-700); }
.badge--danger  { background: var(--danger-200);  color: var(--danger-700); }
.badge--warning { background: #FFF0D6; color: #8A6D00; }
.badge--info    { background: var(--brand-100);   color: var(--brand-700); }
.badge--brand   { background: var(--brand-100);   color: var(--brand-700); }

.badge__dot {
  width: 6px; height: 6px; border-radius: var(--radius-full);
  background: currentColor;
}

/* ---------- DIVIDER ---------- */
.divider { height: 1px; background: var(--gray-200); border: 0; margin: var(--space-4) 0; }
