:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --ink: #111827;
  --muted: #667085;
  --line: #d8dde7;
  --line-strong: #b7c0cf;
  --accent: #1d4ed8;
  --accent-strong: #173ea8;
  --success: #147a54;
  --warning: #b54708;
  --danger: #b42318;
  --slate: #475467;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  letter-spacing: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(240px, 1fr) auto;
  gap: 20px;
  align-items: center;
  min-height: 72px;
  padding: 14px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand-text {
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
}

.header-nav,
.user-box,
.button-row,
.actions,
.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.header-nav {
  justify-content: center;
}

.header-nav a {
  padding: 7px 2px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.header-nav a:hover,
.header-nav a:focus-visible {
  border-color: var(--accent);
  color: var(--ink);
}

.user-box {
  justify-content: flex-end;
}

.user-email {
  max-width: 280px;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 48px) 64px;
}

.flashes {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  border: 1px solid currentColor;
  border-radius: 8px;
  padding: 11px 13px;
  font-weight: 650;
}

.flash.success {
  background: #ecfdf3;
  color: var(--success);
}

.flash.error {
  background: #fff1f0;
  color: var(--danger);
}

.flash.info {
  background: #eff6ff;
  color: var(--accent);
}

.section {
  padding: 24px 0 30px;
  border-top: 1px solid var(--line);
}

.section:first-of-type {
  border-top: 0;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.section-heading.full,
.compact-heading {
  grid-column: 1 / -1;
}

.compact-heading {
  margin-bottom: 14px;
}

h1,
h2,
h3,
p,
dl {
  margin-top: 0;
}

h1,
h2,
h3 {
  line-height: 1.18;
}

h2 {
  margin-bottom: 5px;
  font-size: 22px;
}

h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

.page-title {
  margin-bottom: 5px;
  font-size: 24px;
}

.section-heading p,
.list-row p,
.login-panel p {
  margin-bottom: 0;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.compact-table table {
  min-width: 760px;
}

.compact-table th,
.compact-table td {
  padding: 8px 10px;
}

.table-wrap + h3,
.item-list + h3 {
  margin-top: 24px;
}

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

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

th {
  background: var(--surface-alt);
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

td strong {
  display: block;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.mono {
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.code-input,
.formula-code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.formula-code {
  overflow-x: auto;
  margin: 0 0 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-alt);
  white-space: pre-wrap;
}

.value-preview {
  max-width: 360px;
  overflow: hidden;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  max-width: 100%;
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 750;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

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

.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.choice:has(input:focus-visible) {
  outline: 3px solid rgba(29, 78, 216, 0.18);
  outline-offset: 2px;
}

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

.button.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: #fff;
}

.button.ghost {
  background: transparent;
}

.button.small {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
}

.button.danger {
  border-color: #f2b8b5;
  color: var(--danger);
}

.button.danger:hover {
  border-color: var(--danger);
  background: #fff1f0;
}

.button.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.button.wide {
  width: 100%;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.badge.sent,
.badge.status-active,
.flash.success {
  background: #ecfdf3;
  color: var(--success);
}

.badge.failed,
.badge.status-deleted,
.badge.status-not-found,
.flash.error {
  background: #fff1f0;
  color: var(--danger);
}

.badge.status-unassigned,
.badge.status-disabled {
  background: #fffaeb;
  color: var(--warning);
}

.badge.created,
.badge.status-not-checked,
.flash.info {
  background: #eff6ff;
  color: var(--accent);
}

.badge.muted {
  background: #f2f4f7;
  color: var(--slate);
}

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

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

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 24px;
}

fieldset,
.stack-form {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

legend {
  padding: 0 6px;
  color: #344054;
  font-weight: 800;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: #344054;
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid #c9d2df;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

.segmented-control {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

label.choice {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  margin: 0;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-alt);
  font-weight: 750;
}

label.compact-choice {
  min-height: 32px;
  margin-bottom: 12px;
}

.choice input {
  width: auto;
  min-height: 0;
  margin: 0;
}

.conditional {
  margin-top: 12px;
}

.hidden {
  display: none;
}

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

.compact-list {
  margin-bottom: 18px;
}

.list-row {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

.row-title,
.list-row > div:first-child {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

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

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

.meta-grid div {
  min-width: 0;
}

.meta-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-grid dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
  overflow-wrap: anywhere;
}

.schedule-delete-form {
  margin-top: 14px;
}

.quantity-form {
  display: grid;
  grid-template-columns: minmax(88px, 110px) auto;
  gap: 7px;
  align-items: center;
}

.quantity-input {
  min-height: 32px;
  padding-block: 6px;
}

.inline-editor {
  margin: 10px 0 12px;
}

.inline-editor summary,
.table-editor summary {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.inline-editor summary:hover,
.inline-editor summary:focus-visible,
.table-editor summary:hover,
.table-editor summary:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.calc-inline {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  background: #ecfdf3;
  color: var(--success);
  font-size: 12px;
  font-weight: 800;
}

.resource-edit-form,
.item-edit-form,
.table-edit-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
}

.resource-edit-form label,
.item-edit-form label,
.table-edit-form label {
  margin-bottom: 0;
}

.table-editor {
  position: relative;
}

.table-edit-form {
  position: absolute;
  right: 0;
  z-index: 4;
  width: min(820px, calc(100vw - 40px));
  box-shadow: var(--shadow);
}

.editor-panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

.wide-edit-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.wide-edit-form label {
  margin-bottom: 0;
}

.wide-edit-form .button {
  justify-self: start;
}

.item-wide-edit-form label:nth-of-type(4),
.item-wide-edit-form label:nth-of-type(5) {
  grid-column: span 3;
}

.pagination {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #f3f6fb;
}

.login-shell {
  width: min(440px, 100%);
}

.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 26px;
}

.login-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.login-brand h1 {
  margin: 0 0 3px;
  font-size: 22px;
}

.report-view {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.report-document h1 {
  margin-top: 0;
}

.report-document table {
  min-width: 780px;
}

.report-document td {
  white-space: pre-line;
}

.inline-form {
  justify-content: flex-end;
  max-width: 680px;
}

.inline-form label {
  min-width: 210px;
  margin-bottom: 0;
}

@media (max-width: 1180px) {
  .app-header {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .header-nav,
  .user-box {
    justify-content: flex-start;
  }

  .two-column {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .page {
    padding-inline: 14px;
  }

  .grid-form,
  .grid-form.compact,
  .meta-grid.resource-meta,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    display: grid;
  }

  .button-row,
  .actions,
  .inline-form {
    align-items: stretch;
  }

  .button-row .button,
  .actions .button,
  .inline-form .button,
  .resource-edit-form .button,
  .item-edit-form .button,
  .table-edit-form .button {
    width: 100%;
  }

  .inline-form label {
    width: 100%;
  }

  .resource-edit-form,
  .item-edit-form,
  .table-edit-form,
  .wide-edit-form {
    grid-template-columns: 1fr;
  }

  .item-wide-edit-form label:nth-of-type(4),
  .item-wide-edit-form label:nth-of-type(5) {
    grid-column: auto;
  }

  .table-edit-form {
    position: static;
    width: 100%;
  }
}
