:root {
  --bg: #f4f1ea;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #ded8cd;
  --accent: #245d63;
  --accent-strong: #164a50;
  --warn: #a15c08;
  --danger: #b42318;
  --ok: #1d7f4e;
  --shadow: 0 18px 50px rgba(31, 35, 40, 0.08);
  --radius: 8px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

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

.login-panel h1,
.topbar h1,
.page-head h1 {
  margin: 2px 0 0;
  font-size: clamp(26px, 4vw, 38px);
  letter-spacing: 0;
}

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

.login-form,
.form-grid {
  display: grid;
  gap: 14px;
}

.login-form {
  margin-top: 24px;
}

label {
  display: grid;
  gap: 7px;
  color: #394150;
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cfc8bc;
  border-radius: 7px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 93, 99, 0.14);
}

.primary,
.secondary,
.ghost {
  min-height: 38px;
  border-radius: 7px;
  padding: 9px 13px;
  font-weight: 800;
}

.primary {
  background: var(--accent);
  color: white;
}

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

.secondary {
  border: 1px solid #cfc8bc;
  background: #fff;
  color: #263238;
}

.secondary:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.ghost {
  background: transparent;
  color: var(--muted);
  padding-inline: 0;
}

.full {
  width: 100%;
}

.form-message {
  margin: 0;
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-message.error,
.status.danger {
  color: var(--danger);
}

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

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  font-weight: 900;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: white;
}

nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 40px;
  border-radius: 7px;
  padding: 9px 10px;
  background: transparent;
  color: #4b5563;
  text-align: left;
  font-weight: 800;
}

.nav-item:hover,
.nav-item.active {
  background: #fffdfa;
  color: var(--accent-strong);
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

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

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

.topbar-actions,
.button-row,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.link-button {
  display: inline-grid;
  place-items: center;
  color: inherit;
  text-decoration: none;
}

.view {
  display: none;
}

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

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(31, 35, 40, 0.04);
  padding: 18px;
}

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

.panel h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

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

.metric-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  padding: 16px;
}

.metric strong {
  display: block;
  margin-bottom: 6px;
  font-size: clamp(24px, 4vw, 34px);
  letter-spacing: 0;
}

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

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

.balance-body {
  font-size: 32px;
  font-weight: 900;
}

.pill,
.status {
  display: inline-grid;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  background: #eee8dc;
  color: #4b5563;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status.ok,
.pill.ok {
  background: rgba(29, 127, 78, 0.12);
  color: var(--ok);
}

.status.warn,
.pill.warn {
  background: rgba(161, 92, 8, 0.13);
  color: var(--warn);
}

.status.danger,
.pill.danger {
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
}

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

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

.tool-row strong {
  display: block;
  margin-bottom: 2px;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

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

.wide-table {
  min-width: 1060px;
}

th,
td {
  padding: 12px 11px;
  border-bottom: 1px solid #eee8dc;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: #4b5563;
  background: #faf7f1;
  font-weight: 900;
  white-space: nowrap;
}

td {
  color: #2f3742;
}

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

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

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

.search {
  max-width: 280px;
}

.inline-check {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: #4b5563;
}

.inline-check input {
  width: auto;
  min-height: 0;
}

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

.row-actions button {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 12px;
}

.card-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.busy {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(244, 241, 234, 0.7);
  backdrop-filter: blur(3px);
}

.busy[hidden],
.toast[hidden],
[hidden] {
  display: none !important;
}

.busy-box {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  font-weight: 900;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid #d7d0c5;
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  max-width: min(380px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  color: #253036;
  font-size: 13px;
  font-weight: 800;
}

.toast.error {
  border-color: rgba(180, 35, 24, 0.32);
  color: var(--danger);
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

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

  .workspace {
    padding: 18px;
  }

  .metric-grid,
  .metric-grid.compact,
  .split-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .search {
    max-width: none;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 14px;
  }

  .panel {
    padding: 14px;
  }

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

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions > * {
    flex: 1;
  }
}
