/* ============================================
   CSS Variables for Theming
   ============================================ */
:root {
  /* Light Theme Colors (HSL) */
  --bg-primary: hsl(0, 0%, 98%);
  --bg-secondary: hsl(0, 0%, 100%);
  --bg-tertiary: hsl(0, 0%, 95%);
  --text-primary: hsl(0, 0%, 10%);
  --text-secondary: hsl(0, 0%, 30%);
  --text-muted: hsl(0, 0%, 50%);
  --border-color: hsl(0, 0%, 85%);
  --accent: hsl(0, 0%, 20%);
  --accent-hover: hsl(0, 0%, 30%);
  --shadow: hsla(0, 0%, 0%, 0.1);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Typography */
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'Courier New', monospace;

  /* Transitions */
  --transition-speed: 0.3s;
}

[data-theme="dark"] {
  --bg-primary: hsl(0, 0%, 10%);
  --bg-secondary: hsl(0, 0%, 15%);
  --bg-tertiary: hsl(0, 0%, 20%);
  --text-primary: hsl(0, 0%, 95%);
  --text-secondary: hsl(0, 0%, 80%);
  --text-muted: hsl(0, 0%, 60%);
  --border-color: hsl(0, 0%, 30%);
  --accent: hsl(0, 0%, 85%);
  --accent-hover: hsl(0, 0%, 75%);
  --shadow: hsla(0, 0%, 0%, 0.3);
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* ============================================
   Layout
   ============================================ */
.app-container {
  display: grid;
  grid-template-columns: 400px 1fr;
  min-height: 100vh;
  gap: 0;
}

@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    display: none;
  }

  .preview-panel.mobile-visible {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: var(--bg-primary);
  }
}

/* ============================================
   Control Panel
   ============================================ */
.control-panel {
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: var(--spacing-lg);
  overflow-y: auto;
  max-height: 100vh;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-xl);
  padding-bottom: var(--spacing-md);
  border-bottom: 2px solid var(--border-color);
}

.panel-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-speed);
  font-size: 1.25rem;
  color: var(--text-primary);
}

.theme-toggle:hover {
  background: var(--accent);
  color: var(--bg-primary);
  transform: scale(1.05);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

[data-theme="light"] .icon-moon {
  display: none;
}

[data-theme="dark"] .icon-sun {
  display: none;
}

/* ============================================
   Input Sections
   ============================================ */
.input-section {
  margin-bottom: var(--spacing-lg);
  padding: var(--spacing-md) var(--spacing-lg);
  background: var(--bg-tertiary);
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.employee-section,
.currency-section {
  padding: var(--spacing-sm) var(--spacing-md);
}

.employee-section .input-group,
.currency-section .input-group {
  margin-bottom: var(--spacing-xs);
}

.employee-section .input-group:last-child,
.currency-section .input-group:last-child {
  margin-bottom: 0;
}

.input-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--spacing-md);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 0.85rem;
}

.total-amount-section {
  border: 2px solid var(--accent);
  background: var(--bg-secondary);
  box-shadow: 0 2px 12px var(--shadow);
}

.total-amount-section h2 {
  color: var(--text-primary);
  font-size: 1rem;
}

.amount-controls {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.input-group label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-field {
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 1rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: all var(--transition-speed);
}

.input-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--shadow);
}

.input-field:disabled,
.input-field:read-only {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

.component-controls select:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

.amount-input {
  font-size: 1.5rem;
  font-weight: 600;
  padding: var(--spacing-md);
}

/* Slider Styles */
.slider-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.slider {
  width: 100%;
  height: 8px;
  border-radius: 5px;
  background: var(--bg-tertiary);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: var(--accent-hover);
}

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.slider::-moz-range-thumb:hover {
  transform: scale(1.2);
  background: var(--accent-hover);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ============================================
   Components List
   ============================================ */
.components-section {
  padding: var(--spacing-md);
}

.components-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.component-item {
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  transition: all 0.2s ease;
}

.component-item:hover {
  border-color: var(--accent);
  box-shadow: 0 1px 4px var(--shadow);
}

.component-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-sm);
}

.component-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  flex-wrap: wrap;
}

.min-badge {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 6px;
  background: var(--accent);
  color: var(--bg-primary);
  border-radius: 4px;
  cursor: help;
}

.component-toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

.component-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: 0.3s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.component-toggle input:checked+.toggle-slider {
  background-color: var(--accent);
}

.component-toggle input:checked+.toggle-slider:before {
  transform: translateX(20px);
}

.component-controls {
  display: flex;
  gap: var(--spacing-sm);
  align-items: stretch;
}

.component-controls select {
  flex: 0 0 120px;
  font-size: 0.85rem;
  padding: var(--spacing-xs) var(--spacing-sm);
  font-weight: 500;
}

.component-controls select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-tertiary);
}

.component-controls input {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  padding: var(--spacing-xs) var(--spacing-md);
  text-align: right;
  font-weight: 600;
}

/* ============================================
   Mobile Preview Button
   ============================================ */
.mobile-preview-btn {
  display: none;
  margin-top: var(--spacing-lg);
  width: 100%;
}

.mobile-close-btn {
  display: none;
  position: fixed;
  top: var(--spacing-md);
  right: var(--spacing-md);
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 101;
  box-shadow: 0 2px 8px var(--shadow);
  transition: all 0.2s;
}

.mobile-close-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px var(--shadow);
}

@media (max-width: 1024px) {
  .mobile-preview-btn {
    display: block;
  }

  .preview-panel.mobile-visible .mobile-close-btn {
    display: block;
  }
}

.btn {
  padding: var(--spacing-md);
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--accent);
  color: var(--bg-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

/* ============================================
   Preview Panel
   ============================================ */
.preview-panel {
  background-color: var(--bg-tertiary);
  padding: var(--spacing-xl);
  padding-bottom: 100px;
  overflow-y: auto;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.preview-container {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: center;
  flex: 1;
}

/* ============================================
   Preview Export Buttons (Sticky)
   ============================================ */
.preview-export-buttons {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 400px;
  background: var(--bg-secondary);
  border-top: 2px solid var(--border-color);
  padding: var(--spacing-md) var(--spacing-xl);
  display: flex;
  gap: var(--spacing-md);
  justify-content: center;
  box-shadow: 0 -4px 12px var(--shadow);
  z-index: 100;
}

.preview-export-buttons .btn {
  min-width: 200px;
}

@media (max-width: 1024px) {
  .preview-export-buttons {
    left: 0;
  }

  .preview-panel.mobile-visible .preview-export-buttons {
    display: flex;
  }
}

/* ============================================
   Annexure Document (Fixed Layout for Export)
   ============================================ */
.annexure-document {
  width: 210mm;
  /* A4 width */
  min-height: 297mm;
  /* A4 height */
  background: white;
  color: black;
  padding: 20mm;
  box-shadow: 0 4px 20px var(--shadow);
  font-size: 11pt;
  line-height: 1.4;
}

.annexure-header {
  text-align: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid black;
}

.annexure-title {
  font-size: 16pt;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: black;
}

.employee-info {
  margin-bottom: 2rem;
  font-size: 11pt;
}

.employee-info p {
  margin-bottom: 0.5rem;
  color: black;
}

/* ============================================
   Salary Tables
   ============================================ */
.salary-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 10pt;
}

.salary-table th,
.salary-table td {
  border: 1px solid #333;
  padding: 0.5rem;
  text-align: left;
  color: black;
}

.salary-table th {
  background-color: #f0f0f0;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 9pt;
}

.component-col {
  width: 50%;
}

.monthly-col,
.yearly-col {
  width: 25%;
  text-align: right;
}

.subtotal-row td {
  font-weight: 700;
  background-color: #f5f5f5;
  border: 1px solid #333;
}

.total-row td {
  font-weight: 700;
  background-color: #e0e0e0;
  font-size: 11pt;
  border: 1px solid #333;
}

/* Export-specific border fix */
@media print,
(-webkit-min-device-pixel-ratio: 0) {
  .salary-table {
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid #333;
  }

  .salary-table th,
  .salary-table td {
    border: 0;
    border-right: 1px solid #333;
    border-bottom: 1px solid #333;
  }

  .salary-table tr th:last-child,
  .salary-table tr td:last-child {
    border-right: 0;
  }

  .salary-table tbody tr:last-child th,
  .salary-table tbody tr:last-child td,
  .salary-table tfoot tr:last-child th,
  .salary-table tfoot tr:last-child td {
    border-bottom: 0;
  }

  .subtotal-row td,
  .total-row td {
    border: 0;
    border-right: 1px solid #333;
    border-bottom: 1px solid #333;
  }

  .subtotal-row td:last-child,
  .total-row td:last-child {
    border-right: 0;
  }
}

.benefits-table {
  margin-top: 1rem;
}

.total-table {
  margin-top: 1rem;
}

.esops-section {
  margin-top: 2rem;
}

.esops-section h3 {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: black;
}

.esops-table {
  margin-top: 0.5rem;
}

/* ============================================
   Footer
   ============================================ */
.annexure-footer {
  margin-top: 2rem;
  font-size: 9pt;
  color: black;
}

.currency-note {
  margin-bottom: 1rem;
  font-style: italic;
  color: black;
}

.footer-notes p {
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: black;
}

.footer-notes ul {
  margin-left: 1.5rem;
  color: black;
}

.footer-notes li {
  margin-bottom: 0.5rem;
  color: black;
}

.info-icon {
  font-size: 0.85em;
  opacity: 0.7;
  cursor: help;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
  .annexure-document {
    width: 100%;
    min-height: auto;
    padding: var(--spacing-lg);
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  body {
    background: white;
  }

  .control-panel {
    display: none;
  }

  .preview-panel {
    padding: 0;
    background: white;
  }

  .annexure-document {
    box-shadow: none;
    width: 100%;
    min-height: auto;
  }
}