/* =========================
   THEME TOKENS (LIGHT DEFAULT)
   ========================= */
:root {
  /* Core surfaces */
  --bg: #f4f7f6;
  --surface: #ffffff;
  --muted-surface: #f8f9fa;
  --border: #e9ecef;
  --shadow: rgba(0,0,0,0.1);
  --shadow-strong: rgba(0,0,0,0.15);

  /* Text */
  --text: #333333;
  --text-strong: #2c3e50;
  --text-muted: #6c757d;
  --text-soft: #495057;

  /* Accents */
  --accent: #343a40;
  --on-accent: #ffffff;

  /* Semantic colours */
  --info: #176ba0;
  --info-bg: #e6f1fb;
  --positive: #1b7c3a;
  --positive-bg: #e6f4ea;
  --negative: #c0392b;
  --negative-bg: #fdecea;
  --neutral: #5e5ce6;
  --neutral-bg: #eef0ff;

  /* Cards / widgets */
  --weather-summary-bg: #e9ecef;
}

/* =========================
   DARK THEME OVERRIDES
   ========================= */
:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171a1f;
  --muted-surface: #1b1f25;
  --border: #242a32;
  --shadow: rgba(0,0,0,0.3);
  --shadow-strong: rgba(0,0,0,0.45);

  --text: #d6d9de;
  --text-strong: #e6e9ef;
  --text-muted: #9aa3af;
  --text-soft: #b6beca;

  --accent: #d6dde6;
  --on-accent: #0f1216;

  --info: #69b3ff;
  --info-bg: #132031;
  --positive: #6dd58c;
  --positive-bg: #102418;
  --negative: #ff8f8f;
  --negative-bg: #2b1414;
  --neutral: #a79bff;
  --neutral-bg: #18162b;

  --weather-summary-bg: #21262d;
}

[data-theme="dark"] .loan-table .bg-light-info {
  background-color: rgba(23, 107, 160, 0.15);
}

[data-theme="dark"] .loan-table .bg-light-negative {
  background-color: rgba(192, 57, 43, 0.18);
}

[data-theme="dark"] .loan-table .bg-light-positive {
  background-color: rgba(27, 124, 58, 0.18);
}

/* =========================
   Base & Layout
   ========================= */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
}

.container {
  max-width: 1200px;
  margin: auto;
  padding: 0 1rem;
}

h1.page-title {
  text-align: center;
  color: var(--text-strong);
  margin-bottom: 2rem;
}

.page-subtitle {
  text-align: center;
  font-size: 1.05rem;
  margin-top: -1.25rem;
  margin-bottom: 1.5rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* =========================
   Page Actions
   ========================= */
.page-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.action-group {
  display: flex;
  gap: 1rem;
}

/* =========================
   Dashboard Cards
   ========================= */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  grid-auto-rows: minmax(220px, auto);
}

.module-item {
  position: relative;
  display: flex;
  height: 100%;
  transition: transform 0.2s ease-out;
}

.module-item.editing {
  cursor: grab;
}

.module-item.editing:active {
  cursor: grabbing;
}

.module-item.dragging {
  opacity: 0.45;
  pointer-events: none;
}

.module-drag-handle {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.08);
  color: var(--text-muted);
  cursor: grab;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.module-drag-handle:active {
  cursor: grabbing;
}

.module-drag-handle span {
  pointer-events: none;
  font-size: 1.1rem;
  line-height: 1;
}

.module-item.editing .module-drag-handle {
  display: inline-flex;
}

.module-item.editing .module-drag-handle:hover {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.45);
  color: var(--text);
}

.module-drag-handle:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: 2px;
}

.module-item.module-hidden {
  display: none;
}

.module-card {
  background-color: var(--surface);
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 4px 8px var(--shadow);
  text-decoration: none;
  color: var(--text);
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
  transition: all 0.2s ease-in-out;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 180px;
  width: 100%;
  height: 100%;
}

.module-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px var(--shadow-strong);
}

.module-card .icon {
  font-size: 3rem;
  display: block;
}

.dashboard-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.controls-toggle {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--shadow);
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.controls-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow-strong);
}

.controls-toggle:active {
  transform: translateY(0);
}

.controls-toggle.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 6px 18px var(--shadow-strong);
}

.control-hint {
  margin-right: auto;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.controls-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.module-toggle-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background-color: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 0.85rem 1.1rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 12px var(--shadow);
}

.module-toggle-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.module-toggle-option {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  background-color: var(--muted-surface);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.module-toggle-option input {
  accent-color: var(--accent);
}

/* =========================
   Home Loan Dashboard
   ========================= */

.home-loan-dashboard {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.empty-state-card {
  padding: 2rem;
  border-radius: 12px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
}


.home-loan-topbar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.topbar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.loan-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.loan-actions .icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--shadow);
  color: var(--info);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.loan-actions .icon-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px var(--shadow-strong);
}

.loan-actions .icon-button:active {
  transform: translateY(0);
}

.loan-selector {
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}


.loan-summary-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

.loan-summary-card {
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 1.1rem;
  box-shadow: 0 4px 10px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 120px;
  flex: 1 1 200px;
  max-width: 240px;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.loan-summary-card--info {
  background-color: var(--info-bg);
  color: var(--info);
  border-color: rgba(23, 107, 160, 0.15);
}

.loan-summary-card--positive {
  background-color: var(--positive-bg);
  color: var(--positive);
  border-color: rgba(27, 124, 58, 0.15);
}

.loan-summary-card--negative {
  background-color: var(--negative-bg);
  color: var(--negative);
  border-color: rgba(192, 57, 43, 0.15);
}

.loan-summary-card--neutral {
  background-color: var(--neutral-bg);
  color: var(--neutral);
  border-color: rgba(94, 92, 230, 0.15);
}

.loan-summary-card h3 {
  margin: 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: inherit;
  opacity: 0.8;
}

.loan-summary-card p {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  color: inherit;
}


.loan-summary-card--muted {
  background-color: var(--surface);
  border-color: var(--border);
  color: var(--text-soft);
}

.loan-panels {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: minmax(0, 1fr);
}

.home-loan-dashboard--simulator .loan-panels {
  grid-template-columns: minmax(0, 1fr);
}

@media (max-width: 768px) {
  .loan-summary-card {
    flex: 1 1 calc(50% - 1rem);
    max-width: none;
  }
}

@media (max-width: 420px) {
  .loan-summary-card {
    flex: 1 1 100%;
  }
}

.loan-table .text-positive {
  color: var(--positive);
}

.loan-table .text-negative {
  color: var(--negative);
}

.loan-table .text-info {
  color: var(--info);
}

.loan-table .text-neutral {
  color: var(--neutral);
}

.loan-table .bg-light-info {
  background-color: rgba(23, 107, 160, 0.05);
}

.loan-table .bg-light-negative {
  background-color: rgba(192, 57, 43, 0.05);
}

.loan-table .bg-light-positive {
  background-color: rgba(27, 124, 58, 0.05);
}

.loan-panel {
  background-color: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 1.5rem;
  box-shadow: 0 6px 16px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.panel-header .panel-title {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.panel-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.table-wrapper {
  max-height: 420px;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.loan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.loan-table th,
.loan-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.loan-table th.col-interest,
.loan-table th.col-hipoteka,
.loan-table td.col-interest,
.loan-table td.col-hipoteka {
  text-align: right;
  color: var(--negative);
}

.loan-table th.col-principal,
.loan-table td.col-principal {
  text-align: right;
  color: var(--positive);
}

.loan-table th.col-opening,
.loan-table th.col-balance,
.loan-table td.col-opening,
.loan-table td.col-balance {
  text-align: right;
  color: var(--info);
}

.loan-table th.col-emi,
.loan-table th.col-prepay,
.loan-table td.col-emi,
.loan-table td.col-prepay {
  text-align: right;
  color: var(--neutral);
}

.loan-table th.col-period,
.loan-table td.col-period,
.loan-table th.col-date,
.loan-table td.col-date {
  text-align: left;
  color: var(--text-soft);
}

.loan-table thead {
  background-color: var(--muted-surface);
  position: sticky;
  top: 0;
  z-index: 1;
}

.scenario-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.scenario-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.scenario-label {
  font-weight: 600;
  color: var(--text-muted);
}

.scenario-field-group input {
  max-width: 240px;
}

.profile-source-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.profile-source-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background-color: var(--muted-surface);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.profile-source-toggle label:hover {
  background-color: rgba(23, 107, 160, 0.08);
  border-color: rgba(23, 107, 160, 0.3);
}

.profile-source-toggle input {
  accent-color: var(--accent);
}

.custom-profile-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 1rem;
  background-color: var(--muted-surface);
}

.scenario-collection {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* Modal styling shared by dashboard & simulator */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 12px 28px var(--shadow-strong);
  z-index: 1001;
  width: min(700px, 92vw);
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border);
}

.modal[hidden],
.modal-backdrop[hidden] {
  display: none;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 1.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.collection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.collection-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.scenario-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.scenario-row input,
.scenario-row select {
  flex: 1 1 140px;
  min-width: 130px;
}

.scenario-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.form-feedback {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form-feedback.error {
  color: #dc3545;
}

.scenario-results {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.scenario-summary-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.scenario-summary-grid .label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.scenario-summary-grid .value {
  font-size: 1.1rem;
  font-weight: 600;
}

/* =========================
   Weather Page
   ========================= */
.weather-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem;
  background-color: var(--muted-surface);
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--shadow);
}

.weather-header {
  text-align: center;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 1rem;
}

.weather-header h1 {
  font-size: 2.5rem;
  margin: 0;
  color: var(--accent);
}

.weather-header p {
  font-size: 1.2rem;
  text-transform: capitalize;
  color: var(--text-muted);
}

.weather-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
}

.weather-card {
  background: var(--surface);
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 2px 6px var(--shadow);
}

.weather-card .icon {
  font-size: 2rem;
  display: block;
}

.weather-card h3 {
  margin: 0.5rem 0 0.2rem;
  font-size: 0.8rem;
  font-weight: bold;
  color: var(--text-soft);
  text-transform: uppercase;
}

.weather-card p {
  margin: 0;
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--text-strong);
}

.summary-card {
  grid-column: 1 / -1;
  text-align: left;
  background-color: var(--weather-summary-bg);
  padding: 1.5rem;
  margin-top: 1.5rem;
}

.summary-card h3 {
  font-size: 1rem;
  color: var(--text-strong);
}

.summary-card p {
  font-size: 1rem;
  font-weight: normal;
  color: var(--text-soft);
  line-height: 1.6;
}

/* =========================
   Full Tree Capture / Print
   ========================= */
#file-navigator,
#file-tree-container {
  max-height: none !important;
  overflow: visible !important;
}

.editor-layout { height: auto !important; }

@media print {
  html, body { height: auto !important; }
  .editor-layout { height: auto !important; }
  .navigator-header, #editor-wrapper { display: none !important; }
  #file-navigator, #file-tree-container {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }
  #file-tree-container * { line-height: 1.1; }
}
/* === Theme utility classes for views (Step 2) === */
.text-default { color: var(--text); }
.text-strong  { color: var(--text-strong); }
.text-muted   { color: var(--text-muted); }
.text-soft    { color: var(--text-soft); }

.bg-surface { background-color: var(--surface); }
.bg-muted   { background-color: var(--muted-surface); }

.border-1   { border: 1px solid var(--border); }
.border-2   { border: 2px solid var(--border); }

.shadow-1   { box-shadow: 0 2px 6px var(--shadow); }
.shadow-2   { box-shadow: 0 4px 12px var(--shadow); }

/* =========================
   Homepage (index.ejs) Styles
   ========================= */

/* Hero section now explicitly uses theme variables for background and text */
.hero-section {
  /* Restoring the original vertical and horizontal padding  */
  padding: 4rem 2rem;
  /* Ensure it uses the surface color for better contrast in dark mode */
  background-color: var(--surface); 
  border-radius: 8px; /* Consistent radius */
  margin-bottom: 2rem;
  box-shadow: 0 4px 12px var(--shadow-strong); /* Re-applying strong shadow */
}

/* This targets the h1 in the hero section */
.hero-section h1 {
  color: var(--text-strong);
}

.stat-card-custom {
  /* Using theme variables for a card look */
  padding: 1.5rem; /* Increased padding for more vertical space inside the card */
  border-radius: 8px;
  /* The rest is handled by bg-surface, shadow-1, and border-1 classes in index.ejs */
}

/* Optional: Center the title color for Public Stats */
.container h2.border-bottom {
  color: var(--text-strong);
}
