/* ═══════════════════════════════════════════════════════════════════════════
   Larrly Design System — components.css
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 38px;
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn--sm  { height: 30px; padding: 0 var(--space-3); font-size: var(--font-size-xs); border-radius: var(--radius-sm); }
.btn--lg  { height: 46px; padding: 0 var(--space-6); font-size: var(--font-size-md); }
.btn--icon { width: 38px; padding: 0; }
.btn--icon.btn--sm { width: 30px; }

.btn--primary {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}
.btn--primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  box-shadow: 0 1px 4px rgba(24,69,59,0.25);
}

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
  box-shadow: var(--shadow-sm);
}
.btn--secondary:hover {
  background: var(--color-surface-2);
  border-color: var(--color-text-subtle);
}

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

.btn--danger {
  background: var(--color-danger-subtle);
  color: var(--color-danger);
  border-color: transparent;
}
.btn--danger:hover {
  background: var(--color-danger);
  color: white;
}

.btn--loading { pointer-events: none; }
.btn--loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ─── Form Controls ───────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text);
}

.form-label--required::after {
  content: ' *';
  color: var(--color-danger);
}

.form-control {
  width: 100%;
  height: 38px;
  padding: 0 var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  box-shadow: var(--shadow-sm);
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}

.form-control:disabled { opacity: 0.5; cursor: not-allowed; background: var(--color-surface-2); }

.form-control--error   { border-color: var(--color-danger) !important; }
.form-control--success { border-color: var(--color-success) !important; }

textarea.form-control {
  height: auto;
  min-height: 90px;
  padding: var(--space-2) var(--space-3);
  resize: vertical;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239CA3AF' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
  cursor: pointer;
}

.form-hint  { font-size: var(--font-size-xs); color: var(--color-text-muted); }
.form-error { font-size: var(--font-size-xs); color: var(--color-danger); }

.form-row   { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); }
.form-row--2 { grid-template-columns: 1fr 1fr; }
.form-row--3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row--4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.form-check-label { font-size: var(--font-size-sm); color: var(--color-text); }

/* ─── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.02);
  overflow: hidden;
}

.card--hover { transition: box-shadow var(--transition), border-color var(--transition); cursor: pointer; }
.card--hover:hover { box-shadow: var(--shadow); border-color: var(--color-text-subtle); }

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-3);
}

.card__title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text);
}

.card__body   { padding: var(--space-5); }
.card__body--compact { padding: var(--space-4); }
.card__footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Stat card */
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.stat-card__label {
  font-size: var(--font-size-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.stat-card__value {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
  letter-spacing: -0.5px;
}

.stat-card__change {
  font-size: var(--font-size-xs);
  margin-top: var(--space-2);
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

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

/* ─── Tables ──────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

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

.table thead tr {
  border-bottom: 1px solid var(--color-border);
}

.table th {
  padding: 10px var(--space-4);
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  text-align: left;
  white-space: nowrap;
  background: var(--color-surface-2);
  cursor: pointer;
  user-select: none;
}

.table th:hover { color: var(--color-text); }
.table th.sort-asc::after  { content: ' \2191'; color: var(--color-primary); }
.table th.sort-desc::after { content: ' \2193'; color: var(--color-primary); }

.table td {
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
  color: var(--color-text);
  vertical-align: middle;
}

.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: var(--color-surface-2); }
.table tbody tr:last-child td { border-bottom: none; }

/* ─── Context Menu ────────────────────────────────────────────────────────── */
.context-menu {
  position: fixed;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  z-index: var(--z-dropdown);
  overflow: hidden;
}

.context-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-decoration: none;
}

.context-menu__item:hover { background: var(--color-surface-2); }
.context-menu__item--danger { color: var(--color-danger); }
.context-menu__item--danger:hover { background: var(--color-danger-subtle); }
.context-menu__divider { height: 1px; background: var(--color-border); margin: 4px 0; }

/* ─── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-xl);
  font-size: var(--font-size-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge--default  { background: var(--color-surface-3); color: var(--color-text-muted); }
.badge--primary  { background: var(--color-primary-subtle); color: var(--color-primary); }
.badge--success  { background: var(--color-success-subtle); color: var(--color-success); }
.badge--warning  { background: var(--color-warning-subtle); color: var(--color-warning); }
.badge--danger   { background: var(--color-danger-subtle);  color: var(--color-danger); }

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.is-open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  transform: translateY(10px) scale(0.99);
  transition: transform var(--transition);
  overflow: hidden;
}

.modal-overlay.is-open .modal { transform: none; }
.modal--lg { max-width: 800px; }
.modal--xl { max-width: 1100px; }
.modal--sm { max-width: 400px; }

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

.modal__title { font-size: var(--font-size-lg); font-weight: 600; color: var(--color-text); }

.modal__close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  display: flex;
}

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

.modal__body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-shrink: 0;
  background: var(--color-surface-2);
}

/* ─── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
}

.tab-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  text-decoration: none;
  white-space: nowrap;
  margin-bottom: -1px;
}

.tab-item:hover { color: var(--color-text); }
.tab-item.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* ─── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
  text-align: center;
  gap: var(--space-4);
}

.empty-state__icon {
  width: 56px;
  height: 56px;
  color: var(--color-text-subtle);
  opacity: 0.5;
}

.empty-state__title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text);
}

.empty-state__text {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  max-width: 360px;
}

/* ─── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.pagination__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.pagination__btn:hover { background: var(--color-surface-2); color: var(--color-text); }
.pagination__btn.is-active { background: var(--color-primary); border-color: var(--color-primary); color: white; }
.pagination__btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ─── Divider ─────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--color-border); margin: var(--space-4) 0; }
.divider--vertical { width: 1px; height: auto; margin: 0 var(--space-3); background: var(--color-border); }

/* ─── Utility ─────────────────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.text-muted   { color: var(--color-text-muted); }
.text-subtle  { color: var(--color-text-subtle); }
.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.text-primary { color: var(--color-primary); }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-end     { display: flex; align-items: center; justify-content: flex-end; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

/* ─── Avatar initials ─────────────────────────────────────────────────────── */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0; letter-spacing: -0.3px;
}
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }
.avatar--lg { width: 44px; height: 44px; font-size: 15px; }
.avatar--green  { background: #DCFCE7; color: #15803d; }
.avatar--blue   { background: #DBEAFE; color: #1d4ed8; }
.avatar--purple { background: #EDE9FE; color: #7c3aed; }
.avatar--orange { background: #FFEDD5; color: #c2410c; }
.avatar--pink   { background: #FCE7F3; color: #be185d; }
.avatar--teal   { background: #CCFBF1; color: #0f766e; }

/* ─── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-6);
}
.page-header__title { font-size: var(--font-size-xl); font-weight: 700; letter-spacing: -0.4px; }
.page-header__sub { font-size: var(--font-size-sm); color: var(--color-text-muted); margin-top: 2px; }

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn    { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp   { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: -200% 0; } to { background-position: 200% 0; } }

.animate-fade   { animation: fadeIn .25s ease; }
.animate-up     { animation: slideUp .3s ease; }
.animate-right  { animation: slideInRight .3s ease; }

/* Staggered children */
.stagger > * { opacity: 0; animation: slideUp .3s ease forwards; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 60ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 180ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }
.stagger > *:nth-child(6) { animation-delay: 300ms; }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface-3) 25%, var(--color-border) 50%, var(--color-surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}

/* Card hover lift */
.card-hover { transition: box-shadow .2s ease, transform .2s ease; }
.card-hover:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

/* ─── Modals ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 500;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadeIn .2s ease;
}
.modal {
  background: var(--color-surface); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); width: 100%;
  animation: slideUp .25s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--color-border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer; color: var(--color-text-muted);
  padding: 4px; border-radius: var(--radius); transition: color .15s;
}
.modal-close:hover { color: var(--color-text); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 24px; border-top: 1px solid var(--color-border);
}

/* ─── Page titles ─────────────────────────────────────────────────────────── */
.page-title { font-size: var(--font-size-xl); font-weight: 700; letter-spacing: -.4px; margin-bottom: 2px; }
.page-sub   { font-size: var(--font-size-sm); color: var(--color-text-muted); }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-6); flex-wrap: wrap; gap: 12px; }
.page-header__content { }
.page-header__actions { display: flex; gap: 8px; }

/* ─── Mobile responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
    --topbar-height: 56px;
    --content-padding: 16px;
  }

  .app-shell { display: block; }

  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 400;
    width: 260px; transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .topbar { left: 0 !important; padding: 0 16px; }
  .topbar__breadcrumb { display: none; }

  .mobile-menu-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; background: none; border: none; cursor: pointer;
    color: var(--color-text); border-radius: var(--radius); flex-shrink: 0;
  }

  .content-area { margin-left: 0 !important; padding: var(--content-padding); }
  .statusbar { left: 0 !important; }

  .sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 399;
  }
  .sidebar-overlay.visible { display: block; animation: fadeIn .2s ease; }

  .page-header { flex-direction: column; align-items: flex-start; }
}

@media (min-width: 769px) {
  .mobile-menu-btn { display: none; }
}
