/* ============================================================
   Kreditrechner – Main Stylesheet
   Clean, professional finance-app look. No external deps.
   ============================================================ */

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

:root {
  --clr-primary:      #1a56db;
  --clr-primary-dark: #1340b0;
  --clr-primary-light:#dbeafe;
  --clr-accent:       #0ea5e9;
  --clr-success:      #16a34a;
  --clr-danger:       #dc2626;
  --clr-warn:         #d97706;

  --clr-bg:           #f1f5f9;
  --clr-surface:      #ffffff;
  --clr-surface2:     #f8fafc;
  --clr-border:       #e2e8f0;
  --clr-border2:      #cbd5e1;

  --clr-text:         #0f172a;
  --clr-text2:        #475569;
  --clr-text3:        #94a3b8;

  --clr-sidebar-bg:   #1e293b;
  --clr-sidebar-text: #e2e8f0;
  --clr-sidebar-muted:#94a3b8;
  --clr-sidebar-item: #334155;
  --clr-sidebar-hover:#2d4a6e;
  --clr-sidebar-active:#1a56db;

  --radius-sm:  4px;
  --radius:     8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 24px rgba(0,0,0,.1), 0 4px 8px rgba(0,0,0,.06);

  --sidebar-w: 300px;
  --header-h:  60px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--clr-bg);
  color: var(--clr-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--clr-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app-header {
  height: var(--header-h);
  background: var(--clr-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-left { display: flex; align-items: center; gap: .75rem; }
.header-logo {
  width: 34px; height: 34px;
  background: rgba(255,255,255,.2);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 700;
}
.header-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -.3px; }
.header-subtitle { font-size: .78rem; opacity: .8; }

.header-right { display: flex; align-items: center; gap: .5rem; }

.btn-lang, .btn-sidebar-toggle {
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  padding: .35rem .8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-lang:hover, .btn-sidebar-toggle:hover { background: rgba(255,255,255,.3); }
.btn-sidebar-toggle { display: none; }

/* Wrapper */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - var(--header-h));
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--clr-sidebar-bg);
  color: var(--clr-sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: transform .25s ease;
  z-index: 50;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid #2d3f55;
}
.sidebar-tab {
  flex: 1;
  padding: .7rem .5rem;
  background: none;
  border: none;
  color: var(--clr-sidebar-muted);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  transition: color .15s, background .15s;
  border-bottom: 2px solid transparent;
}
.sidebar-tab.active {
  color: var(--clr-sidebar-text);
  border-bottom-color: var(--clr-primary);
}
.sidebar-tab:hover { background: rgba(255,255,255,.05); }

.sidebar-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.sidebar-panel.active { display: flex; }

.sidebar-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid #2d3f55;
}
.sidebar-panel-header h3 { font-size: .85rem; font-weight: 600; }

.btn-clear {
  background: none;
  border: 1px solid #4a5568;
  color: var(--clr-sidebar-muted);
  padding: .25rem .6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .75rem;
  transition: all .15s;
}
.btn-clear:hover { border-color: var(--clr-danger); color: var(--clr-danger); }

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: .5rem;
}
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: #3d5068; border-radius: 2px; }

.sidebar-empty {
  padding: 1.5rem 1rem;
  color: var(--clr-sidebar-muted);
  font-size: .82rem;
  text-align: center;
}

/* History item */
.history-item {
  background: var(--clr-sidebar-item);
  border-radius: var(--radius);
  padding: .65rem .75rem;
  margin-bottom: .4rem;
  cursor: pointer;
  transition: background .15s;
  border: 1px solid transparent;
  position: relative;
}
.history-item:hover { background: #3a5068; }
.history-item.current { border-color: var(--clr-primary); }

.history-item-name {
  font-size: .82rem;
  font-weight: 600;
  margin-bottom: .2rem;
  padding-right: 1.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item-meta {
  font-size: .74rem;
  color: var(--clr-sidebar-muted);
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
}
.history-item-meta span { white-space: nowrap; }

.history-item-actions {
  position: absolute;
  top: .4rem; right: .4rem;
  display: flex;
  gap: .25rem;
  opacity: 0;
  transition: opacity .15s;
}
.history-item-actions.always-visible {
  opacity: 1;
}
.history-item:hover .history-item-actions { opacity: 1; }
.history-item-actions button {
  background: none;
  border: none;
  color: var(--clr-sidebar-muted);
  cursor: pointer;
  padding: .15rem .3rem;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  transition: color .15s, background .15s;
}
.history-item-actions button:hover { color: #fff; background: #4a5568; }
.history-item-actions button.btn-delete:hover { color: var(--clr-danger); }
.history-item-actions button.btn-compare-toggle.in-compare {
  color: var(--clr-accent);
}

/* Compare list in sidebar */
.compare-item {
  background: var(--clr-sidebar-item);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  margin-bottom: .4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .82rem;
}
.compare-item-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compare-item button {
  background: none; border: none;
  color: var(--clr-sidebar-muted); cursor: pointer;
  font-size: .9rem; padding: .1rem .3rem;
  border-radius: var(--radius-sm);
}
.compare-item button:hover { color: var(--clr-danger); }

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  margin-top: 2rem;
}

.footer-link {
  font-size: .82rem;
  color: var(--clr-primary);
  text-decoration: none;
  transition: opacity .15s;
}

.footer-link:hover {
  opacity: .7;
  text-decoration: underline;
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  margin-top: 2rem;
}

.footer-link {
  font-size: .82rem;
  color: var(--clr-primary);
  text-decoration: none;
  transition: opacity .15s;
  cursor: pointer;
}

.footer-link:hover {
  opacity: .7;
  text-decoration: underline;
}

/* ---------- Dialog (Impressum) ---------- */
dialog.impressum-dialog {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--clr-surface);
  color: var(--clr-text);
  padding: 0;
}

dialog.impressum-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-close-wrapper {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: flex-end;
  padding: 1rem;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  z-index: 1;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--clr-text3);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: background .15s, color .15s;
  line-height: 1;
}

.modal-close:hover {
  background: var(--clr-bg);
  color: var(--clr-text);
}

dialog.impressum-dialog .modal-content {
  padding: 1.5rem;
  line-height: 1.6;
}

dialog.impressum-dialog h2 {
  font-size: 1.5rem;
  margin: 0 0 1.5rem 0;
  color: var(--clr-primary);
  font-weight: 700;
}

dialog.impressum-dialog h3 {
  font-size: 1rem;
  margin: 1.5rem 0 .75rem 0;
  color: var(--clr-primary);
  font-weight: 700;
}

dialog.impressum-dialog h3:first-of-type {
  margin-top: 0;
}

dialog.impressum-dialog p {
  margin: .5rem 0;
  font-size: .9rem;
  color: var(--clr-text);
}

dialog.impressum-dialog a {
  color: var(--clr-primary);
  text-decoration: none;
}

dialog.impressum-dialog a:hover {
  text-decoration: underline;
}

/* ---------- Main content adjustment ---------- */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---------- Card ---------- */
.card {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
  overflow: hidden;
}
.card-header {
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.card-header h2 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.card-icon {
  width: 30px; height: 30px;
  background: var(--clr-primary-light);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--clr-primary);
  font-size: .9rem;
}
.card-body { padding: 1.25rem; }

/* ---------- Form ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full-width { grid-column: 1 / -1; }

label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--clr-text2);
  letter-spacing: .2px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.input-suffix {
  position: absolute;
  right: .75rem;
  color: var(--clr-text3);
  font-size: .85rem;
  pointer-events: none;
  font-weight: 600;
}

input[type="number"], input[type="date"], select {
  width: 100%;
  padding: .55rem .75rem;
  border: 1.5px solid var(--clr-border2);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  background: var(--clr-surface);
  color: var(--clr-text);
  transition: border-color .15s, box-shadow .15s;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
input[type="number"]:focus, input[type="date"]:focus, select:focus {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
input.has-suffix { padding-right: 2.5rem; }

select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2.5rem; }

/* Mode selector */
.mode-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin-bottom: .25rem;
}
.mode-btn {
  padding: .55rem .5rem;
  border: 1.5px solid var(--clr-border2);
  border-radius: var(--radius);
  background: var(--clr-surface);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  color: var(--clr-text2);
  text-align: center;
  transition: all .15s;
  line-height: 1.3;
}
.mode-btn:hover { border-color: var(--clr-primary); color: var(--clr-primary); background: var(--clr-primary-light); }
.mode-btn.active { background: var(--clr-primary); border-color: var(--clr-primary); color: #fff; }

/* Form actions */
.form-actions {
  display: flex;
  gap: .75rem;
  margin-top: .5rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .6rem 1.25rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  border: none;
}
.btn-primary { background: var(--clr-primary); color: #fff; }
.btn-primary:hover { background: var(--clr-primary-dark); box-shadow: var(--shadow); }
.btn-secondary { background: var(--clr-surface2); color: var(--clr-text2); border: 1.5px solid var(--clr-border2); }
.btn-secondary:hover { background: var(--clr-border); }
.btn-sm { padding: .4rem .85rem; font-size: .8rem; }
.btn-icon { padding: .4rem .6rem; }

/* Error banner */
.error-banner {
  display: none;
  padding: .65rem 1rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: var(--clr-danger);
  font-size: .85rem;
  font-weight: 500;
  margin-top: .5rem;
  align-items: center;
  gap: .5rem;
}
.error-banner.visible { display: flex; }

/* ---------- Results Summary ---------- */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.result-tile {
  background: var(--clr-surface2);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  transition: box-shadow .15s;
}
.result-tile:hover { box-shadow: var(--shadow); }
.result-tile.highlight {
  background: var(--clr-primary);
  border-color: var(--clr-primary);
  color: #fff;
}
.result-tile.highlight .tile-label { color: rgba(255,255,255,.75); }
.tile-label { font-size: .75rem; font-weight: 600; color: var(--clr-text3); text-transform: uppercase; letter-spacing: .4px; }
.tile-value { font-size: 1.3rem; font-weight: 800; letter-spacing: -.5px; line-height: 1.2; }
.tile-sub { font-size: .75rem; color: var(--clr-text3); }
.result-tile.highlight .tile-sub { color: rgba(255,255,255,.65); }

/* ---------- Amortization Table ---------- */
.toggle-table-btn {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: none;
  border: 1.5px solid var(--clr-border2);
  border-radius: var(--radius);
  padding: .5rem 1rem;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  color: var(--clr-text2);
  transition: all .15s;
}
.toggle-table-btn:hover { background: var(--clr-primary-light); border-color: var(--clr-primary); color: var(--clr-primary); }

.view-toggle {
  display: flex;
  gap: .35rem;
}
.view-toggle button {
  padding: .3rem .7rem;
  border: 1.5px solid var(--clr-border2);
  border-radius: var(--radius-sm);
  background: var(--clr-surface);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  color: var(--clr-text2);
  transition: all .15s;
}
.view-toggle button.active { background: var(--clr-primary); border-color: var(--clr-primary); color: #fff; }

.table-wrap {
  overflow-x: auto;
  max-height: 420px;
  overflow-y: auto;
  border-radius: var(--radius);
  border: 1px solid var(--clr-border);
}
.table-wrap::-webkit-scrollbar { width: 5px; height: 5px; }
.table-wrap::-webkit-scrollbar-track { background: var(--clr-surface2); }
.table-wrap::-webkit-scrollbar-thumb { background: var(--clr-border2); border-radius: 3px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--clr-sidebar-bg);
  color: var(--clr-sidebar-text);
}
thead th {
  padding: .65rem .75rem;
  text-align: right;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}
thead th:first-child { text-align: left; }
tbody tr { border-bottom: 1px solid var(--clr-border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--clr-primary-light); }
tbody tr.yr-end { background: #f0f9ff; font-weight: 600; }
tbody tr.fixed-end { border-bottom: 2px solid var(--clr-warn); }
tbody td {
  padding: .5rem .75rem;
  text-align: right;
  white-space: nowrap;
  color: var(--clr-text);
}
tbody td:first-child { text-align: left; }
.td-special { color: var(--clr-success); font-weight: 600; }
.td-interest { color: var(--clr-danger); }

/* ---------- Comparison Panel ---------- */
.comparison-panel { display: none; }
.comparison-panel.visible { display: block; }

.comp-table-wrap {
  overflow-x: auto;
}
.comp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
  min-width: 600px;
}
.comp-table thead {
  background: var(--clr-sidebar-bg);
  color: var(--clr-sidebar-text);
}
.comp-table thead th {
  padding: .65rem .9rem;
  text-align: right;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .3px;
}
.comp-table thead th:first-child { text-align: left; }
.comp-table tbody tr { border-bottom: 1px solid var(--clr-border); }
.comp-table tbody tr:hover { background: var(--clr-primary-light); }
.comp-table tbody td {
  padding: .55rem .9rem;
  text-align: right;
}
.comp-table tbody td:first-child { text-align: left; font-weight: 600; }
.comp-table .best { color: var(--clr-success); font-weight: 700; }
.comp-table .worst { color: var(--clr-danger); }
.comp-name-edit {
  background: none; border: none;
  color: inherit; cursor: pointer;
  font-size: .75rem; padding: .1rem .3rem;
  border-radius: var(--radius-sm);
  opacity: .6;
  transition: opacity .15s;
}
.comp-name-edit:hover { opacity: 1; }

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 3rem 1rem;
  color: var(--clr-text3);
}
.empty-icon { font-size: 2.5rem; }
.empty-text { font-size: .9rem; text-align: center; }

/* ---------- Notification / Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: .75rem 1.25rem;
  background: var(--clr-sidebar-bg);
  color: var(--clr-sidebar-text);
  border-radius: var(--radius);
  font-size: .85rem;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: all .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  :root { --sidebar-w: 280px; }
  .mode-selector { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .btn-sidebar-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    height: calc(100vh - var(--header-h));
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: .75rem; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .results-grid { grid-template-columns: 1fr 1fr; }
  .mode-selector { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .results-grid { grid-template-columns: 1fr 1fr; }
  .tile-value { font-size: 1.1rem; }
}

/* ---------- Google AdSense Containers ---------- */
.ad-container {
  margin: 1rem 0;
  padding: 0;
  background-color: transparent;
}

.ad-above-form {
  background-color: transparent;
  margin: 0 0 1rem 0;
}

.sidebar-ad-container {
  margin-top: 1.5rem;
  padding: 0;
  background-color: transparent;
}

.ad-bottom {
  background-color: transparent;
  margin: 1.5rem 0 1rem 0;
}

/* Hide ads on print */
@media print {
  .ad-container, .sidebar-ad-container, .ad-above-form, .ad-bottom {
    display: none !important;
  }
}

/* Responsive ad sizing */
@media (max-width: 768px) {
  .sidebar-ad-container {
    min-height: auto;
    margin-top: 1rem;
  }
}

/* ---------- Print ---------- */
@media print {
  .app-header, .sidebar, .form-actions, .toggle-table-btn, .btn-sidebar-toggle { display: none !important; }
  .app-body { display: block; }
  .main-content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; margin-bottom: 1rem; }
  .table-wrap { max-height: none; overflow: visible; }
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: .5rem; }
.text-right { text-align: right; }
.text-muted { color: var(--clr-text3); }
.fw-bold { font-weight: 700; }
