/*
|--------------------------------------------------------------------------
| Captain's Toolkit
| Components CSS
|--------------------------------------------------------------------------
*/

/* =========================================================
   CARDS
========================================================= */

.card {
  min-width: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-soft);
}

.card-premium {
  background: linear-gradient(180deg, #ffffff 0%, var(--color-surface-soft) 100%);
}

.card-dark {
  background:
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.25), transparent 18rem),
    var(--color-navy);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.12);
}

.danger-card {
  border-color: rgba(220, 38, 38, 0.28);
  background: linear-gradient(180deg, #ffffff 0%, rgba(254, 242, 242, 0.9) 100%);
}

.section-head,
.card-header,
.split,
.button-row,
.form-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.section-head,
.card-header {
  margin-bottom: var(--space-4);
}

.section-head > *,
.card-header > *,
.split > * {
  min-width: 0;
}

.card-title,
.section-title {
  margin: 0;
  color: var(--color-text);
  font-weight: 600;
  line-height: 1.2;
}

.card-subtitle,
.section-description {
  margin: var(--space-1) 0 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.card-actions,
.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* =========================================================
   BUTTONS
========================================================= */

.button-row,
.form-actions {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.btn,
.button {
  min-height: 44px;
  padding: 0 var(--space-5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    background var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    opacity var(--transition-fast);
}

.btn:hover,
.button:hover {
  transform: translateY(-1px);
}

.btn:focus-visible,
.button:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.btn:disabled,
.button:disabled,
.btn.is-disabled,
.button.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary,
.button-primary {
  color: #ffffff;
  background: var(--color-blue);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

.btn-secondary,
.button-secondary {
  color: #070707;
  background: #dbd894;
  border-color: var(--color-border);
}

.btn-danger,
.button-danger {
  color: #ffffff;
  background: var(--color-red);
  box-shadow: 0 10px 22px rgba(220, 38, 38, 0.18);
}

.btn-success,
.button-success {
  color: #ffffff;
  background: var(--color-green);
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.16);
}

.btn-warning,
.button-warning {
  color: #78350f;
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(217, 119, 6, 0.22);
}

.btn-ghost,
.button-ghost {
  color: var(--color-text);
  background: #bcc7cd94;
  border-color: #00000021;
}

.btn-ghost:hover,
.button-ghost:hover {
  background: var(--color-surface-soft);
}

.btn-sm,
.button-small {
  min-height: 34px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
}

.btn-block,
.button-block {
  width: 100%;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--color-text);
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    background var(--transition-fast),
    border-color var(--transition-fast);
}

.icon-button:hover {
  transform: translateY(-1px);
  background: var(--color-surface-soft);
}

/* =========================================================
   STAT / METRIC CARDS
========================================================= */

.stat-card,
.metric-card {
  min-width: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-soft);
}

.stat-header,
.metric-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.stat-label,
.metric-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-muted);
  line-height: 1.35;
}

.stat-value,
.metric-value {
  display: block;
  max-width: 100%;
  font-family: var(--font-mono);
  font-size: clamp(1.45rem, 4vw, 2.25rem);
  line-height: 1;
  font-weight: 900;
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.stat-meta,
.metric-meta {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-muted);
  line-height: 1.45;
}

/* =========================================================
   BADGES / STATUS CHIPS
========================================================= */

.badge,
.status-chip,
.chip,
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  width: fit-content;
  max-width: 100%;
  min-height: 28px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}

.status-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: var(--radius-full);
  background: currentColor;
}

.badge-success,
.status-success {
  color: var(--color-green);
  background: rgba(15, 118, 110, 0.1);
}

.badge-info,
.status-info {
  color: var(--color-blue);
  background: rgba(37, 99, 235, 0.1);
}

.badge-warning,
.status-warning {
  color: var(--color-warning);
  background: rgba(217, 119, 6, 0.12);
}

.badge-danger,
.status-danger {
  color: var(--color-red);
  background: rgba(220, 38, 38, 0.1);
}

.badge-muted,
.status-muted {
  color: var(--color-muted);
  background: rgba(100, 116, 139, 0.1);
}

/* =========================================================
   DATA LISTS
========================================================= */

.data-list,
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: 12px;
}

.data-list.compact {
  gap: var(--space-1);
}

.data-row {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid rgba(220, 227, 236, 0.72);
}

.data-row:last-child {
  border-bottom: 0;
}

.data-label {
  min-width: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
  line-height: 1.4;
}

.data-value {
  min-width: 0;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

/* =========================================================
   PROGRESS
========================================================= */

.progress,
.progress-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: #e7edf5;
}

.progress-track span,
.progress-bar {
  display: block;
  height: 100%;
  width: var(--progress, 0%);
  max-width: 100%;
  border-radius: inherit;
  background: var(--color-blue);
}

.progress-success {
  background: var(--color-green);
}

.progress-warning {
  background: var(--color-warning);
}

.progress-danger {
  background: var(--color-red);
}

/* =========================================================
   LIST CARDS / ROW COMPONENTS
========================================================= */

.list-card,
.export-row,
.quick-action,
.checklist-item-row,
.cloud-history-row,
.crew-row,
.fuel-log-row,
.maintenance-item,
.voyage-row {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.list-card-main,
.export-row-main,
.cloud-history-main,
.checklist-item-main,
.crew-row-main,
.fuel-log-main,
.maintenance-main,
.voyage-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.list-card-title,
.export-row-title,
.cloud-history-title,
.checklist-item-title,
.crew-row-title,
.fuel-log-title,
.maintenance-title,
.voyage-title {
  margin: 0;
  font-weight: 900;
  color: var(--color-text);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.list-card-meta,
.export-row-meta,
.cloud-history-meta,
.checklist-item-meta,
.crew-row-meta,
.fuel-log-meta,
.maintenance-meta,
.voyage-meta,
.export-row span,
.quick-action span {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-muted);
  line-height: 1.45;
}

.list-row-actions,
.data-row-actions,
.export-row-actions,
.cloud-history-actions,
.checklist-item-actions,
.crew-row-actions,
.fuel-log-actions,
.maintenance-actions,
.voyage-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  flex-wrap: wrap;
  flex: 0 0 auto;
}

/* =========================================================
   EMPTY STATES / NOTICES
========================================================= */

.empty-state {
  padding: var(--space-8);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-lg);
  background: rgb(183 190 190 / 0.38);
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: var(--space-2);
  color: var(--color-text);
  font-size: var(--text-lg);
  line-height: 1.25;
}

.empty-state span,
.empty-state p {
  display: block;
  max-width: 42rem;
  margin-inline: auto;
  color: var(--color-muted);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.empty-state-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-4);
}

.notice,
.alert,
.info-alert,
.success-alert,
.warning-alert,
.danger-alert {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: #ffffff;
  color: var(--color-text);
  font-weight: 700;
  line-height: 1.45;
}

.notice-success,
.success-alert {
  color: var(--color-text-light);
  background: rgb(17 91 85);
  border-color: rgba(15, 118, 110, 0.22);
}

.notice-error,
.notice-danger,
.danger-alert {
  color: var(--color-red);
  background: rgba(220, 38, 38, 0.1);
  border-color: rgba(220, 38, 38, 0.22);
}

.notice-info,
.info-alert {
  color: var(--color-blue);
  background: rgba(37, 99, 235, 0.1);
  border-color: rgba(37, 99, 235, 0.22);
}

.notice-warning,
.warning-alert {
  color: #92400e;
  background: rgba(217, 119, 6, 0.12);
  border-color: rgba(217, 119, 6, 0.22);
}

/* =========================================================
   CHECKLISTS
========================================================= */

.checklist-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: #294062;
  font-weight: 600;
  line-height: 1.45;
}

.checklist-item input {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  accent-color: var(--color-blue);
}

.checklist-item input:checked + span {
  color: rgb(134 149 169 / 68%);
  text-decoration: line-through;
}

/* =========================================================
   INLINE FORM
========================================================= */

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.inline-form input {
  min-height: 42px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--color-text);
}

/* =========================================================
   ALERT / EMERGENCY COMPONENTS
========================================================= */

.alert-card {
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-soft);
}

.alert-card.danger {
  color: #7f1d1d;
  background: linear-gradient(180deg, #ffffff 0%, #fef2f2 100%);
  border-color: rgba(220, 38, 38, 0.25);
}

.mayday-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.2);
}

.emergency-procedure,
.emergency-crew-card,
.fuel-entry,
.maintenance-task,
.crew-card,
.voyage-card,
.checklist-card {
  position: relative;
  min-width: 0;
}

.emergency-procedure {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.emergency-procedure strong {
  display: block;
  margin-bottom: var(--space-2);
  color: var(--color-text);
  line-height: 1.3;
}

.emergency-procedure p,
.fuel-entry-notes,
.maintenance-task-notes,
.crew-notes,
.voyage-notes {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.emergency-crew-card {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.is-completed {
  opacity: 0.75;
}

.is-completed h3 {
  text-decoration: line-through;
}

/* =========================================================
   TOASTS
========================================================= */

.app-toast-container {
  position: fixed;
  right: var(--space-5);
  bottom: calc(var(--bottom-nav-height, 0px) + var(--space-5) + env(safe-area-inset-bottom));
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.app-toast {
  min-width: 240px;
  max-width: 360px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-navy);
  color: #ffffff;
  box-shadow: var(--shadow-floating);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast);
  pointer-events: auto;
}

.app-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.app-toast button {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.25rem;
  cursor: pointer;
}

/* =========================================================
   MODALS
========================================================= */

.modal {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: grid;
  place-items: center;
  padding: var(--space-5);
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 17, 32, 0.58);
  backdrop-filter: blur(6px);
}

.modal__panel {
  position: relative;
  width: min(100%, 560px);
  max-height: 90vh;
  overflow: auto;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-floating);
}

.modal--sm .modal__panel {
  width: min(100%, 420px);
}

.modal__header,
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.modal__footer {
  justify-content: flex-end;
  border-top: 1px solid var(--color-border);
  border-bottom: 0;
}

.modal__body {
  padding: var(--space-5);
}

.modal__close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--color-surface-soft);
  cursor: pointer;
}

.is-modal-open {
  overflow: hidden;
}

/* =========================================================
   LOADING
========================================================= */

.loading-state {
  display: grid;
  place-items: center;
  gap: var(--space-3);
  padding: var(--space-8);
  color: var(--color-muted);
  text-align: center;
}

.loading-state__spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-blue);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* =========================================================
   UTILITIES
========================================================= */

.mt-2 {
  margin-top: var(--space-2);
}

.mt-4 {
  margin-top: var(--space-4);
}

.divider {
  height: 1px;
  background: var(--color-border);
  border: 0;
  margin: var(--space-4) 0;
}

/* =========================================================
   TABLET
========================================================= */

@media (max-width: 1024px) {
  .card,
  .stat-card,
  .metric-card {
    padding: var(--space-5);
  }

  .section-head,
  .card-header {
    gap: var(--space-3);
  }

  .list-card,
  .export-row,
  .quick-action,
  .checklist-item-row,
  .cloud-history-row,
  .crew-row,
  .fuel-log-row,
  .maintenance-item,
  .voyage-row {
    gap: var(--space-3);
  }
}

/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 720px) {
  .card,
  .stat-card,
  .metric-card {
    padding: var(--space-4);
    border-radius: var(--radius-md);
  }

  .section-head,
  .card-header,
  .split {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  .card-actions,
  .section-actions {
    width: 100%;
    justify-content: stretch;
  }

  .card-actions .button,
  .section-actions .button {
    flex: 1 1 auto;
  }

  .btn,
  .button {
    width: 100%;
    white-space: normal;
  }

  .btn-sm,
  .button-small {
    width: auto;
  }

  .button-row,
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .button-row .button,
  .form-actions .button,
  .button-row .btn,
  .form-actions .btn {
    width: 100%;
  }

  .stat-header,
  .metric-header {
    flex-direction: column;
    align-items: stretch;
  }

  .stat-value,
  .metric-value {
    font-size: clamp(1.35rem, 9vw, 2rem);
  }

  .badge,
  .status-chip,
  .chip,
  .tag {
    white-space: normal;
    line-height: 1.25;
    padding-block: var(--space-1);
  }

  .list-card,
  .export-row,
  .quick-action,
  .checklist-item-row,
  .cloud-history-row,
  .crew-row,
  .fuel-log-row,
  .maintenance-item,
  .voyage-row {
    flex-direction: column;
    align-items: stretch;
  }

  .list-row-actions,
  .data-row-actions,
  .export-row-actions,
  .cloud-history-actions,
  .checklist-item-actions,
  .crew-row-actions,
  .fuel-log-actions,
  .maintenance-actions,
  .voyage-actions {
    width: 100%;
    justify-content: stretch;
  }

  .list-row-actions .button,
  .data-row-actions .button,
  .export-row-actions .button,
  .cloud-history-actions .button,
  .checklist-item-actions .button,
  .crew-row-actions .button,
  .fuel-log-actions .button,
  .maintenance-actions .button,
  .voyage-actions .button {
    flex: 1 1 auto;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .data-row {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--space-1);
  }

  .data-value {
    text-align: left;
  }

  .empty-state {
    padding: var(--space-5);
  }

  .empty-state-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .empty-state-actions .button,
  .empty-state-actions .btn {
    width: 100%;
  }

  .modal {
    padding: var(--space-3);
    align-items: end;
  }

  .modal__panel {
    width: 100%;
    max-height: 88vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .modal__header,
  .modal__footer {
    padding: var(--space-4);
  }

  .modal__body {
    padding: var(--space-4);
  }

  .modal__footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .modal__footer .button,
  .modal__footer .btn {
    width: 100%;
  }

  .app-toast-container {
    right: var(--space-4);
    left: var(--space-4);
  }

  .app-toast {
    width: 100%;
    max-width: none;
  }
}

/* =========================================================
   SMALL MOBILE
========================================================= */

@media (max-width: 420px) {
  .card,
  .stat-card,
  .metric-card,
  .list-card,
  .export-row,
  .quick-action,
  .checklist-item-row,
  .cloud-history-row,
  .crew-row,
  .fuel-log-row,
  .maintenance-item,
  .voyage-row {
    padding: var(--space-3);
  }

  .empty-state {
    padding: var(--space-4);
  }

  .modal {
    padding: 0;
  }

  .modal__panel {
    max-height: 92vh;
  }
}

/* =========================================================
   PRINT
========================================================= */

@media print {
  body * {
    visibility: hidden;
  }

  .screen-emergency,
  .screen-emergency * {
    visibility: visible;
  }

  .screen-emergency {
    position: absolute;
    inset: 0;
    background: #ffffff;
  }

  .screen-emergency .page-head .btn,
  .screen-emergency .page-head .button,
  .screen-emergency form,
  .screen-emergency .notice,
  .screen-emergency .stat-card,
  .screen-emergency .card:not(.emergency-print-card),
  .screen-emergency .alert-card {
    display: none !important;
  }

  .emergency-print-card {
    break-inside: avoid;
    box-shadow: none;
    border-color: #111827;
  }
}

/* =========================================================
   DEMO BANNER
========================================================= */

.demo-banner {
  position: sticky;
  top: 0;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 16px;
  background: #b6183d;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.demo-banner strong {
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.demo-banner span {
  opacity: 0.95;
}

@media (max-width: 640px) {
  .demo-banner {
    flex-direction: column;
    gap: 2px;
    padding: 9px 12px;
    font-size: 12px;
    line-height: 1.35;
  }
}