/* === BASE RESET & TOKENS === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root, [data-theme="light"] {
  --font-body: 'General Sans', 'Helvetica Neue', sans-serif;
  --font-display: 'Cabinet Grotesk', 'Helvetica Neue', sans-serif;

  /* Blue-gray palette for German business software */
  --color-bg: #F4F5F7;
  --color-surface: #FFFFFF;
  --color-surface-2: #F8F9FB;
  --color-surface-offset: #EEF0F4;
  --color-border: #D1D5DB;
  --color-divider: #E5E7EB;

  --color-text: #1F2937;
  --color-text-muted: #6B7280;
  --color-text-faint: #9CA3AF;

  --color-primary: #2563EB;
  --color-primary-hover: #1D4ED8;
  --color-primary-active: #1E40AF;
  --color-primary-light: #DBEAFE;
  --color-primary-lighter: #EFF6FF;

  --color-success: #16A34A;
  --color-success-bg: #F0FDF4;
  --color-warning: #D97706;
  --color-warning-bg: #FFFBEB;
  --color-error: #DC2626;
  --color-error-bg: #FEF2F2;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);

  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  --color-bg: #111318;
  --color-surface: #1A1D24;
  --color-surface-2: #21242C;
  --color-surface-offset: #15171D;
  --color-border: #2E3340;
  --color-divider: #252A35;

  --color-text: #D1D5DB;
  --color-text-muted: #9CA3AF;
  --color-text-faint: #6B7280;

  --color-primary: #60A5FA;
  --color-primary-hover: #93C5FD;
  --color-primary-active: #3B82F6;
  --color-primary-light: rgba(96,165,250,0.15);
  --color-primary-lighter: rgba(96,165,250,0.08);

  --color-success: #4ADE80;
  --color-success-bg: rgba(74,222,128,0.1);
  --color-warning: #FBBF24;
  --color-warning-bg: rgba(251,191,36,0.1);
  --color-error: #F87171;
  --color-error-bg: rgba(248,113,113,0.1);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  font-size: 15px;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  min-height: 100dvh;
}

/* === LAYOUT === */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.app-logo svg {
  flex-shrink: 0;
  color: var(--color-primary);
}

.app-logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.app-logo-sub {
  font-size: 11px;
  color: var(--color-text-faint);
  font-weight: 400;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-divider {
  width: 1px;
  height: 24px;
  background: var(--color-divider);
  margin: 0 4px;
}

.pw-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pw-input {
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  width: 110px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.pw-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.pw-input.pw-success {
  border-color: var(--color-success);
  background: var(--color-success-bg);
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-icon:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.btn-icon.unlocked {
  background: var(--color-success-bg);
  border-color: var(--color-success);
  color: var(--color-success);
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 80px;
}

/* === SECTION HEADER WITH BADGE === */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.section-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.section-header .card-title {
  margin-bottom: 0;
}

.section-header .lock-icon {
  color: var(--color-text-faint);
  flex-shrink: 0;
}

/* === INFO BANNER === */
.info-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #92400e;
}
[data-theme="dark"] .info-banner {
  background: #451a0340;
  border-color: #b4540060;
  color: #fbbf24;
}
.info-banner p { margin: 0; }
.icon-info { margin-right: 4px; }

/* === CARD === */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

/* === FORM ELEMENTS === */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.01em;
}

input[type="number"],
input[type="text"],
input[type="password"],
select {
  height: 36px;
  padding: 0 10px;
  font-size: 14px;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

input[type="number"]:focus,
input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.readonly-field {
  background: var(--color-surface-2) !important;
  color: var(--color-primary) !important;
  font-weight: 600;
  cursor: default;
}

.input-suffix {
  position: relative;
}
.input-suffix input {
  padding-right: 50px;
}
.input-suffix .suffix {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--color-text-faint);
  pointer-events: none;
}

.form-note {
  font-size: 11px;
  color: var(--color-text-faint);
  margin-top: 2px;
}

/* Radio group */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.radio-pill {
  display: flex;
  align-items: center;
}

.radio-pill input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.radio-pill label {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  color: var(--color-text-muted);
  background: var(--color-surface);
  white-space: nowrap;
}

.radio-pill input:checked + label {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.radio-pill input:focus-visible + label {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.radio-pill label:hover {
  border-color: var(--color-primary);
  color: var(--color-text);
}

/* === RESULTS TABLE === */
.result-table-wrap {
  overflow-x: auto;
  margin-top: 4px;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums lining-nums;
}

.result-table th,
.result-table td {
  padding: 8px 12px;
  text-align: right;
  border-bottom: 1px solid var(--color-divider);
}

.result-table th {
  font-weight: 600;
  font-size: 12px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--color-surface-2);
  position: sticky;
  top: 0;
}

.result-table th:first-child,
.result-table td:first-child {
  text-align: left;
  font-weight: 500;
  color: var(--color-text);
}

.result-table td {
  color: var(--color-text);
}

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

.result-table .row-highlight {
  background: var(--color-primary-lighter);
  font-weight: 600;
}

.result-table .row-highlight td {
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
}

.result-table .row-total {
  font-weight: 700;
}

.result-table .row-total td {
  border-top: 2px solid var(--color-text);
  border-bottom: none;
  padding-top: 10px;
}

.diff-positive {
  color: var(--color-success) !important;
  font-weight: 600;
}
.diff-negative {
  color: var(--color-error) !important;
  font-weight: 600;
}
.diff-neutral {
  color: var(--color-warning) !important;
  font-weight: 600;
}

/* === TRAFFIC LIGHT === */
.traffic-light {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
}
.traffic-light.green {
  background: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid var(--color-success);
}
.traffic-light.yellow {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid var(--color-warning);
}
.traffic-light.red {
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-body);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-surface-offset);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* === RESULT NOTE === */
.result-note {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  font-size: 12.5px;
  color: var(--color-text-muted);
  border-left: 3px solid var(--color-primary);
  line-height: 1.7;
}

/* === TOGGLE SWITCH === */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}
.toggle-row .toggle-label {
  font-size: 13px;
  color: var(--color-text);
  font-weight: 500;
  user-select: none;
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--color-border);
  border-radius: 24px;
  transition: background var(--transition);
}
.toggle-switch .slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--color-surface);
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}
.toggle-switch input:checked + .slider {
  background: var(--color-primary);
}
.toggle-switch input:checked + .slider::before {
  transform: translateX(18px);
}
.toggle-switch input:focus-visible + .slider {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* === AG SECTION TITLE === */
.ag-section-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  margin-top: 20px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--color-divider);
}
.ag-section-title:first-of-type {
  margin-top: 0;
}

/* === RESERVE BOX === */
.reserve-box {
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.7;
  border: 1px solid;
}
.reserve-box.positive {
  background: var(--color-success-bg);
  border-color: var(--color-success);
  color: var(--color-text);
}
.reserve-box.negative {
  background: var(--color-error-bg);
  border-color: var(--color-error);
  color: var(--color-text);
}
.reserve-box strong {
  font-weight: 700;
}

/* === HIDDEN AG SECTIONS === */
.ag-section.hidden {
  display: none;
}
.ag-section.visible {
  display: block;
  animation: slideIn 300ms ease;
}

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

/* === FOOTER === */
.app-footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-divider);
  margin-top: 32px;
}
.app-footer a {
  color: var(--color-text-muted);
  text-decoration: none;
}
.app-footer a:hover {
  color: var(--color-primary);
}

/* === PRINT === */
@media print {
  .app-header { 
    position: static;
    border-bottom: 2px solid #333;
  }
  .header-actions { display: none !important; }
  .pw-group { display: none !important; }
  .btn, button { display: none !important; }
  
  body { 
    background: #fff; 
    color: #000; 
    font-size: 11px; 
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  
  .app-container { 
    max-width: 100%; 
    padding: 0 16px; 
  }
  
  .card { 
    break-inside: avoid; 
    border: 1px solid #ccc; 
    box-shadow: none;
    margin-bottom: 12px;
    page-break-inside: avoid;
  }
  
  .ag-section.hidden { 
    display: none !important; 
  }
  .ag-section.visible { 
    display: block !important; 
  }
  
  .result-table th { background: #f0f0f0; }
  
  .section-badge {
    background: #333;
    color: #fff;
  }
  
  .traffic-light,
  .reserve-box {
    break-inside: avoid;
  }
  
  .radio-pill label { border: 1px solid #ccc; }
  .radio-pill input:checked + label { 
    background: #333; 
    color: #fff; 
    border-color: #333; 
  }
  
  .toggle-switch { display: none; }
  .toggle-label::before { content: '→ '; }
  
  .app-footer {
    border-top: 1px solid #ccc;
    margin-top: 16px;
    padding: 12px;
    page-break-inside: avoid;
  }
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  html { font-size: 14px; }
  .app-container { padding: 12px 14px 60px; }
  .app-header { 
    padding: 10px 14px; 
    flex-wrap: wrap;
    gap: 8px;
  }
  .header-actions {
    gap: 6px;
  }
  .header-divider { display: none; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .app-logo-text { font-size: 15px; }
  .pw-input { width: 90px; }
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .radio-group { flex-direction: column; }
  .app-logo-sub { display: none; }
}
