:root {
  --ink: #1f2933;
  --muted: #66707a;
  --line: #d5deee;
  --brand: #1565c0;
  --brand-deep: #0f2a6f;
  --accent: #00b894;
  --accent-soft: #d9f8f0;
  --danger: #a4432c;
  --shadow: 0 24px 60px rgba(21, 101, 192, 0.12);
}

html {
  font-size: 15px;
}

body {
  margin: 0;
  height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(21, 101, 192, 0.16), transparent 28%),
    radial-gradient(circle at bottom right, rgba(0, 184, 148, 0.16), transparent 30%),
    linear-gradient(135deg, #f7fbff, #eef6ff 55%, #f4fffc);
  font-family: Bahnschrift, "Trebuchet MS", sans-serif;
  overflow: hidden;
}

.app-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  gap: 1rem;
  background: rgba(247, 251, 255, 0.78);
  backdrop-filter: blur(5px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms ease, visibility 140ms ease;
}

.app-loading-overlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.app-loading-spinner {
  position: relative;
  width: 152px;
  height: 152px;
}

.app-loading-spinner span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 62px;
  margin: -31px 0 0 -11px;
  border-radius: 999px;
  background: linear-gradient(180deg, #27dec2, #1598ff);
  transform-origin: center -8px;
  animation: loadingPulse 1s linear infinite;
}

.app-loading-spinner span:nth-child(1) { transform: rotate(0deg) translateY(-46px); animation-delay: -0.9s; }
.app-loading-spinner span:nth-child(2) { transform: rotate(36deg) translateY(-46px); animation-delay: -0.8s; }
.app-loading-spinner span:nth-child(3) { transform: rotate(72deg) translateY(-46px); animation-delay: -0.7s; }
.app-loading-spinner span:nth-child(4) { transform: rotate(108deg) translateY(-46px); animation-delay: -0.6s; }
.app-loading-spinner span:nth-child(5) { transform: rotate(144deg) translateY(-46px); animation-delay: -0.5s; }
.app-loading-spinner span:nth-child(6) { transform: rotate(180deg) translateY(-46px); animation-delay: -0.4s; }
.app-loading-spinner span:nth-child(7) { transform: rotate(216deg) translateY(-46px); animation-delay: -0.3s; }
.app-loading-spinner span:nth-child(8) { transform: rotate(252deg) translateY(-46px); animation-delay: -0.2s; }
.app-loading-spinner span:nth-child(9) { transform: rotate(288deg) translateY(-46px); animation-delay: -0.1s; }
.app-loading-spinner span:nth-child(10) { transform: rotate(324deg) translateY(-46px); animation-delay: 0s; }

.app-loading-label {
  margin-top: -0.7rem;
  font-size: 1.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #1caee2;
}

@keyframes loadingPulse {
  0%,
  100% {
    opacity: 0.22;
    filter: saturate(0.7);
  }

  50% {
    opacity: 1;
    filter: saturate(1.1);
  }
}

.shell-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  padding: 2rem 1.5rem;
  background: linear-gradient(180deg, rgba(15, 42, 111, 0.98), rgba(21, 101, 192, 0.96) 58%, rgba(0, 184, 148, 0.93));
  color: #f7f3ea;
  box-shadow: var(--shadow);
}

.brand-lockup {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-decoration: none;
  color: inherit;
}

.brand-kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.78);
}

.brand-name {
  font-family: Cambria, "Palatino Linotype", serif;
  font-size: 1.7rem;
}

.nav-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.nav-chip {
  display: block;
  padding: 0.95rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  color: #f7f3ea;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.06);
  transition: transform 120ms ease, background 120ms ease;
}

.nav-chip:hover,
.nav-chip.active {
  color: #fff;
  transform: translateX(4px);
  background: rgba(255, 255, 255, 0.16);
}

.sidebar-user {
  margin-top: auto;
  padding: 1.15rem;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-database {
  margin-bottom: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-database-name {
  margin-top: 0.4rem;
  font-size: 1rem;
  font-weight: 700;
}

.sidebar-database-server {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.9rem;
  word-break: break-word;
}

.sidebar-user-label {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.76;
}

.sidebar-user-name {
  margin-top: 0.4rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.sidebar-user-id {
  margin-bottom: 1rem;
  color: rgba(255, 255, 255, 0.72);
}

.btn-ghost-danger {
  color: #fff4ef;
  background: rgba(164, 67, 44, 0.3);
  border: 1px solid rgba(255, 244, 239, 0.18);
}

.btn-ghost-danger:hover {
  color: #fff;
  background: rgba(164, 67, 44, 0.5);
}

.main-panel {
  padding: 2rem;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-kicker {
  display: inline-block;
  margin-bottom: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: var(--brand);
}

.page-title {
  margin: 0;
  font-family: Cambria, "Palatino Linotype", serif;
  font-size: 2rem;
}

.page-subtitle {
  margin-top: 0.45rem;
  color: var(--muted);
}

.list-panel,
.editor-panel,
.metric-card,
.summary-card,
.login-card {
  background: rgba(255, 253, 250, 0.94);
  border: 1px solid rgba(223, 211, 192, 0.9);
  border-radius: 1.3rem;
  box-shadow: var(--shadow);
}

.list-panel,
.editor-panel,
.login-card {
  padding: 1.5rem;
}

.list-panel-workspace,
.editor-panel-workspace {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  padding: 1.2rem;
}

.metric-label {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metric-value {
  margin-top: 0.5rem;
  font-size: 2rem;
  font-weight: 700;
  color: var(--brand-deep);
}

.two-up {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.2rem;
}

.section-title {
  margin: 0 0 1rem;
  font-family: Cambria, "Palatino Linotype", serif;
  font-size: 1.25rem;
}

.clean-table {
  width: 100%;
  border-collapse: collapse;
}

.clean-table th,
.clean-table td {
  padding: 0.85rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.clean-table th {
  font-size: 0.83rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.page-head .toolbar {
  justify-content: flex-end;
}

.editor-topbar {
  display: grid;
  gap: 1rem;
  margin-bottom: 1rem;
}

.autosave-pill {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.84rem;
  background: rgba(21, 101, 192, 0.1);
  color: var(--brand-deep);
}

.autosave-pill[data-state="saving"],
.autosave-pill[data-state="pending"] {
  background: rgba(0, 184, 148, 0.14);
  color: #007d66;
}

.autosave-pill[data-state="error"] {
  background: rgba(164, 67, 44, 0.15);
  color: var(--danger);
}

.btn-primary-soft {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  border: 0;
}

.btn-primary-soft:hover {
  color: #fff;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
}

.btn-accent-soft {
  background: var(--accent-soft);
  color: #007d66;
  border: 0;
}

.payment-intent-card {
  margin-bottom: 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(240, 180, 41, 0.38);
  border-radius: 1rem;
  background: linear-gradient(135deg, rgba(255, 250, 237, 0.98), rgba(255, 245, 224, 0.94));
}

.payment-intent-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
}

.payment-intent-title {
  margin: 0.2rem 0 0;
}

.payment-intent-copy {
  margin: 0.7rem 0 0;
  color: var(--muted);
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.editor-static-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.editor-static-meta {
  display: flex;
  align-items: baseline;
  min-height: 42px;
}

.editor-static-value {
  color: var(--brand-deep);
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.2;
  word-break: break-word;
}

.editor-comment-field {
  min-height: 42px;
  resize: vertical;
}

.field-span-4 {
  grid-column: span 4;
}

.lookup-picker {
  position: relative;
}

.lookup-picker-shell {
  display: grid;
  grid-template-columns: 1fr 38px;
  align-items: stretch;
}

.lookup-picker-input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.lookup-picker-toggle {
  border: 1px solid #ced4da;
  border-left: 0;
  background: #f8fbff;
  color: var(--brand-deep);
  border-top-right-radius: 0.75rem;
  border-bottom-right-radius: 0.75rem;
}

.lookup-picker-toggle:hover {
  background: #eef6ff;
}

.lookup-native-select {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  inset: auto;
  width: 1px;
  height: 1px;
}

.lookup-option {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(260px, 1.8fr) minmax(120px, 0.8fr);
  gap: 1rem;
  align-items: center;
  padding: 0.55rem 0.8rem;
  border: 0;
  background: transparent;
  text-align: left;
}

.lookup-option:hover,
.lookup-option.active {
  background: rgba(21, 101, 192, 0.08);
}

.lookup-option-primary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.lookup-option-secondary {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
  text-align: right;
}

.lookup-empty {
  padding: 0.7rem 0.8rem;
  color: var(--muted);
}

.lookup-picker-article {
  min-width: 320px;
}

.lookup-portal {
  position: fixed;
  z-index: 1000;
  max-height: 320px;
  overflow-y: auto;
  background: rgba(255, 253, 250, 0.99);
  border: 1px solid rgba(21, 101, 192, 0.16);
  border-radius: 0.9rem;
  box-shadow: 0 20px 42px rgba(16, 42, 111, 0.18);
}

.compact-table-shell,
.table-scroll-frame {
  border-radius: 1rem;
}

.table-scroll-frame {
  overflow: auto;
  min-height: 0;
  flex: 1;
}

.line-editor-table th,
.line-editor-table td {
  padding: 0.24rem 0.3rem;
  vertical-align: middle;
}

.line-editor-table {
  table-layout: fixed;
}

.line-editor-table th:nth-child(1),
.line-editor-table td:nth-child(1) {
  width: 31%;
}

.line-editor-table th:nth-child(2),
.line-editor-table td:nth-child(2) {
  width: 7.5%;
}

.line-editor-table th:nth-child(3),
.line-editor-table td:nth-child(3) {
  width: 11.5%;
}

.line-editor-table th:nth-child(4),
.line-editor-table td:nth-child(4) {
  width: 6.5%;
}

.line-editor-table th:nth-child(5),
.line-editor-table td:nth-child(5),
.line-editor-table th:nth-child(6),
.line-editor-table td:nth-child(6),
.line-editor-table th:nth-child(7),
.line-editor-table td:nth-child(7),
.line-editor-table th:nth-child(8),
.line-editor-table td:nth-child(8),
.line-editor-table th:nth-child(9),
.line-editor-table td:nth-child(9) {
  width: 7%;
}

.line-editor-table th:nth-child(10),
.line-editor-table td:nth-child(10) {
  width: 6%;
}

.line-editor-table th:nth-child(11),
.line-editor-table td:nth-child(11) {
  width: 4.5%;
}

.line-editor-table .form-control,
.line-editor-table .form-select {
  min-height: 32px;
  padding: 0.28rem 0.45rem;
  font-size: 0.88rem;
}

.line-editor-table .lookup-picker-shell {
  grid-template-columns: 1fr 30px;
}

.line-editor-table .lookup-picker-toggle {
  padding: 0;
}

.line-editor-table .btn-sm {
  padding: 0.28rem 0.5rem;
  font-size: 0.78rem;
}

.line-comment-link {
  font-size: 0.84rem;
  text-decoration: none;
  color: var(--brand);
}

.line-comment-link:hover {
  color: var(--brand-deep);
  text-decoration: underline;
}

.line-comment-link[data-comment-state="filled"] {
  font-weight: 600;
}

.line-comment-context {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

[data-comment-modal-input] {
  min-height: 140px;
  resize: vertical;
}

.preview-modal-content {
  background: #fffdf8;
}

.preview-sheet {
  display: grid;
  gap: 1.2rem;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.preview-title {
  margin: 0.2rem 0 0;
  font-family: Cambria, "Palatino Linotype", serif;
  font-size: 1.8rem;
  color: var(--brand-deep);
}

.preview-kicker {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--brand);
}

.preview-number {
  font-size: 1rem;
  font-weight: 700;
  color: var(--brand-deep);
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.preview-card {
  padding: 0.8rem 0.95rem;
  border-radius: 0.9rem;
  background: rgba(238, 246, 255, 0.65);
  border: 1px solid rgba(21, 101, 192, 0.14);
}

.preview-card-label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.preview-card-value {
  color: var(--brand-deep);
  font-weight: 700;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
}

.preview-table th,
.preview-table td {
  padding: 0.55rem 0.45rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.preview-table th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.preview-table td:last-child,
.preview-table th:last-child {
  text-align: right;
}

@media print {
  body,
  .main-panel {
    height: auto;
    overflow: visible;
    background: #fff;
  }

  .shell-grid {
    display: block;
    height: auto;
  }

  .sidebar,
  .page-head,
  .editor-topbar,
  .modal,
  .btn,
  .lookup-picker-toggle,
  [data-remove-line] {
    display: none !important;
  }
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.summary-card {
  padding: 1rem 1.1rem;
}

.summary-strip-top {
  position: sticky;
  top: 1rem;
  z-index: 2;
}

.summary-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.summary-value {
  margin-top: 0.4rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--brand-deep);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.status-pill.success {
  color: #14553a;
  background: rgba(29, 122, 82, 0.12);
}

.status-pill.warning {
  color: #007d66;
  background: rgba(0, 184, 148, 0.16);
}

.status-pill.draft {
  color: #7a4b11;
  background: rgba(240, 180, 41, 0.2);
}

.list-filter-bar {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.list-filter-input {
  flex: 1 1 320px;
  max-width: 460px;
}

.list-filter-meta {
  color: var(--muted);
  font-size: 0.92rem;
}

.login-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-card {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  overflow: hidden;
}

.login-story {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    linear-gradient(160deg, rgba(15, 42, 111, 0.97), rgba(21, 101, 192, 0.94)),
    linear-gradient(45deg, rgba(0, 184, 148, 0.24), transparent);
  color: #fff9ef;
}

.login-logo {
  width: min(280px, 72%);
  height: auto;
  display: block;
  filter: drop-shadow(0 16px 30px rgba(8, 24, 66, 0.28));
}

.login-form {
  padding: 2rem;
}

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

@media (max-width: 1080px) {
  .metrics-grid,
  .two-up,
  .summary-strip,
  .editor-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 840px) {
  .shell-grid,
  .login-card,
  .metrics-grid,
  .two-up,
  .summary-strip,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .page-head {
    align-items: start;
    flex-direction: column;
  }

  .field-span-4 {
    grid-column: span 1;
  }

  .main-panel {
    padding: 1rem;
    overflow: auto;
  }
}
