:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #17211d;
  --muted: #66726d;
  --line: #d9e1dd;
  --accent: #0d7b68;
  --accent-2: #c24d2c;
  --accent-3: #2e5f9e;
  --danger: #b3261e;
  --ok: #127a3a;
  --shadow: 0 18px 45px rgba(25, 36, 32, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

[hidden] {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(13, 123, 104, 0.12), transparent 42%),
    linear-gradient(315deg, rgba(194, 77, 44, 0.12), transparent 40%),
    var(--bg);
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-block.compact {
  margin: 0;
  padding: 22px 18px;
}

.brand-block strong,
.brand-block span {
  display: block;
}

.brand-block span:not(.brand-mark) {
  color: var(--muted);
  font-size: 13px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
}

.brand-mark svg {
  width: 44px;
  height: 44px;
}

.brand-block.compact .brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.brand-block.compact .brand-mark svg {
  width: 34px;
  height: 34px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stack,
.form-panel,
.inline-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: white;
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 123, 104, 0.15);
}

.primary-button,
.ghost-button,
.icon-button,
.nav-list button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: white;
  padding: 0 16px;
}

.ghost-button {
  background: white;
  border-color: var(--line);
  color: var(--text);
  padding: 0 12px;
}

.icon-button {
  width: 42px;
  background: white;
  border-color: var(--line);
  color: var(--text);
}

.danger-button {
  color: var(--danger);
}

.form-message,
.alert {
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fbfcfb;
}

.nav-list {
  display: grid;
  gap: 6px;
  padding: 10px;
  overflow-y: auto;
}

.nav-list button {
  justify-content: flex-start;
  min-height: 44px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
}

.nav-list button.active {
  background: var(--surface-2);
  color: var(--accent);
}

#logoutButton {
  margin: auto 10px 14px;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.month-picker {
  min-width: 180px;
}

.alert {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(179, 38, 30, 0.25);
  border-radius: 8px;
  background: rgba(179, 38, 30, 0.06);
}

.alert.success {
  color: var(--ok);
  border-color: rgba(18, 122, 58, 0.25);
  background: rgba(18, 122, 58, 0.06);
}

.view {
  display: none;
}

.active-view {
  display: grid;
  gap: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.kpi {
  min-height: 118px;
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi strong {
  font-size: 25px;
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.kpi strong.compact-value {
  font-size: 21px;
  letter-spacing: -0.35px;
}

.split-layout,
.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.8fr);
  gap: 18px;
}

.two-column {
  grid-template-columns: 360px minmax(0, 1fr);
}

.wide-form {
  grid-template-columns: 430px minmax(0, 1fr);
}

.tariff-layout {
  grid-template-columns: 390px minmax(0, 1fr);
}

.note-layout {
  grid-template-columns: 470px minmax(0, 1fr);
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 10px 24px rgba(25, 36, 32, 0.05);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 15px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.active-pill {
  color: var(--ok);
  background: rgba(18, 122, 58, 0.1);
}

.warning-pill {
  color: #8b4a09;
  background: #fff2dc;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.notes-table {
  min-width: 1250px;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td:last-child,
th:last-child {
  text-align: right;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.row-actions button {
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

.remember-login {
  grid-template-columns: auto 1fr;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
}

.remember-login input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.performance-list,
.cashflow-list,
.closing-grid {
  display: grid;
  gap: 12px;
}

.performance-item,
.cashflow-item,
.closing-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.performance-top,
.closing-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.meter {
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}

.meter span {
  display: block;
  height: 100%;
  width: var(--value);
  background: var(--accent);
}

.money-positive {
  color: var(--ok);
  font-weight: 900;
}

.money-negative {
  color: var(--danger);
  font-weight: 900;
}

.money-investment {
  color: #2e68a3;
  font-weight: 900;
}

.muted {
  color: var(--muted);
}

.compact-copy {
  margin-top: 4px;
  font-size: 12px;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(220px, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.route-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent-3);
  background: #f3f6fa;
  font-size: 13px;
}

.route-summary strong {
  color: var(--text);
}

.calculation-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: #f8faf9;
}

.calculation-box span {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.calculation-box span:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.calculation-box span:nth-child(-n + 2) {
  border-bottom: 1px solid var(--line);
}

.calculation-box strong {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 15px;
  text-transform: none;
}

.section-band {
  min-width: 0;
}

.integration-band {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 20px;
  border-radius: 8px;
  background: #24332e;
  color: white;
}

.integration-band .muted {
  margin-top: 6px;
  color: #c2d0cb;
}

.integration-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--accent);
}

.import-thumb {
  display: block;
  width: 74px;
  height: 58px;
  overflow: hidden;
  padding: 0;
  border: 1px solid #d7e2de;
  border-radius: 6px;
  background: #f4f8f6;
}

.import-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.manual-import-preview {
  padding: 12px;
  border: 1px solid #b9d9ce;
  border-radius: 7px;
  background: #f2faf7;
}

.manual-import-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.manual-import-preview span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.image-preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.image-preview-toolbar .image-preview-help {
  flex: 1;
  min-width: 150px;
  text-align: left;
}

.image-preview-button {
  width: 100%;
  min-height: 300px;
  max-height: 520px;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 10px;
  border: 1px solid #d7e2de;
  border-radius: 6px;
  background: white;
  cursor: zoom-in;
}

.manual-import-preview img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 490px;
  object-fit: contain;
  border-radius: 5px;
  background: white;
  transition: transform 180ms ease;
}

.image-viewer-dialog {
  width: min(96vw, 1400px);
  height: min(94vh, 1000px);
  max-width: none;
  max-height: none;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: #111715;
  color: white;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

.image-viewer-dialog::backdrop {
  background: rgba(6, 12, 10, 0.82);
  backdrop-filter: blur(3px);
}

.image-viewer-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.image-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  background: #1d2824;
}

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

.image-viewer-actions .icon-button,
.image-viewer-actions .ghost-button {
  color: white;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
}

#imageZoomValue {
  min-width: 54px;
  text-align: center;
  font-weight: 800;
}

.image-viewer-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 28px;
  background:
    linear-gradient(45deg, #18201d 25%, transparent 25%),
    linear-gradient(-45deg, #18201d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #18201d 75%),
    linear-gradient(-45deg, transparent 75%, #18201d 75%),
    #111715;
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.image-viewer-stage img {
  display: block;
  max-width: 92%;
  max-height: calc(94vh - 150px);
  object-fit: contain;
  cursor: zoom-in;
  transform-origin: center;
  transition: transform 160ms ease;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.36);
}

.image-viewer-stage img.zoomed {
  cursor: zoom-out;
}

.image-viewer-help {
  padding: 9px 14px;
  color: #c4d0cb;
  background: #1d2824;
  font-size: 12px;
  text-align: center;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #f7c7ba;
  font-size: 12px;
  font-weight: 800;
}

.status-badge.online {
  color: #b8f3cf;
  background: rgba(62, 190, 112, 0.16);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.chart-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.chart-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.chart-canvas {
  position: relative;
  height: 260px;
}

.summary-card {
  border-top: 3px solid var(--accent-3);
}

.primary-button:hover {
  background: #096656;
}

.ghost-button:hover,
.icon-button:hover,
.row-actions button:hover {
  border-color: #a8b7b0;
  background: var(--surface-2);
}

button:focus-visible {
  outline: 3px solid rgba(46, 95, 158, 0.3);
  outline-offset: 2px;
}

.inline-form {
  grid-template-columns: minmax(220px, 1fr) 160px auto;
  align-items: end;
}

@media (max-width: 1100px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-layout,
  .two-column,
  .wide-form,
  .tariff-layout,
  .note-layout {
    grid-template-columns: 1fr;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    padding: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .inline-form,
  .form-grid,
  .form-grid.two,
  .filter-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .integration-band {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .integration-band .status-badge {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .route-summary,
  .chart-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .manual-import-heading,
  .image-viewer-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .image-viewer-dialog {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .image-viewer-actions {
    justify-content: flex-start;
  }

  .image-preview-button {
    min-height: 240px;
  }

  .image-viewer-stage {
    padding: 14px;
  }
}
