:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --line: #d7dde4;
  --text: #1f2933;
  --muted: #667383;
  --accent: #176b87;
  --accent-strong: #0f4f64;
  --good: #1f8a5b;
  --warn: #a55c00;
  --bad: #b42318;
  --shadow: 0 16px 42px rgba(27, 43, 58, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body.locked .sidebar,
body.locked .app {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  background: rgba(15, 28, 36, 0.54);
  padding: 20px;
}

body.locked .login-screen {
  display: grid;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--text);
  margin-bottom: 6px;
}

.login-brand p {
  color: var(--muted);
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--bad);
  font-size: 13px;
}

button,
input,
select {
  font: inherit;
}

button {
  height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: #dfe7ed;
  color: var(--text);
}

input:disabled,
select:disabled {
  background: #eef3f7;
  color: #7b8794;
  cursor: not-allowed;
}

textarea {
  width: 100%;
  min-height: 118px;
  border: 1px solid #cbd5df;
  border-radius: 7px;
  padding: 10px;
  color: var(--text);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  resize: vertical;
}

button.secondary:hover {
  background: #ccd8e0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #17242c;
  color: #fff;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e6f4f1;
  color: #135b62;
  font-size: 24px;
  font-weight: 800;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  color: #b8c6ce;
  font-size: 13px;
  margin-top: 3px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-btn {
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: #dce5ea;
  border: 1px solid transparent;
}

.nav-btn:hover,
.nav-btn.active {
  background: #243944;
  border-color: #375461;
}

.role-box {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: #cbd8df;
  font-size: 13px;
}

.role-box strong {
  color: #fff;
  font-size: 15px;
}

.role-box button {
  width: 100%;
}

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

.topbar,
.filters,
.panel,
.kpis article {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(21, 36, 48, 0.04);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 8px;
}

.topbar h2,
.topbar p {
  margin: 0;
}

.topbar h2 {
  font-size: 24px;
}

.topbar p,
.panel-head span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  padding: 14px;
  margin: 16px 0;
  border-radius: 8px;
}

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

input,
select {
  min-width: 0;
  height: 38px;
  border: 1px solid #cbd5df;
  border-radius: 7px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

.mobile-app {
  display: none;
}

body.mobile-mode {
  display: block;
  background: #f4f6f8;
}

body.mobile-mode .sidebar,
body.mobile-mode .app {
  display: none;
}

body.mobile-mode .mobile-app {
  display: grid;
  gap: 14px;
  max-width: 560px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px;
}

.mobile-head,
.mobile-form,
.mobile-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.mobile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.mobile-head h2,
.mobile-head p,
.mobile-list h3 {
  margin: 0;
}

.mobile-head p {
  color: var(--muted);
  margin-top: 3px;
  font-size: 13px;
}

.mobile-form {
  display: grid;
  gap: 12px;
}

.mobile-form textarea {
  min-height: 86px;
  font-family: inherit;
}

.mobile-list {
  display: grid;
  gap: 10px;
}

.expense-item {
  display: grid;
  gap: 5px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.expense-item:first-of-type {
  border-top: 0;
}

.expense-item strong {
  font-size: 16px;
}

.expense-item span {
  color: var(--muted);
  font-size: 13px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
}

.kpis article {
  min-height: 96px;
  border-radius: 8px;
  padding: 16px;
}

.kpis span {
  color: var(--muted);
  font-size: 13px;
}

.kpis strong {
  display: block;
  margin-top: 10px;
  font-size: 24px;
  line-height: 1.1;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 16px;
}

.panel {
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

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

.panel h3,
.panel-head h3 {
  margin: 0;
  font-size: 17px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  font-size: 14px;
}

th {
  background: var(--surface-soft);
  color: #41515f;
  font-weight: 700;
}

th.sortable-column {
  padding: 0;
}

.table-sort {
  display: flex;
  width: 100%;
  height: auto;
  min-height: 40px;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  border-radius: 0;
  padding: 10px 12px;
  background: transparent;
  color: #41515f;
  font-weight: 700;
  text-align: left;
}

.table-sort:hover {
  background: #e3ebf0;
  color: var(--text);
}

.sort-indicator {
  color: #8896a3;
  font-size: 13px;
  font-weight: 700;
}

.table-sort.active {
  color: var(--accent);
}

.table-sort.active .sort-indicator {
  color: var(--accent);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.num {
  text-align: right;
}

.profit {
  color: var(--good);
  font-weight: 700;
}

.loss {
  color: var(--bad);
  font-weight: 700;
}

.bars {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #dfe7ed;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.form-grid {
  display: grid;
  gap: 16px;
}

.form-grid.three {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

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

.form-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.wide-form {
  gap: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.form-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.row-actions button {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

button.danger {
  background: #b42318;
}

button.danger:hover {
  background: #8f1d14;
}

.import-panel {
  display: grid;
  gap: 12px;
}

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

.file-label {
  width: fit-content;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  padding: 0 12px;
  background: #eef3f7;
  color: var(--text);
  cursor: pointer;
}

.file-label input {
  display: none;
}

.import-result {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.import-result.ok {
  color: var(--good);
}

.import-result.err {
  color: var(--bad);
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #e7f1ed;
  color: #1f6b52;
  font-size: 12px;
  font-weight: 700;
}

.tag.clothing {
  background: #fff0e6;
  color: #985000;
}

@media (max-width: 1100px) {
  body {
    grid-template-columns: 1fr;
  }

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

  .nav,
  .filters,
  .kpis,
  .split,
  .form-grid.three,
  .form-grid.two,
  .form-row {
    grid-template-columns: 1fr;
  }
}
