:root {
  --ink: #18201d;
  --muted: #68736e;
  --line: #d9dfdc;
  --surface: #ffffff;
  --surface-soft: #f3f6f4;
  --canvas: #e9eeeb;
  --sidebar: #111715;
  --sidebar-soft: #1b2420;
  --green: #126b49;
  --green-strong: #0c583b;
  --gold: #b67b16;
  --red: #b63434;
  --blue: #26638e;
  --shadow: 0 12px 28px rgba(18, 27, 23, 0.14);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: Tahoma, Arial, sans-serif;
  font-size: 14px;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--sidebar);
}

.login-panel {
  width: min(390px, 100%);
  padding: 34px;
  border: 1px solid #34413c;
  border-radius: 8px;
  background: #18201d;
  box-shadow: var(--shadow);
}

.login-mark {
  display: block;
  width: 78px;
  height: 58px;
  object-fit: contain;
  margin: 0 auto 12px;
}

.login-heading {
  display: grid;
  gap: 5px;
  margin-bottom: 30px;
  text-align: center;
}

.login-heading strong {
  color: #f8faf8;
  font-size: 25px;
}

.login-heading span {
  color: #aeb9b4;
}

label {
  display: grid;
  gap: 7px;
  color: #34413c;
  font-weight: 700;
}

.login-panel label {
  color: #cbd4d0;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c8d0cc;
  border-radius: 6px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(18, 107, 73, 0.12);
}

.login-panel input {
  border-color: #46554f;
  background: #101613;
  color: #fff;
}

.form-error {
  min-height: 22px;
  margin: 8px 0;
  color: #ff9b9b;
  font-size: 13px;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 15px;
  background: transparent;
  color: inherit;
  font-weight: 700;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.button.primary {
  background: var(--green);
  color: #fff;
}

.button.primary:hover {
  background: var(--green-strong);
}

.button.subtle {
  border-color: var(--line);
  background: var(--surface);
}

.button.danger {
  background: var(--red);
  color: #fff;
}

.button.danger-quiet {
  border-color: #e2bcbc;
  color: #922b2b;
}

.button.full {
  width: 100%;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: #dfe6e2;
  border-left: 1px solid #29332f;
}

.brand {
  min-height: 88px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid #2b3531;
}

.brand img {
  width: 48px;
  height: 38px;
  object-fit: contain;
}

.brand div {
  display: grid;
  gap: 4px;
}

.brand strong {
  color: #fff;
  font-size: 18px;
}

.brand span {
  color: #97a49e;
  font-size: 12px;
}

.navigation {
  display: grid;
  gap: 3px;
  padding: 16px 10px;
}

.nav-item {
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-radius: 6px;
  padding: 0 13px;
  background: transparent;
  color: #aeb9b4;
  text-align: right;
  font-weight: 700;
}

.nav-item:hover {
  background: #18211d;
  color: #fff;
}

.nav-item.active {
  background: #20352b;
  color: #fff;
  box-shadow: inset -3px 0 0 #3aa273;
}

.nav-count {
  min-width: 24px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  text-align: center;
  font-size: 11px;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 17px 20px;
  border-top: 1px solid #2b3531;
  color: #aeb9b4;
  font-size: 12px;
}

.health-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--gold);
}

.health-dot.ok {
  background: #35a66f;
  box-shadow: 0 0 0 4px rgba(53, 166, 111, 0.13);
}

.health-dot.bad {
  background: var(--red);
}

.main {
  min-width: 0;
  padding: 0 28px 40px;
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid #d0d7d3;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

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

.admin-identity {
  min-width: 116px;
  display: grid;
  gap: 3px;
  padding: 0 8px;
}

.admin-identity span {
  color: var(--muted);
  direction: ltr;
  font-size: 12px;
  text-align: right;
}

.loading-line {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 230px;
  left: 0;
  height: 3px;
  overflow: hidden;
  background: #d6ded9;
}

.loading-line::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 100%;
  background: var(--green);
  animation: loading 900ms ease-in-out infinite;
}

@keyframes loading {
  from {
    right: -30%;
  }
  to {
    right: 100%;
  }
}

.view {
  display: none;
  padding-top: 24px;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.metric {
  min-height: 118px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(20, 30, 25, 0.04);
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric strong {
  color: var(--green-strong);
  font-size: 27px;
}

.metric.alert strong {
  color: var(--red);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
}

.data-section,
.settings-form {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.settings-form + .settings-form {
  margin-top: 16px;
}

.section-heading {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2 {
  margin: 0 0 5px;
  font-size: 16px;
}

.section-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 700;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  height: 52px;
  padding: 9px 14px;
  border-bottom: 1px solid #e7ebe9;
  text-align: right;
  vertical-align: middle;
}

th {
  background: #f7f9f8;
  color: #55615b;
  font-size: 12px;
}

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

tbody tr:hover td {
  background: #fafcfb;
}

.compact th,
.compact td {
  height: 46px;
}

.empty-row td {
  height: 120px;
  color: var(--muted);
  text-align: center;
}

.user-cell {
  display: grid;
  gap: 4px;
  white-space: normal;
}

.user-cell small,
.subtle-text {
  color: var(--muted);
  font-size: 11px;
}

.ltr {
  direction: ltr;
  text-align: right;
}

.amount-positive {
  color: var(--green);
  font-weight: 700;
}

.amount-negative {
  color: var(--red);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #edf1ef;
  color: #4f5a55;
  font-size: 11px;
  font-weight: 700;
}

.badge.success {
  background: #dcefe6;
  color: #176544;
}

.badge.warning {
  background: #f8ecd2;
  color: #845b13;
}

.badge.danger {
  background: #f5dddd;
  color: #932f2f;
}

.badge.info {
  background: #dceaf4;
  color: #255c82;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar label {
  width: 180px;
}

.toolbar .search-field {
  width: min(360px, 100%);
}

.toolbar span {
  color: var(--muted);
  font-size: 12px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 62px;
  border-top: 1px solid var(--line);
}

.report-list {
  min-height: 220px;
}

.report-item {
  display: grid;
  gap: 7px;
  padding: 14px 18px;
  border-bottom: 1px solid #e7ebe9;
}

.report-item:last-child {
  border-bottom: 0;
}

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

.report-item p {
  margin: 0;
  overflow: hidden;
  color: #4f5a55;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  padding: 24px;
}

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

.form-actions {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
}

.switch {
  display: inline-flex;
  grid: none;
  align-items: center;
  gap: 9px;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch span {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #b9c2bd;
  transition: background 150ms ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 150ms ease;
}

.switch input:checked + span {
  background: var(--green);
}

.switch input:checked + span::after {
  transform: translateX(-18px);
}

dialog {
  width: min(780px, calc(100% - 30px));
  max-height: calc(100vh - 34px);
  padding: 0;
  border: 1px solid #bfc8c3;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(12, 17, 15, 0.64);
}

.dialog-head {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0 0 5px;
  font-size: 18px;
}

.dialog-head p {
  margin: 0;
  color: var(--muted);
  direction: ltr;
  font-size: 11px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: #59645f;
  font-size: 22px;
}

.dialog-body {
  max-height: calc(100vh - 108px);
  overflow-y: auto;
  padding: 20px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0 0 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
}

.detail-grid div {
  min-height: 65px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 10px 12px;
  background: var(--surface);
}

.detail-grid dt {
  color: var(--muted);
  font-size: 11px;
}

.detail-grid dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.action-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.action-panel h3,
.embedded-section h3 {
  margin: 0;
  font-size: 14px;
}

.embedded-section {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.embedded-section > h3 {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.toast-region {
  position: fixed;
  z-index: 50;
  left: 20px;
  bottom: 20px;
  width: min(360px, calc(100% - 40px));
  display: grid;
  gap: 8px;
}

.toast {
  padding: 13px 15px;
  border: 1px solid #385347;
  border-radius: 6px;
  background: #17231e;
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.error {
  border-color: #8c3838;
  background: #3e1f1f;
}

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

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    z-index: 10;
    width: 100%;
    height: auto;
    border: 0;
  }

  .brand {
    min-height: 64px;
    padding: 10px 14px;
  }

  .brand img {
    width: 39px;
    height: 31px;
  }

  .navigation {
    display: flex;
    overflow-x: auto;
    padding: 7px;
  }

  .nav-item {
    min-width: max-content;
    min-height: 38px;
  }

  .nav-item.active {
    box-shadow: inset 0 -3px 0 #3aa273;
  }

  .sidebar-foot {
    display: none;
  }

  .main {
    padding: 0 12px 30px;
  }

  .topbar {
    min-height: auto;
    align-items: flex-start;
    padding: 16px 0;
  }

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

  .topbar p,
  .admin-identity {
    display: none;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .button {
    padding: 7px 10px;
  }

  .loading-line {
    right: 0;
  }

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

  .metric {
    min-height: 104px;
    padding: 13px;
  }

  .metric strong {
    font-size: 22px;
  }

  .toolbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .toolbar label,
  .toolbar .search-field {
    width: 100%;
  }

  .toolbar .button {
    flex: 1;
  }

  .settings-grid,
  .dialog-columns,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid .wide {
    grid-column: auto;
  }

  dialog {
    width: calc(100% - 16px);
    max-height: calc(100vh - 16px);
  }

  .dialog-body {
    max-height: calc(100vh - 90px);
    padding: 14px;
  }
}
