:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-surface-2: #f1f4f8;
  --color-header-bg: #0f1c3f;
  --color-header-text: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-secondary: #64748b;
  --color-text-muted: #94a3b8;
  --color-primary: #10b981;
  --color-primary-hover: #059669;
  --color-danger: #ef4444;
  --color-positive: #16a34a;
  --color-negative: #dc2626;
  --radius: 10px;
  --font: 'Segoe UI', Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font);
  line-height: 1.6;
  padding-bottom: 3rem;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  padding: 1rem;
  background: var(--color-header-bg);
  border-bottom: 1px solid var(--color-header-bg);
  text-align: center;
}
.topbar h1 { font-size: 1.25rem; color: var(--color-header-text); }
.subtitle { color: #b7c0d6; font-size: .875rem; }
.back-link {
  color: #b7c0d6;
  text-decoration: none;
  font-size: .875rem;
}
.back-link:hover { color: var(--color-header-text); }

@media (min-width: 768px) {
  .topbar {
    flex-direction: row;
    justify-content: space-between;
    text-align: initial;
  }
}

/* ===== Buttons ===== */
.btn-primary, .btn-secondary, .btn-ghost {
  border: none;
  border-radius: var(--radius);
  padding: .6rem 1.1rem;
  font-size: .9375rem;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--color-primary); color: #ffffff; font-weight: 600; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface-2); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-border); }
.btn-ghost { background: transparent; color: var(--color-header-text); border: 1px solid #3a4a70; }
.btn-ghost:hover { background: rgba(255,255,255,.08); }
.btn-icon-danger {
  background: transparent; border: none; color: var(--color-danger); cursor: pointer; font-size: .875rem;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  overflow-x: auto;
  gap: .25rem;
  padding: .75rem 1rem 0;
  background: var(--color-header-bg);
  border-bottom: 1px solid var(--color-header-bg);
}
.tab-btn {
  background: transparent;
  border: none;
  color: #b7c0d6;
  padding: .6rem 1rem;
  font-size: .875rem;
  white-space: nowrap;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  font-family: inherit;
}
.tab-btn.active { color: #ffffff; border-bottom-color: var(--color-primary); font-weight: 600; }

/* ===== Layout ===== */
main { max-width: 900px; margin: 0 auto; padding: 1rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(15, 28, 63, .06);
}
.card h2 { font-size: 1.0625rem; margin-bottom: .25rem; color: var(--color-text); }
.hint { color: var(--color-text-muted); font-size: .8125rem; margin-bottom: .875rem; }

/* ===== Form fields ===== */
.field-row {
  display: flex;
  flex-direction: column;
  gap: .375rem;
  margin-bottom: .75rem;
}
.field-row label { font-size: .8125rem; color: var(--color-text-secondary); }
input, select {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
  padding: .6rem .75rem;
  font-size: .9375rem;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--color-primary); }
.hidden { display: none !important; }

/* ===== Dynamic rows (sales periods / opex lines) ===== */
.rows-container { display: flex; flex-direction: column; gap: .75rem; margin-bottom: .875rem; }
.dyn-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: .5rem;
  padding: .75rem;
  background: var(--color-surface-2);
  border-radius: 8px;
  border: 1px solid var(--color-border);
}
.dyn-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .8125rem;
  color: var(--color-text-secondary);
}

@media (min-width: 600px) {
  .dyn-row { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
table th, table td {
  padding: .6rem .75rem;
  text-align: start;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
table th { color: var(--color-text-secondary); font-weight: 600; font-size: .8125rem; }
table tr.total-row td { font-weight: 700; border-top: 2px solid var(--color-border); }
.num-positive { color: var(--color-positive); }
.num-negative { color: var(--color-negative); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-header-bg);
  color: #ffffff;
  padding: .75rem 1.25rem;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}

button + button { margin-inline-start: .5rem; }
