/**
 * Base Styles & Accessibility Reset
 * Dornier Training Flight System
 */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text-main);
  background-color: var(--color-bg);
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Natural Heading Balance & Typographic Discipline */
h1, h2, h3, h4 {
  text-wrap: balance;
}

/* Tabular figures for numbers, codes, and identifiers */
.tabular-nums,
input,
code,
.badge-code {
  font-variant-numeric: tabular-nums;
}

/* Focus Visible Management */
:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Touch targets and clickable minimum sizes */
button,
input,
select,
a {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

/* Accessible Screen Reader Only Utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ==========================================================================
   ENTERPRISE BUTTON COMPONENT SYSTEM (SECTION 5)
   Tactile, refined military aviation button interactions with stable geometry
   ========================================================================== */
.btn,
.btn-tool,
.btn-workflow,
.dash-btn,
.btn-submit-sortie,
.btn-save-amendment,
.btn-unlock-submit,
.dash-signout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-weight: var(--font-weight-semibold);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: 
    background-color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    border-color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 180ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 120ms cubic-bezier(0.16, 1, 0.3, 1),
    filter 180ms ease;
  position: relative;
}

/* Tactile 1-2px press-down interaction across all interactive buttons */
.btn:active,
.btn-tool:active,
.btn-workflow:active,
.dash-btn:active,
.btn-submit-sortie:active,
.btn-save-amendment:active,
.btn-unlock-submit:active,
.dash-signout-btn:active {
  transform: translateY(1.5px) !important;
}

/* Primary Action Buttons */
.btn-primary,
.btn-workflow-primary {
  background: linear-gradient(180deg, #1D4ED8 0%, #173DB5 100%);
  color: #FFFFFF !important;
  border-color: #1E40AF;
  border-radius: var(--radius-md);
  padding: 8px 18px;
  font-size: var(--font-size-sm);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), var(--shadow-sm);
}

.btn-primary:hover,
.btn-workflow-primary:hover {
  background: linear-gradient(180deg, #2563EB 0%, #1D4ED8 100%);
  border-color: #1D4ED8;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), var(--shadow-md);
  transform: translateY(-1px);
}

/* Secondary Neutral & Tool Buttons */
.btn-secondary,
.btn-workflow-secondary {
  background: var(--color-surface);
  color: var(--color-text-main) !important;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-subtle);
}

.btn-secondary:hover,
.btn-workflow-secondary:hover {
  background: var(--color-surface-subtle);
  border-color: var(--color-border-hover);
  color: var(--color-text-main) !important;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

/* Destructive & Danger Buttons */
.btn-danger,
.btn-destructive {
  background: #DC2626;
  color: #FFFFFF !important;
  border: 1px solid #B91C1C;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-sm);
}

.btn-danger:hover,
.btn-destructive:hover {
  background: #B91C1C;
  border-color: #991B1B;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Tool Buttons in Physical Sortie Toolbar */
.btn-tool {
  padding: 6px 12px;
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-subtle);
}

.btn-tool:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* Sortie Submit Button in Physical Form */
.btn-submit-sortie {
  background: linear-gradient(180deg, #0C1E36 0%, #071527 100%);
  color: #FFFFFF !important;
  border: 1px solid #081528;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: var(--font-size-xs);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), var(--shadow-sm);
}

.btn-submit-sortie:hover {
  background: linear-gradient(180deg, #162B4D 0%, #0C1E36 100%);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Subtle Icon Nudge on Interactive Buttons */
.btn svg,
.btn-tool svg,
.btn-workflow svg {
  transition: transform 180ms ease;
  flex-shrink: 0;
}

.btn:hover svg.btn-icon-end,
.btn-workflow:hover svg.btn-icon-end {
  transform: translateX(3px);
}

.btn:hover svg.btn-icon-start,
.btn-workflow:hover svg.btn-icon-start {
  transform: translateX(-2px);
}

/* Disabled & Read-Only States */
.btn:disabled,
.btn[aria-disabled="true"],
.btn-tool:disabled,
.btn-workflow:disabled {
  opacity: 0.55 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
  transform: none !important;
  box-shadow: none !important;
}

/* Button Loading State (Preserves Exact Button Dimensions) */
.btn.is-loading,
.btn-tool.is-loading,
.btn-workflow.is-loading {
  color: transparent !important;
  pointer-events: none !important;
  position: relative;
}

.btn.is-loading::after,
.btn-tool.is-loading::after,
.btn-workflow.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: dtfButtonSpin 600ms linear infinite;
}

.btn-secondary.is-loading::after,
.btn-tool.is-loading::after {
  border-color: rgba(30, 41, 59, 0.2);
  border-top-color: var(--color-primary);
}

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

/* ==========================================================================
   THEME TOGGLE BUTTON COMPONENT
   Compact, tactical sun/moon toggle with smooth rotational transition
   ========================================================================== */
.dash-theme-toggle {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-navy-850);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #FDE047;
  cursor: pointer;
  flex-shrink: 0;
  transition: 
    background-color 180ms ease,
    border-color 180ms ease,
    transform 140ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 180ms ease;
  position: relative;
  overflow: hidden;
}

.dash-theme-toggle:hover {
  background: var(--color-navy-800);
  border-color: rgba(245, 158, 11, 0.6);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.35);
  transform: scale(1.06);
}

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

.dash-theme-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 300ms cubic-bezier(0.16, 1, 0.3, 1), opacity 200ms ease;
}

/* Icon Swap between Light and Dark mode */
:root .dash-theme-toggle .theme-icon-sun {
  display: none;
}
:root .dash-theme-toggle .theme-icon-moon {
  display: block;
  color: #93C5FD;
}

:root[data-theme="dark"] .dash-theme-toggle .theme-icon-moon {
  display: none;
}
:root[data-theme="dark"] .dash-theme-toggle .theme-icon-sun {
  display: block;
  color: #FBBF24;
}

/* ==========================================================================
   PAGE ENTRANCE ANIMATIONS (SECTION 3)
   Subtle, enterprise-grade fade & staggered entrance without layout shift
   ========================================================================== */
.animate-fade-in {
  animation: dtfHeaderFadeIn 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.animate-card-enter {
  animation: dtfCardStagger 480ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes dtfHeaderFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dtfCardStagger {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger Delays for Dashboard KPI Grids & Content Cards */
.stagger-1 { animation-delay: 40ms; }
.stagger-2 { animation-delay: 90ms; }
.stagger-3 { animation-delay: 140ms; }
.stagger-4 { animation-delay: 190ms; }
.stagger-5 { animation-delay: 240ms; }
.stagger-6 { animation-delay: 290ms; }

/* ==========================================================================
   CARD & TABLE MICRO-INTERACTIONS (SECTION 8)
   ========================================================================== */
.is-clickable-card,
a.dash-card,
.dash-card.is-clickable {
  transition: 
    transform 220ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 220ms cubic-bezier(0.16, 1, 0.3, 1),
    border-color 220ms ease;
  cursor: pointer;
}

.is-clickable-card:hover,
a.dash-card:hover,
.dash-card.is-clickable:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-plate);
  border-color: var(--color-border-hover);
}

.is-clickable-card:active,
a.dash-card:active,
.dash-card.is-clickable:active {
  transform: translateY(-1px);
}

/* Table Row Subtle Hover Transition */
tbody tr {
  transition: background-color 140ms ease;
}

tbody tr:hover {
  background-color: var(--color-surface-subtle);
}

/* ==========================================================================
   PREMIUM ANIMATED SNACKBAR / TOAST SYSTEM (SECTION 6)
   Unified, accessible notifications replacing disruptive browser alerts
   ========================================================================== */
#dtfToastContainer {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 420px;
  width: calc(100vw - 48px);
  pointer-events: none;
}

@media (max-width: 767px) {
  #dtfToastContainer {
    top: 14px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: 100%;
  }
}

.dtf-toast {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow: hidden;
  animation: dtfToastEnter 320ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: transform 200ms ease, opacity 200ms ease;
}

.dtf-toast.is-leaving {
  animation: dtfToastLeave 220ms cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes dtfToastEnter {
  from {
    opacity: 0;
    transform: translateX(18px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes dtfToastLeave {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateX(20px) scale(0.95);
  }
}

/* Toast Type Accents */
.dtf-toast--success {
  border-left-color: var(--color-success);
}
.dtf-toast--success .dtf-toast-icon {
  color: var(--color-success);
  background: var(--color-success-bg);
}

.dtf-toast--error {
  border-left-color: var(--color-error);
}
.dtf-toast--error .dtf-toast-icon {
  color: var(--color-error);
  background: var(--color-error-bg);
}

.dtf-toast--warning {
  border-left-color: var(--color-warning);
}
.dtf-toast--warning .dtf-toast-icon {
  color: var(--color-warning);
  background: var(--color-warning-bg);
}

.dtf-toast--info {
  border-left-color: var(--color-info);
}
.dtf-toast--info .dtf-toast-icon {
  color: var(--color-info);
  background: var(--color-info-bg);
}

.dtf-toast-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dtf-toast-icon svg {
  width: 18px;
  height: 18px;
}

.dtf-toast-content {
  flex: 1;
  min-width: 0;
}

.dtf-toast-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-main);
  line-height: 1.3;
  margin-bottom: 2px;
}

.dtf-toast-message {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  line-height: 1.45;
  word-break: break-word;
}

.dtf-toast-close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px;
  margin: -4px -4px 0 0;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms ease, background-color 150ms ease;
  flex-shrink: 0;
}

.dtf-toast-close:hover {
  color: var(--color-text-main);
  background-color: var(--color-surface-subtle);
}

.dtf-toast-close:focus-visible {
  outline: 2px solid var(--color-primary);
}

.dtf-toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  width: 100%;
  background-color: currentColor;
  opacity: 0.35;
  transform-origin: left;
  animation: dtfToastProgress linear forwards;
}

.dtf-toast:hover .dtf-toast-progress,
.dtf-toast:focus-within .dtf-toast-progress {
  animation-play-state: paused !important;
}

@keyframes dtfToastProgress {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* ==========================================================================
   ACCESSIBLE CONFIRMATION MODAL (SECTION 6 & 10)
   Tactile accessible dialog for irreversible or confirmational decisions
   ========================================================================== */
#dtfConfirmOverlay {
  position: fixed;
  inset: 0;
  background-color: rgba(8, 21, 40, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

#dtfConfirmOverlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

#dtfConfirmDialog {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-portal);
  width: 100%;
  max-width: 460px;
  padding: 24px;
  transform: scale(0.96) translateY(8px);
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

#dtfConfirmOverlay.is-active #dtfConfirmDialog {
  transform: scale(1) translateY(0);
}

.dtf-confirm-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.dtf-confirm-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dtf-confirm-icon--warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.dtf-confirm-icon--danger {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.dtf-confirm-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-main);
  line-height: 1.3;
}

.dtf-confirm-body {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.dtf-confirm-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Media query for reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
