:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --ink: #20242b;
  --muted: #69717d;
  --line: #d9dde4;
  --header: #e9f0f7;
  --manual: #ffd7d7;
  --manual-strong: #ffbcbc;
  --import: #fff5a8;
  --calc: #eef1f5;
  --section: #dfeaf7;
  --summary: #f7ead2;
  --accent: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar > div:first-child {
  min-width: 220px;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #c9d3df;
  border-radius: 6px;
  background: #fff;
  padding: 0;
}

.admin-icon span {
  width: 15px;
  height: 15px;
  display: block;
  border-radius: 4px;
  background:
    linear-gradient(90deg, #2563eb 0 45%, transparent 45% 55%, #2563eb 55%),
    linear-gradient(#2563eb 0 45%, transparent 45% 55%, #2563eb 55%);
  opacity: 0.9;
}

.admin-icon:hover {
  border-color: #2563eb;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

.period-filter {
  display: flex;
  align-items: end;
  gap: 10px;
}

.view-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.view-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.view-tabs button.active {
  background: var(--accent);
  border-color: #1d4ed8;
  color: #fff;
}

.tab-icon {
  width: 15px;
  height: 15px;
  display: inline-block;
  border: 2px solid currentColor;
}

.report-icon {
  border-radius: 3px;
  box-shadow: inset 0 -4px 0 currentColor;
}

.clients-icon {
  border-radius: 50%;
  position: relative;
}

.clients-icon::after {
  content: "";
  position: absolute;
  width: 13px;
  height: 6px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  left: -1px;
  top: 11px;
}

.period-filter label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.period-filter select {
  min-width: 118px;
}

main {
  padding: 18px 24px 28px;
}

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

button {
  border: 1px solid #1d4ed8;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

select, input, textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

.session label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
}

.admin-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-top: 16px;
}

.admin-panel h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr);
  gap: 14px;
}

.admin-grid form {
  display: grid;
  gap: 8px;
  align-content: start;
}

.admin-grid h3 {
  font-size: 15px;
}

textarea {
  min-height: 112px;
  resize: vertical;
}

.hidden {
  display: none;
}

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: calc(100vh - 170px);
}

.chart-panel {
  margin-top: 14px;
  padding: 14px 16px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.chart-head h2 {
  font-size: 17px;
}

.chart-legend {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  width: 24px;
  height: 3px;
  display: inline-block;
  border-radius: 3px;
}

.plan-line {
  background: #64748b;
}

.fact-line {
  background: #2563eb;
}

#yearChart {
  width: 100%;
  height: 280px;
  display: block;
}

.chart-grid {
  stroke: #e3e7ee;
  stroke-width: 1;
}

.chart-axis {
  fill: #66707d;
  font-size: 12px;
}

.chart-axis-line {
  stroke: #cfd6df;
  stroke-width: 1;
}

.plan-path,
.fact-path {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plan-path,
.plan-dot {
  stroke: #64748b;
  fill: #64748b;
}

.fact-path,
.fact-dot {
  stroke: #2563eb;
  fill: #2563eb;
}

table {
  width: 100%;
  min-width: 1280px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

#clientsTable th:first-child,
#clientsTable td:first-child {
  min-width: 320px;
}

.clients-tools {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 4;
}

.clients-tools label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

#clientsTable thead th button {
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font-weight: 700;
}

#clientsTable thead th button::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  vertical-align: middle;
}

#clientsTable thead th button.active-sort[data-dir="asc"]::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid currentColor;
}

#clientsTable thead th button.active-sort[data-dir="desc"]::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid currentColor;
}

#clientsTable th:nth-child(2),
#clientsTable td:nth-child(2) {
  min-width: 220px;
}

#clientsTable tbody th {
  position: static;
  background: #fff;
  text-align: left;
}

#clientsTable thead th {
  top: 49px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
}

th, td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 5px 8px;
  text-align: right;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--header);
  z-index: 2;
  text-align: center;
  font-weight: 700;
}

thead tr:nth-child(2) th {
  top: 27px;
}

thead tr:first-child th:first-child {
  left: 0;
  z-index: 5;
}

tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
  min-width: 260px;
  background: #fff;
}

tbody tr.section th,
tbody tr.section td,
tbody tr.total th,
tbody tr.total td {
  background: var(--section);
  font-weight: 700;
}

tbody tr.summary th,
tbody tr.summary td {
  background: var(--summary);
  font-weight: 400;
}

tbody tr.manager th,
tbody tr.manager td {
  font-weight: 700;
}

tbody tr.summary.level-1 th,
tbody tr.summary.level-1 td {
  font-weight: 700;
}

tbody tr.entry th {
  font-weight: 500;
}

.level-1 th { padding-left: 22px; }
.level-2 th { padding-left: 42px; }

td.manual,
td.import {
  background: transparent;
}

td.calc {
  background: var(--calc);
  color: #3f4650;
}

td.performance-cell {
  color: #1f2933;
}

td.no-plan-performance {
  background: #edf0f3;
  color: #7a828c;
  font-weight: 600;
}

input.cell-input {
  width: 104px;
  padding: 3px 6px;
  text-align: right;
  background: #fff;
  border-color: var(--manual-strong);
}

.readonly {
  color: #5c6470;
}

@media (max-width: 760px) {
  body {
    background: #fff;
  }

  .topbar {
    position: static;
    gap: 12px;
    padding: 12px;
  }

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

  .topbar > div:first-child {
    min-width: 0;
  }

  .brand-title {
    gap: 8px;
  }

  h1 {
    font-size: 20px;
  }

  .topbar p {
    font-size: 14px;
  }

  .view-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .view-tabs button {
    justify-content: center;
    padding: 8px 10px;
  }

  .period-filter {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .period-filter select {
    width: 100%;
    min-width: 0;
  }

  main {
    padding: 10px;
  }

  .toolbar {
    margin-bottom: 8px;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button,
  .admin-grid button {
    width: 100%;
  }

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

  .admin-panel {
    padding: 12px;
    margin-top: 10px;
  }

  .table-wrap {
    border-radius: 6px;
    max-height: none;
  }

  table {
    min-width: 980px;
    font-size: 12px;
  }

  th, td {
    padding: 4px 6px;
  }

  tbody th {
    min-width: 190px;
    max-width: 190px;
    white-space: normal;
  }

  thead th:first-child {
    min-width: 190px;
  }

  .level-1 th { padding-left: 16px; }
  .level-2 th { padding-left: 28px; }

  input.cell-input {
    width: 86px;
    min-height: 26px;
  }

  .chart-panel {
    padding: 12px 10px 8px;
    margin-top: 10px;
  }

  .chart-head {
    align-items: flex-start;
    flex-direction: column;
  }

  #yearChart {
    height: 220px;
  }

  .clients-tools {
    position: static;
    justify-content: stretch;
    padding: 8px;
  }

  .clients-tools label {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .clients-tools select {
    width: 100%;
  }

  #clientsTable thead th {
    top: 0;
  }

  #clientsTable th:first-child,
  #clientsTable td:first-child {
    min-width: 220px;
  }

  #clientsTable th:nth-child(2),
  #clientsTable td:nth-child(2) {
    min-width: 180px;
  }
}

@media (max-width: 420px) {
  .admin-icon {
    width: 26px;
    height: 26px;
  }

  h1 {
    font-size: 18px;
  }

  .view-tabs button,
  button,
  select,
  input,
  textarea {
    font-size: 14px;
  }

  table {
    min-width: 900px;
    font-size: 11px;
  }

  tbody th,
  thead th:first-child {
    min-width: 170px;
    max-width: 170px;
  }
}
