:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #14212b;
  --muted: #63717b;
  --line: #dce4ea;
  --accent: #0a7a63;
  --accent-dark: #075f4d;
  --danger: #b13a3a;
  --positive: #087a4d;
  --negative: #b13a3a;
  font-family: Segoe UI, Aptos, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-wrap: anywhere;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.menu-state,
.mobile-menu-button,
.mobile-menu-backdrop {
  display: none;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 22px 16px;
  background: #17262f;
  color: #e8f0f4;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

.sidebar h1 {
  margin: 4px 0 0;
  font-size: 1.2rem;
}

.sidebar nav {
  display: grid;
  gap: 8px;
  align-content: start;
}

.sidebar a {
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.06);
}

.sidebar a:hover {
  background: rgba(255, 255, 255, 0.14);
}

.nav-tree {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.nav-tree summary {
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}

.nav-tree-links {
  display: grid;
  gap: 2px;
  padding: 0 6px 8px;
}

.nav-tree-links a,
.nav-tree-links span {
  display: block;
  padding: 7px 8px;
  border-radius: 6px;
  text-decoration: none;
  background: transparent;
}

.nav-tree-links a:hover {
  background: rgba(255, 255, 255, 0.12);
}

.nav-main {
  font-weight: 700;
  color: #ffffff;
}

.nav-sub {
  margin-left: 14px;
  color: #c9d8df;
  font-size: 0.93rem;
}

.content {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
  display: grid;
  gap: 16px;
  align-content: start;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card,
.panel,
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.login-card {
  width: min(420px, 100%);
}

.page-head h2,
.panel h3,
.login-card h1 {
  margin: 0 0 10px;
}

.eyebrow,
.muted {
  color: var(--muted);
  margin: 0;
}

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

.metric {
  display: grid;
  gap: 6px;
}

.metric strong {
  font-size: 1.35rem;
}

.metric.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.metric.primary span {
  color: rgba(255, 255, 255, 0.82);
}

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

.form-grid,
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  align-items: end;
}

.wide {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 5px;
  font-weight: 600;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid #cbd6dd;
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  background: #ffffff;
}

textarea {
  resize: vertical;
}

input[type="checkbox"] {
  width: auto;
  padding: 0;
}

.checkbox-line {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.compact-check {
  font-size: 0.92rem;
}

.inline-check-form {
  margin: 0;
}

.inline-check-form input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

button,
.button,
.mobile-menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 10px 13px;
  font: inherit;
  text-decoration: none;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.button:hover,
.mobile-menu-button:hover {
  background: var(--accent-dark);
}

.mobile-menu-button {
  display: none;
}

.secondary {
  background: #e4ebef;
  color: #1f303a;
}

.secondary:hover {
  background: #d5e0e7;
}

.danger {
  background: var(--danger);
}

.compact {
  padding: 7px 9px;
  font-size: 0.9rem;
}

.full {
  width: 100%;
}

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

.section-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.row-actions {
  justify-content: flex-end;
}

.row-actions form {
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 0.86rem;
  color: var(--muted);
}

.right {
  text-align: right;
}

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

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

.alert {
  color: var(--danger);
  font-weight: 700;
}

.position-groups {
  display: grid;
  gap: 12px;
}

.position-group {
  display: grid;
  gap: 12px;
}

.position-group-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.subposition-list {
  display: grid;
  gap: 8px;
}

.subposition-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafb;
}

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

  .mobile-menu-button {
    position: sticky;
    top: 10px;
    left: 10px;
    z-index: 90;
    display: inline-flex;
    width: fit-content;
    margin: 10px 0 0 10px;
    box-shadow: 0 8px 18px rgba(20, 33, 43, 0.18);
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: none;
    background: rgba(0, 0, 0, 0.38);
  }

  .menu-state:checked ~ .mobile-menu-backdrop {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 80;
    width: min(320px, calc(100vw - 48px));
    height: 100vh;
    max-height: 100vh;
    gap: 12px;
    padding: 16px 12px;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 16px 0 34px rgba(0, 0, 0, 0.26);
  }

  .menu-state:checked ~ .sidebar {
    transform: translateX(0);
  }

  .sidebar nav {
    grid-template-columns: 1fr;
  }

  .sidebar nav > a,
  .nav-tree {
    min-width: 0;
  }

  .nav-tree {
    grid-column: 1 / -1;
  }

  .nav-tree-links {
    grid-template-columns: 1fr;
  }

  .content {
    width: min(100% - 20px, 1180px);
    padding-top: 8px;
    gap: 12px;
  }

  .page-head h2 {
    font-size: 1.35rem;
  }

  .panel,
  .metric,
  .login-card {
    padding: 14px;
  }

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

  .form-grid,
  .filter-grid {
    grid-template-columns: 1fr;
  }

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

  .actions,
  .row-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .actions > *,
  .row-actions > *,
  .row-actions form,
  .row-actions button,
  .row-actions .button {
    width: 100%;
  }

  .position-group-head,
  .subposition-row {
    align-items: stretch;
    flex-direction: column;
  }

  table {
    display: grid;
    gap: 10px;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #ffffff;
  }

  td {
    display: grid;
    grid-template-columns: minmax(108px, 38%) 1fr;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid #edf2f5;
    text-align: left;
  }

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

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  td.right {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .sidebar a,
  .nav-tree summary {
    padding: 9px 10px;
  }

  .nav-sub {
    margin-left: 10px;
  }

  .content {
    width: min(100% - 14px, 1180px);
  }

  .panel,
  .metric,
  .login-card {
    padding: 12px;
  }

  td {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
