@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@500;600;700&family=Prompt:wght@400;500;600;700&family=Sarabun:wght@300;400;500;600&display=swap');

/* ==========================================================================
   Design Tokens & Themes (WCAG AA Compliant Contrast)
   ========================================================================== */
:root,
[data-theme="warm"] {
  --font-heading: 'Prompt', -apple-system, sans-serif;
  --font-body: 'Sarabun', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Palette: Warm Editorial */
  --bg-page: #FAF7F2;
  --bg-surface: #FFFFFF;
  --bg-surface-subtle: #F6F1EA;
  --bg-surface-elevated: #FFFDF9;
  
  --text-primary: #182230;
  --text-secondary: #4A5568;
  --text-muted: #718096;

  --border-subtle: #ECE4D9;
  --border-strong: #D4C7B5;

  /* WCAG AA contrast >= 4.5:1 on light background */
  --accent-primary: #B45309;
  --accent-hover: #92400E;
  --accent-subtle: #FEF3C7;
  --accent-contrast: #FFFFFF;

  --success-primary: #15803D;
  --success-subtle: #DCFCE7;

  --info-primary: #1D4ED8;
  --info-subtle: #DBEAFE;

  --payslip-header-bg: #1E293B;
  --payslip-header-text: #F8FAFC;
  --payslip-total-bg: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
  --payslip-total-num: #F59E0B;

  --shadow-sm: 0 1px 3px rgba(24, 34, 48, 0.05);
  --shadow-md: 0 8px 20px -4px rgba(24, 34, 48, 0.08);
  --shadow-lg: 0 20px 32px -8px rgba(24, 34, 48, 0.12);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
}

[data-theme="nordic"] {
  --bg-page: #F0F4F8;
  --bg-surface: #FFFFFF;
  --bg-surface-subtle: #E2E8F0;
  --bg-surface-elevated: #FFFFFF;
  
  --text-primary: #0F172A;
  --text-secondary: #334155;
  --text-muted: #64748B;

  --border-subtle: #E2E8F0;
  --border-strong: #CBD5E1;

  /* WCAG AA contrast >= 4.5:1 */
  --accent-primary: #047857;
  --accent-hover: #065F46;
  --accent-subtle: #D1FAE5;
  --accent-contrast: #FFFFFF;

  --success-primary: #047857;
  --success-subtle: #D1FAE5;

  --info-primary: #1D4ED8;
  --info-subtle: #DBEAFE;

  --payslip-header-bg: #0F172A;
  --payslip-header-text: #F8FAFC;
  --payslip-total-bg: linear-gradient(135deg, #0F172A 0%, #064E3B 100%);
  --payslip-total-num: #10B981;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px -4px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 36px -8px rgba(15, 23, 42, 0.12);
}

/* ==========================================================================
   Base & Reset
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  transition: background-color 0.25s ease, color 0.25s ease;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.mono-num {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1, "cv01" 1;
}

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* Focus Visible Accessibility */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   Layout Container
   ========================================================================== */
.app-container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px env(safe-area-inset-bottom, 32px) 16px;
}

/* ==========================================================================
   Header & Navbar
   ========================================================================== */
.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 12px;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.brand-title {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.825rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-subtle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 40px;
}

.btn-subtle:hover {
  background: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.theme-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm);
  min-height: 40px;
}

.theme-switch-btn:hover {
  background: var(--bg-surface-subtle);
  transform: translateY(-1px);
}

/* ==========================================================================
   Main Grid Layout
   ========================================================================== */
.main-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.95fr;
  gap: 28px;
  align-items: stretch;
}

.payslip-column {
  align-self: stretch;
  position: relative;
}

@media (max-width: 860px) {
  .main-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

/* ==========================================================================
   Cards & Surfaces
   ========================================================================== */
.panel-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: 24px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.25s ease, background-color 0.25s ease;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.section-label .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent-primary);
  font-size: 0.775rem;
  font-weight: 700;
}

/* ==========================================================================
   Step 1: Modern Styled Dropdown (Select)
   ========================================================================== */
.select-container {
  position: relative;
  display: flex;
  align-items: center;
}

.modern-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-surface-subtle);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 44px 14px 16px;
  outline: none;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 48px;
}

.modern-select:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface-elevated);
}

.modern-select:focus {
  border-color: var(--accent-primary);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.select-arrow {
  position: absolute;
  right: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* ==========================================================================
   Step 2: Salary Input Field & Alert Banner
   ========================================================================== */
.input-wrapper {
  margin-bottom: 22px;
}

.input-container {
  position: relative;
  display: flex;
  align-items: center;
}

.currency-input {
  width: 100%;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-surface-subtle);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 70px 14px 16px;
  outline: none;
  transition: all 0.2s ease;
  min-height: 52px;
}

.currency-input:focus {
  border-color: var(--accent-primary);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.currency-unit {
  position: absolute;
  right: 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

.alert-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: #FFFBEB;
  border: 1px solid #FCD34D;
  color: #B45309;
  font-size: 0.825rem;
  font-weight: 500;
}

.base-status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  font-size: 0.85rem;
}

.badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.775rem;
  font-weight: 600;
}

.badge-tag.upper {
  background: var(--success-subtle);
  color: var(--success-primary);
}

.badge-tag.lower {
  background: var(--info-subtle);
  color: var(--info-primary);
}

/* ==========================================================================
   Step 3: Quick Chips (2.5%, 3.0%, 3.5%) & Slider
   ========================================================================== */
.chips-group {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.chip-btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
}

.chip-btn:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.chip-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--accent-contrast);
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.custom-range {
  flex: 1;
  -webkit-appearance: none;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
}

.custom-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 2px solid #FFFFFF;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.custom-range::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 2px solid #FFFFFF;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.percent-display-box {
  display: flex;
  align-items: center;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  width: 100px;
  min-height: 44px;
}

.percent-input-field {
  width: 60px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: right;
}

.percent-symbol {
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 2px;
}

/* ==========================================================================
   Mode Switcher
   ========================================================================== */
.mode-toggle-bar {
  display: flex;
  background: var(--bg-surface-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-top: 14px;
}

.mode-tab {
  flex: 1;
  padding: 10px 14px;
  border: none;
  background: transparent;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
}

.mode-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.annual-panel {
  display: none;
  margin-top: 14px;
  padding: 16px;
  background: var(--bg-surface-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.annual-panel.active {
  display: block;
}

/* ==========================================================================
   Digital Payslip Card (Sticky on Desktop)
   ========================================================================== */
.payslip-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border-strong);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 24px;
  /* Subtle Guilloche/watermark feel */
  background-image: radial-gradient(var(--border-subtle) 0.75px, transparent 0.75px);
  background-size: 16px 16px;
}

.payslip-header {
  background: var(--payslip-header-bg);
  color: var(--payslip-header-text);
  padding: 20px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.payslip-badge-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.15rem;
}

.payslip-badge-sub {
  font-size: 0.775rem;
  opacity: 0.8;
  margin-top: 2px;
}

.payslip-seal {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.payslip-body {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.payslip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.925rem;
}

.payslip-row .label {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.payslip-row .value {
  font-weight: 600;
  color: var(--text-primary);
}

.highlight-row {
  background: var(--accent-subtle);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border-left: 4px solid var(--accent-primary);
}

.highlight-row .label {
  color: var(--text-primary);
  font-weight: 600;
}

.highlight-row .value {
  color: var(--accent-primary);
  font-size: 1.15rem;
  font-weight: 700;
}

.increment-arrow {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--accent-primary);
}

.payslip-divider {
  border: none;
  border-top: 1px dashed var(--border-strong);
  margin: 4px 0;
}

.payslip-grand-total {
  background: var(--payslip-total-bg);
  color: #FFFFFF;
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

.total-title {
  font-size: 0.825rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.9;
  margin-bottom: 4px;
}

.total-number {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--payslip-total-num);
  line-height: 1.1;
}

.total-unit {
  font-size: 0.8rem;
  opacity: 0.8;
  margin-top: 4px;
}

.annual-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
}

/* ==========================================================================
   Action Buttons
   ========================================================================== */
.actions-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 22px 22px 22px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent-primary);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  min-height: 48px;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-surface-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 48px;
}

.btn-secondary:hover {
  background: var(--bg-surface-elevated);
}

/* ==========================================================================
   Modals (Criteria Table & Image Preview Fallback)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}

.modal-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-strong);
}

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

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.3rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.modal-body {
  padding: 22px;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.6;
}

.table-responsive {
  overflow-x: auto;
  margin-bottom: 16px;
}

.criteria-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.criteria-table th, .criteria-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.criteria-table th {
  background: var(--bg-surface-subtle);
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text-primary);
}

.modal-note {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-surface-subtle);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  line-height: 1.6;
}

.modal-note ul {
  padding-left: 20px;
  margin-top: 6px;
}

/* ==========================================================================
   Toast Notification
   ========================================================================== */
.toast-notice {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1E293B;
  color: #FFFFFF;
  padding: 12px 24px;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 3000;
}

.toast-notice.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
  text-align: center;
  margin-top: 48px;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ==========================================================================
   Responsive & Print Rules
   ========================================================================== */
@media (max-width: 640px) {
  .app-container {
    padding: 16px 12px 80px 12px;
  }
  .brand-title {
    font-size: 1.15rem;
  }
  .btn-label, .btn-text-responsive {
    display: none;
  }
  .btn-subtle, .theme-switch-btn {
    padding: 8px 10px;
  }
  .currency-input {
    font-size: 1.2rem;
  }
  .total-number {
    font-size: 1.85rem;
  }
}

@media print {
  .header-actions, .panel-card, .actions-bar, .toast-notice, .modal-backdrop {
    display: none !important;
  }
  .app-container {
    max-width: 100%;
    padding: 0;
  }
  .main-grid {
    grid-template-columns: 1fr;
  }
  .payslip-card {
    border: 1px solid #000;
    box-shadow: none;
    position: static;
  }
}
