/* HeyLynx — componentes reutilizáveis
 * card, button, input, select, table, sidebar, topbar, status-pill, avatar, modal, drawer, toast
 */

/* ----------------------------------------------------------------------------
 * Layout shell — sidebar + topbar + content
 * -------------------------------------------------------------------------- */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    'sidebar topbar'
    'sidebar content';
  min-height: 100vh;
}

.app-shell__sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: 0.5px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.app-shell__topbar {
  grid-area: topbar;
  background: var(--color-bg);
  border-bottom: 0.5px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-shell__content {
  grid-area: content;
  padding: var(--space-8) var(--space-6);
  max-width: var(--content-max-width);
  width: 100%;
}

/* ----------------------------------------------------------------------------
 * Logo (símbolo H + wordmark)
 * -------------------------------------------------------------------------- */

.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--color-text-primary);
  font-weight: var(--font-weight-medium);
  font-size: var(--text-base);
  letter-spacing: var(--letter-spacing-heading);
}

.logo__symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-medium);
  font-size: var(--text-base);
  letter-spacing: 0;
}

.logo__symbol--lg {
  width: 40px;
  height: 40px;
  font-size: var(--text-lg);
  border-radius: var(--radius-lg);
}

/* ----------------------------------------------------------------------------
 * Sidebar nav
 * -------------------------------------------------------------------------- */

.sidebar__brand {
  padding: var(--space-5) var(--space-5);
  border-bottom: 0.5px solid var(--color-border);
}

.sidebar__nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
}

.sidebar__nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar__nav-item:hover {
  background: var(--color-surface-elevated);
  color: var(--color-text-primary);
}

.sidebar__nav-item--active,
.sidebar__nav-item[aria-current='page'] {
  background: var(--color-accent-bg);
  color: var(--color-accent);
}

.sidebar__nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar__footer {
  border-top: 0.5px solid var(--color-border);
  padding: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar__user-info {
  flex: 1;
  min-width: 0;
}

.sidebar__user-name {
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__user-email {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Drawer toggle (mobile) — hidden por padrão, exposto via media query */
.sidebar__toggle {
  display: none;
  background: transparent;
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  padding: var(--space-2);
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
}

.sidebar__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 19;
}

/* ----------------------------------------------------------------------------
 * Topbar
 * -------------------------------------------------------------------------- */

.topbar__title {
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  letter-spacing: var(--letter-spacing-heading);
}

.topbar__breadcrumb {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ----------------------------------------------------------------------------
 * Cards
 * -------------------------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-card);
}

.card--elevated {
  background: var(--color-surface-elevated);
  box-shadow: var(--shadow-elevated);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card__title {
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  letter-spacing: var(--letter-spacing-heading);
}

.card__subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* Métric card (overview) */
.metric {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.metric__label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric__value {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  letter-spacing: var(--letter-spacing-heading);
  font-variant-numeric: tabular-nums;
}

.metric__delta {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.metric__delta--up { color: var(--color-success); }
.metric__delta--down { color: var(--color-danger); }

/* ----------------------------------------------------------------------------
 * Buttons
 * -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 0.5px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-body);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  min-height: 36px;
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn--primary {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  border-color: var(--color-accent);
}

.btn--primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  color: var(--color-text-on-accent);
}

.btn--primary:active {
  background: var(--color-accent-active);
  border-color: var(--color-accent-active);
}

.btn--secondary {
  background: transparent;
  color: var(--color-text-primary);
  border-color: var(--color-border-strong);
}

.btn--secondary:hover {
  background: var(--color-surface-elevated);
  border-color: var(--color-text-muted);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: transparent;
}

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

.btn--danger {
  background: var(--color-danger);
  color: var(--color-text-primary);
  border-color: var(--color-danger);
}

.btn--lg {
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-base);
  min-height: 44px;
}

.btn--sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  min-height: 28px;
}

.btn--block {
  display: flex;
  width: 100%;
}

/* ----------------------------------------------------------------------------
 * Inputs / forms
 * -------------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field__label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.02em;
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.field__error {
  font-size: var(--text-xs);
  color: var(--color-danger);
}

.input,
.select,
.textarea {
  font-family: var(--font-family);
  font-size: var(--text-sm);
  background: var(--color-bg);
  color: var(--color-text-primary);
  border: 0.5px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  min-height: 36px;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  width: 100%;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--color-text-muted);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--color-text-muted);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--color-accent);
  outline: none;
  background: var(--color-surface);
}

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

.textarea {
  min-height: 80px;
  resize: vertical;
  font-family: inherit;
}

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'><path d='M3 4.5L6 7.5L9 4.5' stroke='%23A0A0A8' stroke-width='1' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
}

/* ----------------------------------------------------------------------------
 * Status pill
 * -------------------------------------------------------------------------- */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  text-transform: capitalize;
  border: 0.5px solid transparent;
  background: var(--color-surface-elevated);
  color: var(--color-text-secondary);
}

.status-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill--active,
.status-pill--success,
.status-pill--paid {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.status-pill--inactive,
.status-pill--draft {
  background: var(--color-surface-elevated);
  color: var(--color-text-secondary);
}

.status-pill--blocked,
.status-pill--danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.status-pill--warning,
.status-pill--pending {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.status-pill--info,
.status-pill--sent {
  background: var(--color-info-bg);
  color: var(--color-info);
}

/* ----------------------------------------------------------------------------
 * Avatar
 * -------------------------------------------------------------------------- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-surface-elevated);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  flex-shrink: 0;
  user-select: none;
}

.avatar--sm {
  width: 24px;
  height: 24px;
  font-size: 10px;
}

.avatar--lg {
  width: 48px;
  height: 48px;
  font-size: var(--text-base);
}

/* ----------------------------------------------------------------------------
 * Tables
 * -------------------------------------------------------------------------- */

.table-container {
  overflow-x: auto;
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table thead th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 0.5px solid var(--color-border);
  background: var(--color-surface);
  white-space: nowrap;
}

.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 0.5px solid var(--color-border);
  color: var(--color-text-primary);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr {
  transition: background var(--transition-fast);
}

.table tbody tr:hover {
  background: var(--color-surface-elevated);
}

.table tbody tr.is-clickable {
  cursor: pointer;
}

.table__cell-numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.table__cell-muted {
  color: var(--color-text-muted);
}

/* ----------------------------------------------------------------------------
 * Modal
 * -------------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 50;
  padding: var(--space-4);
  animation: modal-fade-in var(--transition-base);
}

.modal[hidden] {
  display: none;
}

.modal__panel {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  max-width: 480px;
  width: 100%;
  max-height: calc(100vh - var(--space-8));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal__header {
  padding: var(--space-5);
  border-bottom: 0.5px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-heading);
}

.modal__close {
  background: transparent;
  border: 0;
  color: var(--color-text-muted);
  font-size: var(--text-lg);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.modal__close:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-elevated);
}

.modal__body {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.modal__footer {
  padding: var(--space-5);
  border-top: 0.5px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ----------------------------------------------------------------------------
 * Toast (mensagem flutuante)
 * -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  background: var(--color-surface-elevated);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-elevated);
  z-index: 60;
  max-width: 360px;
  animation: toast-slide-in var(--transition-base);
}

.toast--success { border-left: 2px solid var(--color-success); }
.toast--error { border-left: 2px solid var(--color-danger); }
.toast--info { border-left: 2px solid var(--color-info); }

@keyframes toast-slide-in {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ----------------------------------------------------------------------------
 * Toolbar (filtros + ações em listas)
 * -------------------------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.toolbar__search {
  flex: 1;
  min-width: 200px;
  max-width: 360px;
}

.toolbar__filters {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.toolbar__actions {
  margin-left: auto;
  display: flex;
  gap: var(--space-2);
}

/* ----------------------------------------------------------------------------
 * Empty state
 * -------------------------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--color-text-muted);
}

.empty-state__title {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state__description {
  font-size: var(--text-sm);
  margin-bottom: var(--space-5);
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

/* ----------------------------------------------------------------------------
 * Loading skeleton + spinner
 * -------------------------------------------------------------------------- */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface-elevated) 0%,
    var(--color-border-strong) 50%,
    var(--color-surface-elevated) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
  border-radius: var(--radius-sm);
  display: inline-block;
}

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

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
  to { transform: rotate(360deg); }
}

/* ----------------------------------------------------------------------------
 * Mobile (<768px)
 * -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas:
      'topbar'
      'content';
  }

  .app-shell__sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform var(--transition-base);
  }

  .app-shell__sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar__backdrop.is-open {
    display: block;
  }

  .sidebar__toggle {
    display: inline-flex;
  }

  .app-shell__content {
    padding: var(--space-5) var(--space-4);
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar__search {
    max-width: none;
  }

  .toolbar__actions {
    margin-left: 0;
  }

  /* Tables → cards stacked em mobile */
  .table-container--responsive .table thead {
    display: none;
  }

  .table-container--responsive .table tbody tr {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-1);
    padding: var(--space-3);
    border-bottom: 0.5px solid var(--color-border);
  }

  .table-container--responsive .table tbody td {
    padding: 2px 0;
    border: 0;
  }

  .table-container--responsive .table tbody td::before {
    content: attr(data-label);
    display: inline-block;
    width: 120px;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
}
