:root {
  --bg: #f4f1eb;
  --bg-elevated: #faf8f4;
  --text: #1a2744;
  --text-muted: #5c6478;
  --accent: #c45c3e;
  --accent-soft: #f0ddd6;
  --border: #ddd6cb;
  --nav-width: 15.5rem;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(26, 39, 68, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  overflow-x: hidden;
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 100;
  background: #fff;
  padding: 0.5rem 1rem;
}

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

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .side-nav {
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0.65rem 0.65rem;
    gap: 0.5rem;
  }
  .side-nav .brand-block h1 {
    font-size: 1.05rem;
  }
  .nav-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.15rem;
    padding: 0 0.15rem 0.1rem;
  }
  .nav-list {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.35rem;
    width: max-content;
    min-width: 100%;
  }
  .nav-list a {
    font-size: 0.8rem;
    padding: 0.4rem 0.65rem;
    white-space: nowrap;
  }
}

.side-nav {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.brand-block h1 {
  font-size: 1.35rem;
  margin: 0;
  letter-spacing: -0.02em;
}

.brand-block .byline {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.pill {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
}

.pill.private {
  border-color: #b8c4d9;
  color: #2c3f66;
}

.pill.demo {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-list a {
  display: block;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.88rem;
}

.nav-list a:hover,
.nav-list a[aria-current="page"] {
  background: #ebe6dc;
}

.nav-list a[aria-current="page"] {
  font-weight: 600;
}

.main-pane {
  padding: 1.25rem 1.5rem 3rem;
  max-width: 1100px;
  min-width: 0;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1.25rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.top-actions a {
  color: var(--accent);
  text-decoration: none;
}

h2.page-title {
  font-size: 1.75rem;
  margin: 0 0 0.35rem;
  letter-spacing: -0.02em;
}

.lede {
  color: var(--text-muted);
  max-width: 42rem;
  margin: 0 0 1.25rem;
  font-size: 1rem;
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.panel h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.82rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-grid {
  display: grid;
  gap: 0.65rem;
  max-width: 32rem;
  font-family: var(--font-ui);
  font-size: 0.88rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

input,
select,
textarea {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--text);
  background: var(--text);
  color: #fff;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  text-decoration: none;
}

button.secondary,
.btn.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: end;
}

.alert {
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.alert.error {
  background: #fdecea;
  border: 1px solid #e8b4ad;
  color: #7a2e24;
}

.alert.info {
  background: #eef2f8;
  border: 1px solid #c5d0e4;
  color: #2c3f66;
}

.empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.95rem;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 39, 68, 0.35);
  display: flex;
  justify-content: flex-end;
  z-index: 50;
}

.drawer {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  padding: 1rem 1.1rem 2rem;
  border-left: 1px solid var(--border);
  overflow: auto;
}

.loading-banner {
  padding: 2rem;
  font-family: var(--font-ui);
}

.alert.success {
  background: #e8f4ea;
  border: 1px solid #a8d5b0;
  color: #1f4d2c;
}

.help {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.toast-root {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 80;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-width: min(360px, calc(100vw - 2rem));
}

.toast {
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  background: #fff;
}

.toast-error {
  border-color: #e8b4ad;
  background: #fdecea;
}

.toast-success {
  border-color: #a8d5b0;
  background: #e8f4ea;
}

.badge {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
}

.badge-reversed,
.badge-disabled {
  border-color: #e8b4ad;
  color: #7a2e24;
}

.badge-paid,
.badge-active,
.badge-saved,
.badge-enabled,
.badge-checked,
.badge-passed {
  border-color: #a8d5b0;
}

.badge-failed,
.badge-empty {
  border-color: #e8b4ad;
  color: #7a2e24;
}

.provider-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
}

.provider-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.provider-card h4 {
  margin: 0 0 0.35rem;
}

.provider-name {
  font-weight: normal;
  color: var(--muted, #666);
}

.provider-status {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.linkish {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-align: left;
}

.import-preview.ok {
  color: #1f4d2c;
}

.import-preview.err {
  color: #7a2e24;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.main-pane,
.drawer {
  overflow-x: hidden;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 32rem;
}

.data-table th,
.data-table td {
  white-space: nowrap;
  word-break: normal;
}

@media print {
  .side-nav,
  .top-actions,
  .drawer-backdrop,
  .toast-root {
    display: none !important;
  }
  .app-shell {
    display: block;
  }
  .main-pane {
    max-width: none;
    padding: 0;
  }
}

.print-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

@media (max-width: 860px) {
  .main-pane {
    padding: 1rem;
  }
  .form-grid {
    max-width: none;
  }
}

.provider-card { min-width: 0; }
.provider-card code { overflow-wrap: anywhere; word-break: break-word; white-space: normal; }
