/* ============================================================
   NAUTICA SENTINEL — COMPONENT LIBRARY
   Buttons, cards, badges, tables, modals, tabs, alerts, etc.
   ============================================================ */

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
  user-select: none;
  position: relative;
}

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

/* Primary */
.btn-primary {
  background: var(--color-brand);
  color: var(--ns-white);
  border-color: var(--color-brand);
}
.btn-primary:hover { background: var(--color-brand-hover); border-color: var(--color-brand-hover); color: var(--ns-white, #ffffff); }
.btn-primary:active { background: var(--color-brand-active); }

/* Secondary */
.btn-secondary {
  background: var(--color-secondary);
  color: var(--ns-white);
  border-color: var(--color-secondary);
}
.btn-secondary:hover { background: var(--color-secondary-hover); color: var(--ns-white, #ffffff); }

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
.btn-ghost:hover { background: var(--color-bg-page); color: var(--color-text-primary); }

/* Outline */
.btn-outline {
  background: transparent;
  color: var(--color-brand);
  border-color: var(--color-brand);
}
.btn-outline:hover { background: var(--color-brand-subtle); }

/* Danger */
.btn-danger {
  background: var(--color-danger);
  color: var(--ns-white);
  border-color: var(--color-danger);
}
.btn-danger:hover { background: var(--ns-red-700); color: var(--ns-white, #ffffff); }

/* Sizes */
.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}
.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}
.btn-xl {
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-lg);
}

/* Icon only */
.btn-icon {
  padding: var(--space-2);
  border-radius: var(--radius-md);
}
.btn-icon.btn-sm { padding: var(--space-1); }

/* Loading state */
.btn.loading .btn-text { opacity: 0; }
.btn.loading::after {
  content: '';
  position: absolute;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ── CARDS ── */
.card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-xs);
}

.card-elevated {
  background: var(--color-bg-elevated);
  box-shadow: var(--shadow-md);
  border-color: transparent;
}

.card-interactive {
  cursor: pointer;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}
.card-interactive:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-brand);
  transform: translateY(-1px);
}

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

.card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

.card-body { /* content area, no extra styles needed */ }

.card-footer {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* Stat card */
.stat-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.stat-card-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
}

.stat-card-value {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--color-text-primary);
  line-height: 1;
}

.stat-card-delta {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.stat-card-delta.up   { color: var(--color-success); }
.stat-card-delta.down { color: var(--color-danger); }

.stat-card-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
}

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.125rem var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-full);
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-success { background: var(--color-success-subtle); color: var(--ns-green-700); border-color: var(--color-success-border); }
.badge-warning { background: var(--color-warning-subtle); color: var(--ns-gold-700); border-color: var(--color-warning-border); }
.badge-danger  { background: var(--color-danger-subtle);  color: var(--ns-red-700);  border-color: var(--color-danger-border); }
.badge-info    { background: var(--color-info-subtle);    color: var(--ns-blue-600); border-color: var(--color-info-border); }
.badge-neutral { background: var(--ns-slate-100); color: var(--ns-slate-700); border-color: var(--ns-slate-200); }
.badge-brand   { background: var(--color-brand-subtle); color: var(--ns-navy-700); border-color: var(--ns-navy-100); }

.badge-lg {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}

/* Traffic light for cert expiry */
.cert-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.cert-status::before {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.cert-status.valid::before    { background: var(--color-success); }
.cert-status.expiring::before { background: var(--color-warning); }
.cert-status.expired::before  { background: var(--color-danger); }
.cert-status.valid   { color: var(--ns-green-700); }
.cert-status.expiring{ color: var(--ns-gold-700); }
.cert-status.expired { color: var(--ns-red-700); }

/* ── TABLES ── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.data-table {
  min-width: 100%;
}

.data-table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  background: var(--color-bg-page);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  cursor: default;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.data-table th.sortable:hover { color: var(--color-text-primary); }

.data-table th.sorted-asc::after  { content: ' ↑'; }
.data-table th.sorted-desc::after { content: ' ↓'; }

.data-table td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

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

.data-table tbody tr:hover {
  background: var(--color-bg-page);
}

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

.data-table .cell-primary {
  color: var(--color-text-primary);
  font-weight: var(--weight-medium);
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.pagination-page {
  min-width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.pagination-page:hover     { background: var(--color-bg-page); }
.pagination-page.active    { background: var(--color-brand); color: var(--ns-white); }

/* ── ALERTS / BANNERS ── */
.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border-left: 4px solid;
  font-size: var(--text-sm);
}

.alert-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  margin-top: 0.1em;
}

.alert-content { flex: 1; }
.alert-title   { font-weight: var(--weight-semibold); margin-bottom: var(--space-1); }
.alert-body    { color: var(--color-text-secondary); }

.alert-dismiss {
  flex-shrink: 0;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-1);
}

.alert-success { background: var(--color-success-subtle); border-color: var(--color-success); color: var(--ns-green-700); }
.alert-warning { background: var(--color-warning-subtle); border-color: var(--color-warning); color: var(--ns-gold-700); }
.alert-danger  { background: var(--color-danger-subtle);  border-color: var(--color-danger);  color: var(--ns-red-700); }
.alert-info    { background: var(--color-info-subtle);    border-color: var(--color-info);    color: var(--ns-blue-600); }

/* ── TABS ── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  overflow-x: auto;
}

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

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

.tab-panel { display: none; padding-top: var(--space-6); }
.tab-panel.active { display: block; }

/* ── MODAL ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-bg-overlay);
  z-index: var(--z-modal);
  display: none;          /* hidden by default — JS adds .active to show */
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  background: var(--color-bg-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp var(--transition-base);
}

.modal-sm  { max-width: 26rem; }
.modal-md  { max-width: 36rem; }
.modal-lg  { max-width: 48rem; }
.modal-xl  { max-width: 64rem; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-6) var(--space-6) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.modal-close {
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.modal-close:hover { background: var(--color-bg-page); color: var(--color-text-primary); }

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

.modal-footer {
  padding: var(--space-4) var(--space-6) var(--space-6);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(1rem); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── DROPDOWN ── */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  min-width: 12rem;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  padding: var(--space-1) 0;
  animation: slideUp var(--transition-fast);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-decoration: none;
}
.dropdown-item:hover { background: var(--color-bg-page); color: var(--color-text-primary); }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-item.danger:hover { background: var(--color-danger-subtle); }

.dropdown-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-1) 0;
}

/* ── TIMELINE ── */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}

.timeline-item {
  display: flex;
  gap: var(--space-4);
  padding-bottom: var(--space-6);
  position: relative;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-line {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.timeline-dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--color-brand);
  border: 2px solid var(--color-bg-surface);
  box-shadow: 0 0 0 2px var(--color-brand);
  flex-shrink: 0;
  margin-top: 0.2rem;
}

.timeline-connector {
  width: 2px;
  flex: 1;
  background: var(--color-border);
  margin-top: var(--space-1);
}

.timeline-item:last-child .timeline-connector { display: none; }

.timeline-content { flex: 1; }
.timeline-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

/* ── PROGRESS BARS ── */
.progress {
  height: 0.5rem;
  background: var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-brand);
  transition: width var(--transition-slow);
}

.progress-bar.success { background: var(--color-success); }
.progress-bar.warning { background: var(--color-warning); }
.progress-bar.danger  { background: var(--color-danger); }

/* ── SKELETON LOADER ── */
.skeleton {
  background: linear-gradient(90deg, var(--ns-slate-100) 25%, var(--ns-slate-200) 50%, var(--ns-slate-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

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

/* ── AVATAR ── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--ns-navy-500);
  color: var(--ns-white);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
}

.avatar-sm  { width: 1.5rem; height: 1.5rem; font-size: var(--text-xs); }
.avatar-md  { width: 2rem;   height: 2rem;   font-size: var(--text-sm); }
.avatar-lg  { width: 2.5rem; height: 2.5rem; font-size: var(--text-base); }
.avatar-xl  { width: 3.5rem; height: 3.5rem; font-size: var(--text-lg); }
.avatar-2xl { width: 5rem;   height: 5rem;   font-size: var(--text-2xl); }

.avatar-group {
  display: flex;
  align-items: center;
}
.avatar-group .avatar {
  border: 2px solid var(--color-bg-surface);
  margin-left: -0.5rem;
}
.avatar-group .avatar:first-child { margin-left: 0; }

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

.empty-state-icon {
  width: 4rem;
  height: 4rem;
  color: var(--color-text-muted);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

.empty-state-body {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 24rem;
}

/* ── KANBAN BOARD ── */
.kanban-board {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  padding-bottom: var(--space-4);
}

.kanban-column {
  flex-shrink: 0;
  width: 18rem;
  background: var(--color-bg-page);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.kanban-column-count {
  min-width: 1.25rem;
  height: 1.25rem;
  background: var(--color-border-strong);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kanban-cards {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 10rem;
}

.kanban-card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  cursor: grab;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.kanban-card:hover       { box-shadow: var(--shadow-md); border-color: var(--color-brand); }
.kanban-card.dragging    { opacity: 0.5; cursor: grabbing; }
.kanban-card.drag-over   { border-color: var(--ns-teal-400); background: var(--color-secondary-subtle); }

.kanban-card-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.kanban-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.kanban-drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.kanban-drop-zone.over { border-color: var(--ns-teal-400); background: var(--color-secondary-subtle); }

/* ── STEPS / WIZARD ── */
.steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: var(--space-8);
  overflow-x: auto;
}

.step {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 0;
}

.step-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.step-circle {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid var(--color-border-strong);
  background: var(--color-bg-surface);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.step.completed .step-circle { background: var(--color-success); border-color: var(--color-success); color: var(--ns-white); }
.step.active    .step-circle { background: var(--color-brand);   border-color: var(--color-brand);   color: var(--ns-white); }

.step-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
  text-align: center;
}
.step.active .step-label    { color: var(--color-brand); font-weight: var(--weight-medium); }
.step.completed .step-label { color: var(--color-success); }

.step-connector {
  flex: 1;
  height: 2px;
  background: var(--color-border);
  margin: 0 var(--space-2);
  margin-bottom: var(--space-6);
  transition: background var(--transition-fast);
}
.step.completed + .step .step-connector,
.step.completed .step-connector {
  background: var(--color-success);
}

/* ── TOGGLE SWITCH ── */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  width: 2.75rem;
  height: 1.5rem;
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  transition: background var(--transition-fast), border-color var(--transition-fast);
  position: relative;
  flex-shrink: 0;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.125rem;
  height: 1.125rem;
  background: white;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.switch input:checked + .switch-track {
  background: var(--color-brand);
  border-color: var(--color-brand);
}

.switch input:checked + .switch-track::after {
  transform: translateX(1.25rem);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
}

/* ── ADMIN-SPECIFIC ── */
.sub-tier-row {
  display: flex;
  align-items: center;
}

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

.btn-danger:hover {
  background: #dc2626;
}

.badge-danger {
  background: #fef2f2;
  color: var(--color-danger);
  border: 1px solid #fecaca;
}
