/* ==========================================================================
   Shared Design System — Component Base Styles
   Version: 1.0 | Date: 2026-08-03
   15 components matching DESIGN_SYSTEM_SPEC.md §3

   Load after: design-tokens.css, layout.css
   ========================================================================== */

/* --------------------------------------------------------------------------
   3.1  Button
   -------------------------------------------------------------------------- */

.btn {
  display:        inline-flex;
  align-items:    center;
  justify-content:center;
  gap:            var(--space-2);
  padding:        13px 22px;
  font-family:    var(--font-body);
  font-size:      var(--text-base);
  font-weight:    var(--weight-medium);
  line-height:    var(--leading-normal);
  border-radius:  var(--r-btn);
  border:         var(--border-width) solid transparent;
  cursor:         pointer;
  transition:     transform var(--duration-fast) var(--ease-default),
                  background var(--duration-fast) var(--ease-default),
                  border-color var(--duration-fast) var(--ease-default);
  position:       relative;
  user-select:    none;
  text-decoration:none;

  /* 48×48 px minimum touch target via ::before expansion */
  &::before {
    content: '';
    position: absolute;
    inset: -5px;
  }
}

/* Variants */
.btn--solid {
  background: var(--text);
  color:      var(--text-inverse);
}

.btn--outline {
  background:   var(--surface);
  color:        var(--text);
  border-color: var(--border);
}

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

.btn--icon {
  background:   var(--surface);
  color:        var(--text);
  border-color: var(--border);
  padding:      12px;
  width:        38px;
  height:       38px;
}

.btn--brand {
  background: var(--accent-brand);
  color:      var(--text-inverse);
}

/* States */
.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  filter:    brightness(0.95);
}

.btn:focus-visible {
  outline:        var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

.btn:disabled,
.btn--loading {
  opacity:        0.5;
  cursor:         not-allowed;
  pointer-events: none;
  transform:      none;
}

/* --------------------------------------------------------------------------
   3.2  Card
   -------------------------------------------------------------------------- */

.card {
  background:    var(--surface);
  border:        var(--border-width) solid var(--border);
  border-radius: var(--r-card);
  box-shadow:    var(--shadow-none);
  overflow:      hidden;
  transition:    transform var(--duration-slow) var(--ease-out),
                 box-shadow var(--duration-slow) var(--ease-out),
                 border-color var(--duration-slow) var(--ease-out);
}

.card--feature {
  border-radius: var(--r-card-lg);
  box-shadow:    var(--shadow-md);
}

.card--elevated {
  box-shadow: var(--shadow-sm);
}

.card--nested {
  background:    var(--surface-2);
  border-radius: var(--r-group);
  box-shadow:    none;
}

/* Card states */
.card:hover {
  transform:  translate(-3px, -5px);
  box-shadow: var(--shadow-sheet);
}

.card--active {
  border-color: var(--accent-primary);
  box-shadow:   inset var(--glow-subtle);
}

.card--collapsed {
  max-height: var(--header-h);
  overflow:   hidden;
}

/* Card sub-elements */
.card__body {
  padding: 22px 24px;
}

.card--feature .card__body {
  padding: 18px;
}

.card__header {
  padding-bottom: var(--space-4);
  font-family:    var(--font-display);
  font-size:      var(--text-lg);
  font-weight:    var(--weight-semibold);
}

.card__footer {
  padding-top: var(--space-3);
  border-top:  var(--border-width) solid var(--border);
  color:       var(--text-muted);
  font-size:   var(--text-sm);
}

/* --------------------------------------------------------------------------
   3.3  Badge / Tag / Chip
   -------------------------------------------------------------------------- */

.badge {
  display:        inline-flex;
  align-items:    center;
  gap:            var(--space-1);
  padding:        2px 8px;
  font-family:    var(--font-body);
  font-size:      var(--text-xs);
  font-weight:    var(--weight-medium);
  line-height:    var(--leading-snug);
  border-radius:  var(--r-chip);
  border:         var(--border-width) solid var(--border);
  background:     var(--surface-2);
  color:          var(--text-muted);
  user-select:    none;
}

/* Semantic variants */
.badge--success { background: var(--accent-primary-soft);   color: var(--accent-primary-ink);   border-color: transparent; }
.badge--warning { background: var(--accent-secondary-soft); color: var(--accent-secondary-ink); border-color: transparent; }
.badge--error   { background: rgba(248, 81, 73, 0.15);      color: var(--status-error);         border-color: transparent; }
.badge--info    { background: rgba(88, 166, 255, 0.15);     color: var(--status-info);           border-color: transparent; }
.badge--brand   { background: var(--accent-brand-soft);     color: var(--accent-brand-ink);     border-color: transparent; }

/* Pill variant — round style for JobWatch compatibility */
.badge--pill {
  border-radius: 20px;
}

/* --------------------------------------------------------------------------
   3.4  Input
   -------------------------------------------------------------------------- */

.input {
  display:          block;
  width:            100%;
  padding:          13px 16px;
  font-family:      var(--font-body);
  font-size:        var(--text-base);
  line-height:      var(--leading-normal);
  color:            var(--text);
  background:       var(--surface);
  border:           var(--border-width) solid var(--border);
  border-radius:    var(--r-btn);
  transition:       border-color var(--duration-fast) var(--ease-default),
                    box-shadow var(--duration-fast) var(--ease-default);
  min-height:       48px;
}

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

.input:hover {
  border-color: var(--border-strong);
}

.input:focus {
  outline:        none;
  border-color:   var(--accent-primary);
  box-shadow:     0 0 0 var(--focus-ring-width) var(--focus-ring-color);
}

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

.input:disabled {
  opacity: 0.5;
  cursor:  not-allowed;
}

/* Input group wrapper */
.input-group {
  display:     flex;
  align-items: center;
  gap:         var(--space-2);
  position:    relative;
}

.input-group .input {
  flex: 1;
}

/* --------------------------------------------------------------------------
   3.5  Select
   -------------------------------------------------------------------------- */

.select {
  display:          block;
  width:            100%;
  padding:          13px 16px;
  font-family:      var(--font-body);
  font-size:        var(--text-base);
  line-height:      var(--leading-normal);
  color:            var(--text);
  background:       var(--surface);
  border:           var(--border-width) solid var(--border);
  border-radius:    var(--r-btn);
  cursor:           pointer;
  min-height:       48px;
  appearance:       none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%238b949e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right:    40px;
}

.select:focus {
  outline:        none;
  border-color:   var(--accent-primary);
  box-shadow:     0 0 0 var(--focus-ring-width) var(--focus-ring-color);
}

/* --------------------------------------------------------------------------
   3.6  Table
   -------------------------------------------------------------------------- */

.table {
  width:          100%;
  border-collapse:separate;
  border-spacing: 0;
  font-family:    var(--font-body);
  font-size:      var(--text-sm);
  line-height:    var(--leading-normal);
  background:     var(--surface);
  border:         var(--border-width) solid var(--border);
  border-radius:  var(--r-uniform);
  overflow:       hidden;
}

.table thead th {
  padding:          var(--space-3) var(--space-4);
  font-weight:      var(--weight-semibold);
  font-size:        var(--text-xs);
  text-transform:   uppercase;
  letter-spacing:   var(--tracking-wide);
  color:            var(--text-muted);
  border-bottom:    var(--border-width) solid var(--border);
  text-align:       left;
  background:       var(--surface);
  position:         sticky;
  top:              0;
}

.table tbody td {
  padding: var(--space-3) var(--space-4);
  color:   var(--text);
}

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

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

.table--striped tbody tr:nth-child(even) {
  background: var(--surface-2);
}

.table--selected {
  background: var(--accent-primary-soft) !important;
}

.table__sort {
  cursor: pointer;
}

.table__sort::after {
  content: ' ↕';
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Wrapper for responsive overflow */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* --------------------------------------------------------------------------
   3.7  Navbar / Header
   -------------------------------------------------------------------------- */

.navbar {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  height:          var(--nav-h);
  padding:         0 var(--page-x);
  position:        sticky;
  top:             0;
  z-index:         var(--z-sticky);
  transition:      background var(--duration-normal) var(--ease-default);
}

.navbar--frosted {
  background:      var(--nav-bg);
  backdrop-filter: blur(12px);
  border-bottom:   var(--border-width) solid var(--border);
}

.navbar--solid {
  background:    var(--surface);
  border-bottom: var(--border-width) solid var(--border);
}

.navbar--transparent {
  background: transparent;
  position:   absolute;
}

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

.navbar__logo {
  font-family:     var(--font-display);
  font-size:       var(--text-lg);
  font-weight:     var(--weight-semibold);
  color:           var(--text-heading);
  text-decoration: none;
}

.navbar__links {
  display: flex;
  gap:     var(--space-1);
}

.navbar__link {
  padding:         var(--space-2) var(--space-3);
  font-family:     var(--font-body);
  font-size:       var(--text-sm);
  color:           var(--text-muted);
  text-decoration: none;
  border-radius:   var(--r-chip);
  transition:      color var(--duration-fast) var(--ease-default),
                   background var(--duration-fast) var(--ease-default);
}

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

.navbar__link--active {
  color: var(--accent-primary);
}

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

.navbar__hamburger {
  display: none;
  background: none;
  border:     none;
  color:      var(--text);
  cursor:     pointer;
  padding:    var(--space-2);
  width:      48px;
  height:     48px;
}

@media (max-width: 760px) {
  .navbar {
    height: 52px;
  }

  .navbar__hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .navbar__links {
    display: none;
  }

  .navbar--open .navbar__links {
    display:     flex;
    flex-direction: column;
    position:    absolute;
    top:         100%;
    left:        0;
    right:       0;
    background:  var(--surface);
    border-bottom: var(--border-width) solid var(--border);
    padding:     var(--space-4);
  }
}

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

.modal__backdrop {
  position:         fixed;
  inset:            0;
  z-index:          var(--z-overlay);
  display:          flex;
  align-items:      center;
  justify-content:  center;
  padding:          var(--page-x);
  background:       rgba(15, 15, 20, 0.45);
  backdrop-filter:  blur(4px);
  animation:        fade-in var(--duration-normal) var(--ease-default);
}

.modal {
  position:        relative;
  z-index:         var(--z-modal);
  max-width:       620px;
  width:           100%;
  max-height:      calc(100vh - 2 * var(--page-x));
  background:      var(--surface);
  border:          var(--border-width) solid var(--border);
  border-radius:   var(--r-panel);
  box-shadow:      var(--shadow-xl);
  overflow:        hidden;
  animation:       modal-in var(--duration-slow) var(--ease-spring);
}

.modal__close {
  position:     absolute;
  top:          var(--space-4);
  right:        var(--space-4);
  z-index:      1;
}

.modal__body {
  padding:   var(--space-6);
  overflow-y:auto;
  max-height:calc(80vh - 2 * var(--space-6));
}

.modal__header {
  padding:          var(--space-5) var(--space-6) var(--space-3);
  font-family:      var(--font-display);
  font-size:        var(--text-xl);
  font-weight:      var(--weight-semibold);
  color:            var(--text-heading);
  border-bottom:    var(--border-width) solid var(--border);
}

.modal__footer {
  display:         flex;
  justify-content: flex-end;
  gap:             var(--space-2);
  padding:         var(--space-4) var(--space-6);
  border-top:      var(--border-width) solid var(--border);
}

/* --------------------------------------------------------------------------
   3.9  Progress Bar
   -------------------------------------------------------------------------- */

.progress {
  width:           100%;
  height:          6px;
  background:      var(--surface-2);
  border-radius:   var(--r-pill);
  overflow:        hidden;
}

.progress__fill {
  height:          100%;
  border-radius:   inherit;
  background:      linear-gradient(90deg, var(--accent-primary), var(--accent-brand));
  transition:      width var(--duration-normal) var(--ease-default);
}

.progress--indeterminate .progress__fill {
  width:      40%;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation:  shimmer 1.5s ease-in-out infinite;
}

.progress--scroll {
  position: fixed;
  top:      0;
  left:     0;
  z-index:  var(--z-progress);
  height:   3px;
  border-radius: 0;
}

/* --------------------------------------------------------------------------
   3.10  Empty State
   -------------------------------------------------------------------------- */

.empty-state {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  padding:         var(--space-9) var(--space-6);
  text-align:      center;
}

.empty-state__icon {
  color:         var(--text-muted);
  width:         48px;
  height:        48px;
  margin-bottom: var(--space-4);
}

.empty-state__message {
  font-size:   var(--text-base);
  font-weight: var(--weight-medium);
  color:       var(--text);
}

.empty-state__hint {
  font-size:  var(--text-sm);
  color:      var(--text-muted);
  margin-top: var(--space-2);
}

.empty-state__action {
  margin-top: var(--space-5);
}

/* --------------------------------------------------------------------------
   3.11  Toggle Switch
   -------------------------------------------------------------------------- */

.toggle {
  display:     inline-flex;
  align-items: center;
  gap:         var(--space-3);
  cursor:      pointer;
  user-select: none;
  position:    relative;
  min-height:  48px;
  min-width:   72px;
}

.toggle__input {
  position: absolute;
  opacity:  0;
  width:    0;
  height:   0;
}

.toggle__track {
  position:       relative;
  width:          52px;
  height:         28px;
  border-radius:  var(--r-pill);
  background:     var(--surface-2);
  transition:     background var(--duration-normal) var(--ease-in-out);
  flex-shrink:    0;
}

.toggle__thumb {
  position:       absolute;
  top:            3px;
  left:           3px;
  width:          22px;
  height:         22px;
  border-radius:  50%;
  background:     var(--text-muted);
  transition:     all var(--duration-normal) var(--ease-in-out);
}

.toggle__input:checked + .toggle__track {
  background: var(--accent-primary);
}

.toggle__input:checked + .toggle__track .toggle__thumb {
  left:       27px;
  background: var(--text-inverse);
  box-shadow: var(--glow-subtle);
}

.toggle__input:focus-visible + .toggle__track {
  outline:        var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

.toggle__input:disabled + .toggle__track {
  opacity: 0.5;
  cursor:  not-allowed;
}

.toggle__label {
  font-family: var(--font-body);
  font-size:   var(--text-sm);
  color:       var(--text);
}

/* --------------------------------------------------------------------------
   3.12  Skeleton Loader
   -------------------------------------------------------------------------- */

.skeleton {
  background:    var(--surface-2);
  border-radius: var(--r-uniform);
  animation:     shimmer 1.5s ease-in-out infinite;
  background-size: 200% 100%;
}

.skeleton--shimmer {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
}

.skeleton__line {
  width:         100%;
  height:        12px;
  margin-bottom: var(--space-2);
  border-radius: var(--r-uniform);
  background:    var(--surface-2);
}

.skeleton__line--title {
  width:  60%;
  height: 16px;
}

.skeleton__line--short {
  width: 40%;
}

.skeleton__avatar {
  border-radius: 50%;
  width:         48px;
  height:        48px;
  background:    var(--surface-2);
}

.skeleton-card {
  padding:       var(--space-4);
  border-radius: var(--r-card);
  background:    var(--surface);
  border:        var(--border-width) solid var(--border);
}

/* --------------------------------------------------------------------------
   3.13  State Dot
   -------------------------------------------------------------------------- */

.state-dot {
  display:       inline-block;
  width:         10px;
  height:        10px;
  border-radius: 2px;
  flex-shrink:   0;
  transition:    background var(--duration-normal) var(--ease-default),
                 box-shadow var(--duration-normal) var(--ease-default);
}

.state-dot--on {
  background: var(--status-success);
  box-shadow: var(--glow-standard);
}

.state-dot--off {
  background: var(--text-muted);
}

.state-dot--warning {
  background: var(--status-warning);
  box-shadow: var(--glow-subtle);
}

.state-dot--error {
  background: var(--status-error);
  box-shadow: var(--glow-subtle);
}

/* --------------------------------------------------------------------------
   3.14  Theme Toggle
   -------------------------------------------------------------------------- */

.theme-toggle {
  width:          48px;
  height:         48px;
  padding:        10px;
  background:     transparent;
  border:         none;
  border-radius:  var(--r-thumb);
  color:          var(--text);
  cursor:         pointer;
  transition:     background var(--duration-fast) var(--ease-default),
                  transform var(--duration-fast) var(--ease-default);
}

.theme-toggle:hover {
  background: var(--surface-2);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle__icon {
  width:  28px;
  height: 28px;
}

/* Default (dark mode): show sun icon */
[data-theme="dark"] .theme-toggle__icon--moon { display: none; }
[data-theme="light"] .theme-toggle__icon--sun { display: none; }

/* --------------------------------------------------------------------------
   3.15  Connection Status Indicator
   -------------------------------------------------------------------------- */

.connection-status {
  display:     inline-flex;
  align-items: center;
  gap:         var(--space-2);
  font-family: var(--font-body);
  font-size:   var(--text-xs);
  color:       var(--text-muted);
}

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

.connection-status--connected .connection-status__label {
  color: var(--status-success);
}

.connection-status--disconnected .connection-status__label {
  color: var(--status-error);
}

.connection-status--connecting .state-dot {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* ==========================================================================
   Respect reduced motion for all components
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .btn,
  .card,
  .toggle__track,
  .toggle__thumb,
  .input,
  .select,
  .state-dot,
  .theme-toggle,
  .navbar {
    transition: none !important;
  }

  .skeleton,
  .skeleton--shimmer,
  .progress--indeterminate .progress__fill,
  .connection-status--connecting .state-dot {
    animation: none !important;
  }

  .card:hover {
    transform: none;
  }
}
