:root,
:root[data-theme="light"] {
  color-scheme: light;
  --ink: #05062f;
  --muted: #60657f;
  --line: #d9dff0;
  --surface: #ffffff;
  --page: #f4f6fb;
  --page-start: #fbfcff;
  --primary: #4430c7;
  --primary-dark: #15115f;
  --primary-soft: #eef0ff;
  --accent: #06aee8;
  --accent-soft: #e8f8ff;
  --accent-warm: #f04467;
  --green: #0d8d73;
  --green-soft: #e6f6f2;
  --amber: #b56a00;
  --amber-soft: #fff2d9;
  --red: #c92f42;
  --red-soft: #fde8ec;
  --teal: #087f99;
  --shadow: 0 18px 50px rgba(5, 6, 47, 0.1);
  --topbar-bg: rgba(255, 255, 255, 0.96);
  --nav-bg: #f8f9ff;
  --soft-surface: #f8f9ff;
  --track: #e8ebf6;
  --neutral-fill: #eceef6;
  --neutral-text: #4b5067;
  --progress-empty: #e5e7eb;
  --card-shadow: 0 6px 24px rgba(5, 6, 47, 0.045);
  --primary-button: #15115f;
  --primary-button-hover: #4430c7;
  --auth-warm-glow: rgba(240, 68, 103, 0.11);
  --auth-cool-glow: rgba(6, 174, 232, 0.13);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #f7f8ff;
    --muted: #a9afcf;
    --line: #2a2e5f;
    --surface: #101335;
    --page: #070920;
    --page-start: #0b0d28;
    --primary: #9182ff;
    --primary-dark: #f7f8ff;
    --primary-soft: #171a49;
    --accent: #21d0ff;
    --accent-soft: #102b3d;
    --accent-warm: #ff5c7b;
    --green: #48d6b0;
    --green-soft: #123a35;
    --amber: #ffc15a;
    --amber-soft: #3a2a12;
    --red: #ff6477;
    --red-soft: #401b28;
    --teal: #21d0ff;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    --topbar-bg: rgba(7, 9, 32, 0.94);
    --nav-bg: #0d1030;
    --soft-surface: #151940;
    --track: #242a55;
    --neutral-fill: #1b1f44;
    --neutral-text: #a9afcf;
    --progress-empty: #202548;
    --card-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
    --primary-button: #4430c7;
    --primary-button-hover: #5f4de0;
    --auth-warm-glow: rgba(240, 68, 103, 0.18);
    --auth-cool-glow: rgba(6, 174, 232, 0.2);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f7f8ff;
  --muted: #a9afcf;
  --line: #2a2e5f;
  --surface: #101335;
  --page: #070920;
  --page-start: #0b0d28;
  --primary: #9182ff;
  --primary-dark: #f7f8ff;
  --primary-soft: #171a49;
  --accent: #21d0ff;
  --accent-soft: #102b3d;
  --accent-warm: #ff5c7b;
  --green: #48d6b0;
  --green-soft: #123a35;
  --amber: #ffc15a;
  --amber-soft: #3a2a12;
  --red: #ff6477;
  --red-soft: #401b28;
  --teal: #21d0ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --topbar-bg: rgba(7, 9, 32, 0.94);
  --nav-bg: #0d1030;
  --soft-surface: #151940;
  --track: #242a55;
  --neutral-fill: #1b1f44;
  --neutral-text: #a9afcf;
  --progress-empty: #202548;
  --card-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
  --primary-button: #4430c7;
  --primary-button-hover: #5f4de0;
  --auth-warm-glow: rgba(240, 68, 103, 0.18);
  --auth-cool-glow: rgba(6, 174, 232, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(180deg, var(--page-start) 0%, var(--page) 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0.7rem 0.8rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(6, 174, 232, 0.85);
  box-shadow: 0 0 0 3px rgba(6, 174, 232, 0.14);
  outline: none;
}

a:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(6, 174, 232, 0.28);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
}

.rich-text-source,
textarea.rich-text-source {
  display: none !important;
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  border: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.rich-text-editor {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.rich-text-editor .ql-toolbar.ql-snow {
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--soft-surface);
  color: var(--primary-dark);
}

.rich-text-editor .ql-container.ql-snow {
  min-height: 8rem;
  border: 0;
  background: var(--surface);
  color: var(--primary-dark);
  font: inherit;
}

.rich-text-editor .ql-editor {
  min-height: 8rem;
  color: var(--ink);
  font: inherit;
  overflow-wrap: anywhere;
}

.rich-text-editor .ql-editor.ql-blank::before {
  color: var(--muted);
  font-style: normal;
}

.rich-text-editor .ql-container.ql-snow:focus-within {
  box-shadow: inset 0 0 0 3px rgba(6, 174, 232, 0.14);
}

.rich-text-editor .ql-stroke {
  stroke: var(--primary-dark);
}

.rich-text-editor .ql-fill {
  fill: var(--primary-dark);
}

.rich-text-editor .ql-picker {
  color: var(--primary-dark);
}

.rich-text-editor .ql-toolbar button:hover .ql-stroke,
.rich-text-editor .ql-toolbar button:focus .ql-stroke,
.rich-text-editor .ql-toolbar button.ql-active .ql-stroke {
  stroke: var(--accent);
}

.rich-text-editor .ql-toolbar button:hover .ql-fill,
.rich-text-editor .ql-toolbar button:focus .ql-fill,
.rich-text-editor .ql-toolbar button.ql-active .ql-fill {
  fill: var(--accent);
}

.rich-text-content {
  overflow-wrap: anywhere;
}

.rich-text-content p,
.rich-text-content ul,
.rich-text-content ol {
  margin: 0 0 0.6rem;
}

.rich-text-content p:last-child,
.rich-text-content ul:last-child,
.rich-text-content ol:last-child {
  margin-bottom: 0;
}

.rich-text-content.compact {
  max-width: 28rem;
}

.rich-text-content.compact p,
.rich-text-content.compact ul,
.rich-text-content.compact ol {
  margin-bottom: 0.35rem;
}

.select-search {
  margin-bottom: 0.45rem;
}

.native-select-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  border: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.searchable-select {
  position: relative;
  width: 100%;
}

.select-display {
  position: relative;
  width: 100%;
  min-height: 2.95rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0.7rem 2.3rem 0.7rem 0.8rem;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-display::after {
  content: "";
  position: absolute;
  right: 0.9rem;
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
}

.select-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 0.55rem;
}

.select-menu .select-search {
  margin-bottom: 0.5rem;
}

.select-options {
  display: grid;
  gap: 0.25rem;
  max-height: 18rem;
  overflow-y: auto;
}

.select-option {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 0.55rem 0.65rem;
  text-align: left;
}

.select-option:hover,
.select-option[aria-selected="true"] {
  background: var(--primary-soft);
}

.select-empty {
  color: var(--muted);
  padding: 0.55rem 0.65rem;
}

label span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

label small {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.file-input-native {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  border: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.file-dropzone {
  display: grid;
  gap: 0.35rem;
  align-content: center;
  justify-items: center;
  min-height: 7rem;
  border: 1.5px dashed var(--line);
  border-radius: 8px;
  background: var(--soft-surface);
  color: var(--muted);
  cursor: pointer;
  padding: 1rem;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.file-dropzone:hover,
.file-dropzone:focus-visible,
.file-dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  outline: none;
}

.file-dropzone.has-file {
  border-color: var(--green);
  background: var(--green-soft);
}

.file-dropzone strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.95rem;
}

.file-dropzone span {
  display: block;
  margin: 0;
  color: inherit;
  font-size: 0.82rem;
  font-weight: 700;
}

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

th,
td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(250px, 0.75fr) minmax(360px, 1.55fr) minmax(220px, 0.8fr);
  align-items: center;
  gap: 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  padding: 0.85rem clamp(1rem, 3vw, 2rem);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
  color: var(--ink);
  font-weight: 800;
}

.brand:hover {
  text-decoration: none;
}

.brand img {
  display: block;
  width: auto;
  height: 3.2rem;
  border-radius: 8px;
  background: #fff;
  padding: 0.22rem;
  object-fit: contain;
}

.brand span {
  border-left: 1px solid var(--line);
  color: var(--primary-dark);
  padding-left: 0.8rem;
  line-height: 1.1;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--nav-bg);
}

.nav a,
.nav summary {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  border-radius: 6px;
  padding: 0.48rem 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.nav summary {
  cursor: pointer;
  list-style: none;
}

.nav summary::-webkit-details-marker {
  display: none;
}

.nav a.active,
.nav a:hover,
.nav summary.active,
.nav summary:hover {
  background: var(--surface);
  color: var(--primary-dark);
  text-decoration: none;
  box-shadow: 0 1px 8px rgba(5, 6, 47, 0.08);
}

.nav a.nav-attention {
  background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft));
  color: var(--primary-dark);
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: linear-gradient(135deg, var(--accent-warm), var(--amber));
  color: #fff;
  font-size: 0.75rem;
  font-weight: 900;
  line-height: 1;
  padding: 0 0.4rem;
  box-shadow: 0 0 0 3px rgba(240, 68, 103, 0.18), 0 8px 18px rgba(240, 68, 103, 0.35);
}

.nav-menu {
  position: relative;
}

.nav-dropdown {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 5;
  display: grid;
  min-width: 180px;
  gap: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 0.35rem;
}

.nav-dropdown a {
  display: block;
}

.user-menu {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft-surface);
  color: var(--ink);
  cursor: pointer;
  padding: 0.48rem 0.78rem;
  font-weight: 800;
}

.theme-toggle:hover {
  border-color: rgba(6, 174, 232, 0.55);
  color: var(--primary-dark);
}

.auth-theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 3;
}

.app-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.breadcrumbs a {
  color: var(--muted);
  font-weight: 750;
}

.breadcrumbs a[aria-current="page"] {
  color: var(--ink);
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 2rem;
  background:
    linear-gradient(135deg, var(--auth-warm-glow), transparent 44%),
    linear-gradient(315deg, var(--auth-cool-glow), transparent 44%),
    linear-gradient(180deg, var(--page-start) 0%, var(--page) 100%);
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.login-brand {
  display: grid;
  justify-items: start;
  gap: 0.2rem;
}

.login-brand img {
  width: 9.4rem;
  height: auto;
  margin-bottom: 0.9rem;
  border-radius: 8px;
  background: #fff;
  padding: 0.3rem;
}

.login-panel h1,
.page-heading h1 {
  margin: 0;
  font-size: clamp(1.75rem, 2.5vw, 2.5rem);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--accent-warm);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page-heading,
.section-title,
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.page-heading {
  margin-bottom: 1.5rem;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.65rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 1rem;
  border-bottom: 1px solid var(--line);
}

.tab-link {
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  padding: 0.65rem 0.9rem;
  font-weight: 800;
}

.tab-link:hover {
  color: var(--ink);
  text-decoration: none;
}

.tab-link.active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.catalog-panel {
  display: grid;
  gap: 1rem;
}

.billing-filter-panel {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 1.1fr) auto;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.billing-period-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.billing-type-fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

.billing-type-fieldset legend {
  width: 100%;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.billing-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  width: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--page);
  color: var(--ink);
  padding: 0.55rem 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}

.billing-toggle input {
  width: auto;
  accent-color: var(--primary);
}

.billing-filter-actions {
  display: flex;
  justify-content: flex-end;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.section-title {
  margin: 0 0 0.8rem;
}

.section-title h2,
.workflow-panel h2,
.notes h3,
.history h3 {
  margin: 0;
  font-size: 1.05rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 0.58rem 0.9rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover {
  text-decoration: none;
}

.button.primary {
  background: var(--primary-button);
  color: #fff;
  box-shadow: 0 8px 18px rgba(21, 17, 95, 0.18);
}

.button.primary:hover {
  background: var(--primary-button-hover);
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button.subtle {
  border-color: var(--line);
  background: var(--soft-surface);
  color: var(--ink);
}

.button.success {
  background: var(--green);
  color: #fff;
}

.button.warning {
  background: var(--amber);
  color: #fff;
}

.button.danger {
  background: var(--red);
  color: #fff;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.6rem;
}

.metric,
.detail-panel,
.workflow-panel,
.analytics-band,
.table-wrap,
.action-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.metric {
  padding: 1rem;
}

.metric span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 0.35rem;
  font-size: clamp(1.45rem, 2vw, 2rem);
  line-height: 1.15;
}

.metric small {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
}

.metric-link {
  color: inherit;
  text-decoration: none;
}

.metric-link:hover {
  border-color: rgba(6, 174, 232, 0.4);
  text-decoration: none;
}

.metric.warning strong {
  color: var(--amber);
}

.metric.success strong {
  color: var(--green);
}

.volume-progress {
  width: min(100%, 14rem);
  height: 0.55rem;
  margin-top: 0.55rem;
  border-radius: 999px;
  background: var(--progress-empty);
  overflow: hidden;
}

.volume-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a1a7b8 0%, var(--primary) 100%);
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.entity-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.entity-logo {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  object-fit: contain;
}

.entity-logo.placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--soft-surface);
  font-weight: 850;
  text-transform: uppercase;
}

.logo-preview {
  display: block;
  width: 5rem;
  height: 5rem;
  margin-top: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  object-fit: contain;
}

.detail-identity {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.detail-logo {
  flex: 0 0 auto;
  width: 4rem;
  height: 4rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  object-fit: contain;
}

.split-layout,
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.8fr);
  gap: 1.25rem;
  margin-bottom: 1.6rem;
}

.table-wrap {
  overflow-x: auto;
}

.table-wrap.action-menu-open {
  overflow: visible;
}

.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.table-filter {
  max-width: 280px;
}

.column-filter-row th {
  padding-top: 0;
}

.column-filter-row input {
  min-width: 8rem;
  padding: 0.48rem 0.55rem;
  font-size: 0.82rem;
  text-transform: none;
}

.table-actions,
.table-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.table-actions {
  justify-content: flex-end;
}

.table-aggregation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.table-aggregation label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 750;
}

.table-aggregation input {
  width: auto;
}

.table-aggregation select {
  width: auto;
  min-width: 104px;
  padding: 0.45rem 0.55rem;
}

.row-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
}

.row-check input {
  width: 1.05rem;
  height: 1.05rem;
}

.table-pagination {
  color: var(--muted);
  font-size: 0.9rem;
}

.table-pagination select {
  width: auto;
  min-width: 72px;
  padding: 0.45rem 0.55rem;
}

.aggregate-row td {
  border-top: 2px solid var(--line);
  background: var(--soft-surface);
  font-weight: 850;
}

.aggregate-row .aggregate-label {
  color: var(--muted);
}

.aggregate-row .aggregate-value {
  color: var(--ink);
}

.table-details summary {
  cursor: pointer;
  color: var(--primary-dark);
  font-weight: 800;
}

.table-details p {
  max-width: 42rem;
  margin: 0.45rem 0 0;
  color: var(--ink);
  white-space: pre-wrap;
}

.action-cell {
  position: relative;
  width: 1%;
  min-width: 3.25rem;
  vertical-align: top;
  white-space: nowrap;
}

.inline-row-actions {
  display: block;
  margin: 0;
}

.row-action-menu {
  position: relative;
  display: inline-block;
}

.row-action-menu summary {
  list-style: none;
}

.row-action-menu summary::-webkit-details-marker {
  display: none;
}

.row-action-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.45rem;
  height: 2.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  line-height: 1;
}

.row-action-menu[open] .row-action-trigger,
.row-action-trigger:hover {
  border-color: rgba(6, 174, 232, 0.5);
  background: var(--soft-surface);
}

.row-action-list {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 40;
  display: grid;
  gap: 0.35rem;
  min-width: 11rem;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.row-action-list .button,
.row-action-list button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.sortable-heading {
  cursor: pointer;
  user-select: none;
}

.sortable-heading::after {
  content: " \2195";
  color: var(--muted);
  font-size: 0.72rem;
}

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

.action-list {
  display: grid;
  gap: 0.7rem;
}

.flash {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  font-weight: 750;
}

.flash.error {
  border-color: rgba(240, 68, 103, 0.35);
  background: var(--red-soft);
  color: var(--red);
}

.action-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  padding: 0.85rem;
}

.action-item.stacked {
  align-items: flex-start;
  flex-direction: column;
}

.action-item span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.6rem;
}

.table-chips {
  margin-top: 0.45rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft-surface);
  color: var(--ink);
  padding: 0.18rem 0.62rem;
  font-size: 0.82rem;
  font-weight: 750;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  border-radius: 999px;
  padding: 0.18rem 0.62rem;
  font-size: 0.82rem;
  font-weight: 800;
}

.status.open {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.status.overdue {
  background: var(--red-soft);
  color: var(--red);
}

.status.reminder {
  background: var(--amber-soft);
  color: var(--amber);
}

.status.paid {
  background: var(--green-soft);
  color: var(--green);
}

.status.cancelled {
  background: var(--neutral-fill);
  color: var(--neutral-text);
}

.status.active,
.status.finalized,
.status.approved {
  background: var(--green-soft);
  color: var(--green);
}

.status.draft,
.status.submitted,
.status.pending {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.status.paused {
  background: var(--amber-soft);
  color: var(--amber);
}

.status.rejected {
  background: var(--red-soft);
  color: var(--red);
}

.status.ended,
.status.inactive,
.status.billed,
.status.not_applicable {
  background: var(--neutral-fill);
  color: var(--neutral-text);
}

.analytics-band {
  margin-bottom: 1.6rem;
  padding: 1rem;
}

.analytics-band[id] {
  scroll-margin-top: 6.5rem;
}

.notification-panel {
  display: grid;
  gap: 1rem;
}

.notification-list {
  display: grid;
  gap: 0.75rem;
}

.notification-list.compact {
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.notification-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: var(--soft-surface);
  padding: 0.85rem;
}

.notification-item.reminder {
  border-left-color: var(--amber);
}

.notification-item.overdue {
  border-left-color: var(--red);
}

.notification-item.acknowledged {
  border-left-color: var(--neutral-text);
  opacity: 0.82;
}

.notification-item h3 {
  margin: 0.45rem 0 0.2rem;
  font-size: 1rem;
}

.notification-item p {
  margin: 0;
  color: var(--ink);
}

.notification-item small {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
}

.notification-item form {
  flex: 0 0 auto;
}

.notification-history summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 360px;
}

.chart-canvas-wrap.tall {
  height: 420px;
}

.chart-canvas-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.chart-layout {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(220px, 1fr);
  align-items: center;
  gap: 1.4rem;
}

.pie-chart {
  position: relative;
  display: grid;
  width: min(240px, 100%);
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  background:
    conic-gradient(
      rgba(68, 48, 199, 0.88) 0 var(--license-share),
      rgba(6, 174, 232, 0.82) var(--license-share) var(--service-end),
      rgba(240, 68, 103, 0.82) var(--service-end) var(--variable-end),
      rgba(0, 179, 147, 0.82) var(--variable-end) 100%
    );
}

.pie-chart.empty-chart {
  background: var(--track);
}

.pie-chart::after {
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: var(--surface);
  content: "";
}

.pie-chart span {
  position: relative;
  z-index: 1;
  font-weight: 900;
  text-align: center;
}

.chart-legend {
  display: grid;
  gap: 0.8rem;
}

.chart-legend article {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.chart-legend strong,
.chart-legend span {
  display: block;
}

.chart-legend span,
.chart-bar-label span {
  color: var(--muted);
  font-size: 0.9rem;
}

.legend-dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 999px;
}

.legend-dot.license {
  background: rgba(68, 48, 199, 0.88);
}

.legend-dot.service {
  background: rgba(6, 174, 232, 0.82);
}

.legend-dot.variable {
  background: rgba(240, 68, 103, 0.82);
}

.legend-dot.flat-fee {
  background: rgba(0, 179, 147, 0.82);
}

.chart-bars {
  display: grid;
  gap: 0.8rem;
}

.chart-bar-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(180px, 1.5fr) minmax(110px, auto);
  align-items: center;
  gap: 0.85rem;
}

.chart-bar-label strong,
.chart-bar-label span {
  display: block;
}

.chart-bar-track {
  position: relative;
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--track);
}

.chart-bar-track i {
  position: absolute;
  inset: 0 auto 0 0;
  min-width: 2px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.chart-bar-row > strong {
  text-align: right;
}

.bar-list {
  display: grid;
  gap: 0.65rem;
}

.bar-list.compact {
  max-height: 420px;
  overflow: auto;
}

.bar-row {
  display: grid;
  grid-template-columns: 74px minmax(120px, 1fr) minmax(110px, auto);
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.bar-row strong {
  color: var(--ink);
  text-align: right;
}

.bar-track {
  position: relative;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--track);
}

.bar-track.slim {
  height: 7px;
  margin-bottom: 0.35rem;
}

.bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  min-width: 2px;
  border-radius: inherit;
}

.bar.issued {
  background: rgba(68, 48, 199, 0.78);
}

.bar.paid {
  height: 50%;
  top: 50%;
  background: rgba(6, 174, 232, 0.82);
}

.filter-bar,
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.filter-bar {
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) auto;
}

.form-grid {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1rem;
}

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

.span-2 {
  grid-column: span 2;
}

.span-full {
  grid-column: 1 / -1;
}

.sectioned-form {
  align-items: stretch;
}

.form-section {
  display: grid;
  gap: 0.85rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.form-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.form-section-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  align-items: end;
}

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

.form-section-title {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.required-marker {
  color: var(--danger);
  font-weight: 900;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.billing-actions {
  margin-top: 1rem;
}

.billing-group {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.billing-group + .billing-group {
  margin-top: 1.25rem;
}

.billing-group h3 {
  margin: 0;
  font-size: 1rem;
}

.billing-group-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 0.8rem;
  cursor: pointer;
  list-style: none;
}

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

.billing-group-summary::before {
  content: "+";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 1.65rem;
  height: 1.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-weight: 900;
}

.billing-group[open] .billing-group-summary::before {
  content: "-";
}

.billing-group-summary > div {
  flex: 1 1 auto;
}

.billing-group-summary > strong {
  white-space: nowrap;
}

.billing-group-body {
  display: grid;
  gap: 1rem;
}

.field-hint {
  display: block;
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.45rem;
}

.checkbox-label input {
  width: auto;
}

.checkbox-label span {
  margin: 0;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.6rem;
}

.checkbox-field input {
  width: auto;
}

.generated-secret {
  border-color: rgba(6, 174, 232, 0.45);
}

.secret-value {
  display: block;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-surface);
  padding: 0.75rem;
  color: var(--ink);
  overflow-wrap: anywhere;
  user-select: all;
}

.permission-matrix th,
.permission-matrix td {
  min-width: 132px;
  text-align: center;
  vertical-align: middle;
}

.permission-matrix .role-cell {
  left: 0;
  min-width: 210px;
  position: sticky;
  z-index: 1;
  background: var(--surface);
  text-align: left;
}

.matrix-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
}

.matrix-check input {
  width: 1.05rem;
  height: 1.05rem;
}

.inline-form,
.mini-form {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.inline-form {
  grid-template-columns: minmax(160px, 240px) minmax(160px, 1fr) auto;
  align-items: end;
}

.mini-form {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
}

.pdf-viewer {
  width: 100%;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-surface);
}

.detail-panel,
.workflow-panel {
  padding: 1rem;
}

.contract-overview-panel {
  margin-bottom: 1.6rem;
}

.detail-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.detail-header h2 {
  margin: 0.5rem 0 0;
  font-size: 1.3rem;
}

.detail-header strong {
  font-size: 1.45rem;
}

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

.detail-grid dt {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 0.2rem 0 0;
  overflow-wrap: anywhere;
}

.notes {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.notes p {
  margin-bottom: 0;
  white-space: pre-wrap;
}

.history {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.status-history {
  display: grid;
  gap: 0.9rem;
  margin: 0.8rem 0 0;
  padding: 0;
  list-style: none;
}

.status-history li {
  position: relative;
  border-left: 3px solid var(--line);
  padding-left: 0.85rem;
}

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.history-head time,
.status-history p,
.history-start,
.transition-arrow {
  color: var(--muted);
  font-size: 0.88rem;
}

.history-transition {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.history-start {
  font-weight: 800;
}

.status-history p {
  margin: 0.4rem 0 0;
}

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

.workflow-actions {
  display: grid;
  gap: 0.65rem;
}

.stack {
  display: grid;
  gap: 1rem;
}

.datev-finalize-form {
  margin-top: 1rem;
}

.compact-detail-grid {
  margin-top: 1rem;
}

.alert {
  border: 1px solid var(--red);
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  padding: 0.75rem 0.9rem;
}

.success-alert {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  margin-bottom: 1rem;
}

.year-picker {
  min-width: 140px;
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
  }

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

  .nav-dropdown {
    position: static;
    margin-top: 0.35rem;
    box-shadow: none;
  }

  .metric-grid,
  .split-layout,
  .detail-layout,
  .billing-filter-panel,
  .billing-period-fields,
  .form-grid,
  .filter-bar,
  .chart-layout,
  .chart-bar-row,
  .inline-form,
  .mini-form {
    grid-template-columns: 1fr;
  }

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

  .span-2,
  .span-full {
    grid-column: auto;
  }

  .page-heading,
  .section-title,
  .detail-header,
  .history-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-actions {
    justify-content: flex-start;
  }

  .notification-item {
    flex-direction: column;
  }

  .notification-item form,
  .notification-item .button {
    width: 100%;
  }

  .chart-canvas-wrap,
  .chart-canvas-wrap.tall {
    height: 320px;
  }

  .bar-row {
    grid-template-columns: 64px 1fr;
  }

  .bar-row strong {
    grid-column: 2;
    text-align: left;
  }

  .chart-bar-row > strong {
    text-align: left;
  }
}
