:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --surface-strong: #eef2f7;
  --ink: #111827;
  --ink-soft: #4b5563;
  --ink-muted: #6b7280;
  --line: #d9e1ea;
  --line-soft: #e7edf3;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #e8f0ff;
  --green: #0f766e;
  --green-soft: #e6f6f2;
  --amber: #b45309;
  --amber-soft: #fff7ed;
  --red: #b42318;
  --red-soft: #fff1f1;
  --slate: #334155;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 10px 30px rgba(15, 23, 42, .05);
  --shadow-soft: 0 1px 2px rgba(15, 23, 42, .05);
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar: 264px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-weight: 500;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  color: var(--brand-dark);
}

code,
.mono {
  font-family: Consolas, "SFMono-Regular", ui-monospace, Menlo, Monaco, monospace;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(14px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 68px;
  padding: 10px 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
  color: var(--ink);
}

.brand:hover {
  color: var(--ink);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid #cfe0ff;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-soft);
  flex: 0 0 auto;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-copy {
  display: grid;
  gap: 1px;
}

.brand-copy strong {
  font-size: 15px;
  line-height: 1.2;
  font-weight: 800;
  color: var(--ink);
}

.brand-copy small {
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 700;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: auto;
}

.topnav a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-weight: 800;
}

.topnav a:hover {
  background: var(--surface-strong);
  color: var(--ink);
}

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

.topbar-actions form {
  margin: 0;
}

.status-dot,
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.status-dot span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.nav-logout {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}

.nav-logout:hover {
  background: var(--surface-strong);
  color: var(--ink);
}

.ui-icon {
  width: 16px;
  height: 16px;
  display: block;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.main-shell .app-shell {
  display: block;
}

.sidebar {
  position: sticky;
  top: 69px;
  align-self: start;
  height: calc(100vh - 69px);
  overflow: auto;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
}

.sidebar-section {
  display: grid;
  gap: 5px;
  padding: 4px 0 14px;
}

.sidebar-label {
  margin: 8px 10px 4px;
  color: #7c8898;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-weight: 800;
}

.side-link:hover,
.side-link.is-active {
  background: #edf4ff;
  color: #174ea6;
}

.side-icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--slate);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0;
  flex: 0 0 auto;
}

.side-icon .ui-icon {
  width: 15px;
  height: 15px;
  color: #334155;
}

.side-link.is-active .side-icon {
  border-color: #b9d4ff;
  background: #fff;
  color: #174ea6;
}

.side-link.is-active .side-icon .ui-icon {
  color: #174ea6;
}

.app-main {
  min-width: 0;
}

.content-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 28px 56px;
}

.main-shell .content-shell {
  max-width: 1240px;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--ink);
  letter-spacing: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.18;
  font-weight: 850;
}

h2,
.soft-section-title {
  font-size: 18px;
  line-height: 1.25;
  font-weight: 850;
}

h3 {
  margin-bottom: 12px;
  font-size: 15px;
  line-height: 1.25;
  font-weight: 850;
}

p {
  margin: 0 0 10px;
}

.muted,
.help {
  color: var(--ink-muted);
  font-weight: 600;
}

.help {
  margin-top: 6px;
  font-size: 12px;
}

.grid,
.stack {
  display: grid;
  gap: 16px;
}

form.stack {
  gap: 18px;
}

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

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

.toolbar,
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
}

.toolbar .spacer,
.page-header .spacer {
  flex: 1 1 auto;
}

.hero-panel {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 22px;
  border: 1px solid #cfd9e6;
  border-left: 5px solid var(--green);
  border-radius: var(--radius);
  background: #102033;
  color: #fff;
  box-shadow: var(--shadow);
}

.hero-panel h1,
.hero-panel h2 {
  color: #fff;
}

.hero-panel .muted {
  max-width: 820px;
  margin: 0;
  color: #d7e2ee;
}

.panel,
.soft-card,
.summary-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.panel,
.soft-card {
  padding: 20px;
}

.summary-card {
  padding: 18px;
}

.panel + .panel,
.soft-card + .panel,
.panel + .soft-card {
  margin-top: 16px;
}

.summary-card > :last-child,
.panel > :last-child,
.soft-card > :last-child {
  margin-bottom: 0;
}

.panel > strong,
.summary-card > strong,
.soft-card > strong {
  display: block;
  margin: 4px 0 6px;
  color: #0f172a;
  font-size: 30px;
  line-height: 1;
  font-weight: 900;
}

.panel p a,
.summary-card p a {
  font-weight: 850;
}

.content-shell > table,
.panel > table,
.soft-card > table,
form.panel > table {
  display: block;
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

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

th {
  background: #f1f5f9;
  color: #475569;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  color: #172033;
  font-weight: 560;
}

tbody tr:hover {
  background: #f8fbff;
}

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

.btn,
.soft-button-secondary,
.soft-button-primary,
.btn.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: #1f4f9b;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 850;
  text-align: center;
  box-shadow: var(--shadow-soft);
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}

.btn:hover,
.soft-button-secondary:hover {
  border-color: #b7c6d8;
  background: #f8fbff;
  color: #174ea6;
  transform: translateY(-1px);
}

.btn.primary,
.soft-button-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.btn.primary:hover,
.soft-button-primary:hover {
  border-color: var(--brand-dark);
  background: var(--brand-dark);
  color: #fff;
}

.btn.danger {
  border-color: #dc2626;
  background: #dc2626;
  color: #fff;
}

.btn.danger:hover {
  border-color: #b91c1c;
  background: #b91c1c;
  color: #fff;
}

button:disabled,
.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 4px 9px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
  line-height: 1.1;
  font-weight: 900;
  white-space: nowrap;
}

.pill.good {
  border-color: #a7d8cd;
  background: var(--green-soft);
  color: #0f766e;
}

.pill.warn {
  border-color: #fed7aa;
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.bad {
  border-color: #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.pill.muted {
  border-color: #dbe4ef;
  background: #f3f6fa;
  color: #526071;
}

.notice {
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink-soft);
  font-weight: 700;
}

.notice.warn {
  border-color: #fed7aa;
  background: var(--amber-soft);
  color: #7c3f02;
}

.notice.good {
  border-color: #a7d8cd;
  background: var(--green-soft);
  color: #0f766e;
}

.notice.bad {
  border-color: #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.message {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-soft);
  font-weight: 760;
}

.message.success {
  border-color: #a7d8cd;
  background: var(--green-soft);
  color: #0f766e;
}

.message.error,
.message.danger {
  border-color: #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.message.warning {
  border-color: #fed7aa;
  background: var(--amber-soft);
  color: var(--amber);
}

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

label,
.soft-label {
  display: block;
  margin: 0 0 6px;
  color: #263245;
  font-size: 13px;
  font-weight: 850;
}

input,
select,
textarea,
.soft-input {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 640;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

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

input::placeholder,
textarea::placeholder {
  color: #94a3b8;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #aab8c9;
  background: #fbfdff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .16);
  background: #fff;
}

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--brand);
}

input[type="file"] {
  padding: 8px 10px;
}

.errorlist {
  display: grid;
  gap: 4px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  color: var(--red);
  font-size: 12px;
  font-weight: 850;
}

details {
  border-radius: var(--radius);
}

summary {
  cursor: pointer;
  font-weight: 850;
  color: #1f4f9b;
}

details[open] > summary {
  margin-bottom: 10px;
}

.payload-details {
  min-width: 320px;
}

.payload-details summary {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.payload-details[open] {
  display: grid;
  gap: 10px;
}

.sage-log-panel table {
  min-width: 1080px;
}

pre {
  max-height: 520px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid #223044;
  border-radius: var(--radius);
  background: #0f172a;
  color: #dbeafe;
  font-family: Consolas, "SFMono-Regular", ui-monospace, Menlo, Monaco, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.line-form {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.search-wrap {
  display: grid;
  gap: 8px;
}

.search-wrap input {
  min-height: 38px;
}

.accounting-workspace {
  margin-bottom: 16px;
  padding: 0;
  overflow: hidden;
}

.workspace-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.workspace-title {
  display: grid;
  gap: 6px;
}

.workspace-title p {
  margin: 0;
}

.workspace-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.workspace-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.workspace-actions form {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
}

.workspace-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 14px;
  background: #fff;
}

.workspace-tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink-soft);
  font-weight: 850;
}

.workspace-tabs a:hover,
.workspace-tabs a.is-active {
  border-color: #bfd3f6;
  background: var(--brand-soft);
  color: #174ea6;
}

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

.api-group-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.api-group-card summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  list-style: none;
}

.api-group-card summary::-webkit-details-marker {
  display: none;
}

.api-group-card summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: .55;
}

.api-group-card[open] summary::after {
  transform: rotate(225deg);
}

.api-endpoint-list {
  display: grid;
  gap: 8px;
  padding: 0 16px 16px;
}

.api-endpoint-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.5fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #f8fafc;
}

.api-methods,
.api-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.api-flags {
  margin-top: 6px;
}

.api-method {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 11px;
  font-weight: 900;
}

.api-path {
  color: #334155;
  font-family: Consolas, "SFMono-Regular", ui-monospace, Menlo, Monaco, monospace;
  font-size: 13px;
  word-break: break-word;
}

@media (min-width: 761px) {
  .md-col-span-2 {
    grid-column: span 2 / span 2;
  }
}

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

  .sidebar {
    position: sticky;
    top: 68px;
    z-index: 40;
    display: flex;
    height: auto;
    max-width: 100vw;
    overflow-x: auto;
    gap: 12px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-section {
    min-width: 190px;
    padding-bottom: 4px;
  }

  .sidebar-label {
    margin-top: 0;
  }
}

@media (max-width: 760px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
  }

  .brand {
    min-width: 0;
    flex: 1 1 100%;
  }

  .topnav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .content-shell {
    padding: 18px 14px 38px;
  }

  .grid-2,
  .grid-3,
  .form-grid,
  .soft-form-grid,
  .workspace-header,
  .api-endpoint-row {
    grid-template-columns: 1fr;
  }

  .panel,
  .soft-card,
  .summary-card {
    padding: 16px;
  }

  .workspace-actions,
  .workspace-actions form {
    justify-content: flex-start;
  }

  .toolbar,
  .page-header {
    align-items: stretch;
  }

  .toolbar .spacer,
  .page-header .spacer {
    display: none;
  }

  .btn,
  .soft-button-primary,
  .soft-button-secondary {
    width: 100%;
  }

  .hero-panel {
    padding: 18px;
  }

  h1 {
    font-size: 22px;
  }
}
