:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f0f3f6;
  --border: #d5dbe1;
  --text: #1c2430;
  --text-muted: #5b6875;
  --accent: #1f5fa8;
  --accent-strong: #174a85;
  --accent-soft: #e4eef9;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warning: #9a6700;
  --warning-soft: #fff4d6;
  --success: #1a7f4b;
  --success-soft: #e3f5ea;
  --radius: 8px;
  --nav-width: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* {
  box-sizing: border-box;
}
html {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a {
  color: var(--accent);
}
h1 {
  font-size: 1.5rem;
  margin: 0 0 0.75rem;
}
h2 {
  font-size: 1.15rem;
  margin: 1.25rem 0 0.5rem;
}
h3 {
  font-size: 1rem;
  margin: 1rem 0 0.4rem;
}
p {
  margin: 0.4rem 0;
}
code {
  font-size: 0.9em;
  background: var(--surface-muted);
  padding: 0 0.25em;
  border-radius: 3px;
}
.muted {
  color: var(--text-muted);
}
.small {
  font-size: 0.85rem;
}
.nowrap {
  white-space: nowrap;
}
.address {
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.inline {
  display: inline;
}
.hidden {
  display: none !important;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* Layout */
.app-frame {
  display: flex;
  flex: 1;
  min-height: 100vh;
}
.side-nav {
  width: var(--nav-width);
  flex-shrink: 0;
  background: #16202c;
  color: #e8edf2;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.side-nav .brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  padding: 0.25rem 0.5rem;
}
.side-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.side-nav li a {
  display: block;
  color: #cfd8e3;
  text-decoration: none;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
}
.side-nav li a:hover,
.side-nav li a[aria-current="page"] {
  background: #24384f;
  color: #fff;
}
.nav-user {
  margin-top: auto;
  font-size: 0.85rem;
  color: #b8c4d0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.5rem;
}
.nav-user .link-button {
  color: #cfd8e3;
}
.app-main {
  flex: 1;
  padding: 1.5rem 2rem 3rem;
  min-width: 0;
}
body.wide .app-main {
  padding-right: 1rem;
}
.standalone-main {
  max-width: 520px;
  margin: 3rem auto;
  padding: 0 1rem;
  width: 100%;
}
.brand-header {
  text-align: center;
  margin-bottom: 1.5rem;
}
.brand-header .brand {
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--text);
  text-decoration: none;
}
.attribution {
  margin-top: auto;
  padding: 1rem 2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.attribution a {
  color: var(--text-muted);
}
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.page-header h1 {
  margin: 0;
}
.page-header .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.subtitle {
  color: var(--text-muted);
  margin-top: 0.15rem;
  overflow-wrap: anywhere;
}

/* Cards and grid */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.card h2:first-child,
.card h3:first-child {
  margin-top: 0;
}
.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1rem;
  margin: 0;
}
.kv dt {
  color: var(--text-muted);
}
.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
th,
td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--surface-muted);
}
tr.muted td {
  color: var(--text-muted);
}
td.num,
th.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.table-group th {
  background: var(--accent-soft);
  color: var(--accent-strong);
  text-transform: none;
  font-size: 0.95rem;
}

/* Forms */
form.stack label:not(.checkbox),
.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
label > span:first-child,
.field > span:first-child {
  font-size: 0.85rem;
  color: var(--text-muted);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  font: inherit;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  width: 100%;
  max-width: 100%;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea {
  min-height: 5rem;
  resize: vertical;
}
input.narrow,
select.narrow {
  width: 8rem;
}
.checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}
.checkbox input {
  width: auto;
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}
.field-error {
  color: var(--danger);
  font-size: 0.85rem;
}
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
}
legend {
  font-weight: 600;
  padding: 0 0.3rem;
}
.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

/* Buttons */
button,
.button {
  font: inherit;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.3;
}
button:hover,
.button:hover {
  background: var(--accent-strong);
}
button.secondary,
.button.secondary {
  background: var(--surface);
  color: var(--accent-strong);
  border-color: var(--border);
}
button.secondary:hover,
.button.secondary:hover {
  background: var(--accent-soft);
}
button.danger,
.button.danger {
  background: var(--danger);
  border-color: var(--danger);
}
button.small,
.button.small {
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
}
button[disabled],
.button[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}
.link-button {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}
.link-button:hover {
  background: none;
  color: var(--accent-strong);
}

/* Badges, flashes, banners */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}
.badge.warn {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: transparent;
}
.badge.bad {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
.badge.info {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: transparent;
}
.flashes {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.flash {
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.flash-success {
  background: var(--success-soft);
  border-color: var(--success);
}
.flash-error {
  background: var(--danger-soft);
  border-color: var(--danger);
}
.flash-warning {
  background: var(--warning-soft);
  border-color: var(--warning);
}
.flash-info {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  background: var(--surface);
}
.banner.warn {
  background: var(--warning-soft);
  border-color: var(--warning);
}
.banner.bad {
  background: var(--danger-soft);
  border-color: var(--danger);
}
.banner.info {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.gate {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  background: var(--surface);
  margin-bottom: 1rem;
}
.gate ul {
  margin: 0.3rem 0 0.5rem 1.2rem;
  padding: 0;
}
.gate .blocker {
  color: var(--danger);
}
.gate .warning {
  color: var(--warning);
}

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.tab {
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab:hover {
  color: var(--text);
}

/* Stage indicator */
.stages {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}
.stages li {
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.stages li.done {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}
.stages li.current {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
  font-weight: 600;
}

/* Menus (details-based; repositioned by app.js to avoid clipping) */
details.menu {
  position: relative;
  display: inline-block;
}
details.menu > summary {
  list-style: none;
  cursor: pointer;
}
details.menu > summary::-webkit-details-marker {
  display: none;
}
details.menu > .menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 0.35rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
details.menu > .menu-panel.fixed {
  position: fixed;
}
.menu-panel a,
.menu-panel button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 0.45rem 0.6rem;
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
}
.menu-panel a:hover,
.menu-panel button:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* Dialogs */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 640px;
  width: calc(100% - 2rem);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
dialog::backdrop {
  background: rgba(20, 30, 40, 0.45);
}
dialog h2 {
  margin-top: 0;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Lists */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.list li:last-child {
  border-bottom: none;
}
.empty {
  color: var(--text-muted);
  font-style: italic;
  padding: 0.75rem 0;
}
.progress {
  height: 8px;
  background: var(--surface-muted);
  border-radius: 4px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width 0.2s;
}
.totals {
  max-width: 420px;
  margin-left: auto;
}
.totals dt {
  text-align: right;
}
.totals .selling {
  font-size: 1.2rem;
  font-weight: 700;
}

/* Responsive */
@media (max-width: 900px) {
  .app-frame {
    flex-direction: column;
  }
  .side-nav {
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }
  .side-nav ul {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .nav-user {
    margin-top: 0;
    margin-left: auto;
    flex-direction: row;
    align-items: center;
  }
  .app-main {
    padding: 1rem;
  }
  .attribution {
    padding: 0.75rem 1rem;
  }
}
@media (max-width: 600px) {
  html {
    font-size: 14px;
  }
  .page-header {
    flex-direction: column;
  }
  .kv {
    grid-template-columns: 1fr;
  }
  .kv dt {
    margin-top: 0.4rem;
  }
}
