:root {
  color-scheme: light;
  --bg: #eef6f9;
  --panel: #ffffff;
  --panel-tint: #f7fbfd;
  --text: #183447;
  --muted: #62788a;
  --line: #d8e7ef;
  --accent: #009bd3;
  --accent-dark: #005c82;
  --accent-soft: #e1f6fc;
  --accent-soft-strong: #bcecf8;
  --danger: #b42318;
  --warning: #b95f00;
  --success: #087f8c;
  --shadow: 0 14px 38px rgba(24, 52, 71, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #dff4fb 0, var(--bg) 240px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(24, 52, 71, 0.06);
  backdrop-filter: blur(14px);
  display: flex;
  gap: 32px;
  justify-content: space-between;
  padding: 14px 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  align-items: center;
  color: var(--accent-dark);
  display: inline-flex;
  gap: 12px;
  font-weight: 800;
  text-decoration: none;
}

.brand img {
  display: block;
  height: 34px;
  width: auto;
}

.brand span {
  border-left: 1px solid #c6dce7;
  color: #183447;
  line-height: 1;
  padding-left: 12px;
}

nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

nav a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

nav a:hover,
.section-heading a:hover {
  color: var(--accent-dark);
}

.logout-form {
  display: block;
}

.main-navigation { flex-wrap: nowrap; gap: 4px; }
.main-navigation > a, .navigation-dropdown > summary {
  border-radius: 6px; padding: 10px 12px; white-space: nowrap;
  color: var(--muted); font-size: 14px; font-weight: 650;
}
.main-navigation a[aria-current="page"], .navigation-dropdown.has-current-page > summary {
  background: var(--accent-soft); color: var(--accent-dark);
}
.main-navigation > a:hover, .navigation-dropdown > summary:hover { background: var(--panel-tint); }
.navigation-dropdown { position: relative; }
.navigation-dropdown > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 9px; }
.navigation-dropdown > summary::-webkit-details-marker { display: none; }
.navigation-dropdown > summary::after { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-top: -3px; }
.navigation-dropdown[open] > summary::after { transform: rotate(225deg); margin-top: 3px; }
.navigation-menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 230px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 6px; display: grid; gap: 2px;
}
.navigation-menu a, .navigation-menu .link-button { display: block; padding: 11px 12px; width: 100%; text-align: left; border-radius: 4px; font-size: 14px; font-weight: 650; box-shadow: none; }
.navigation-menu a:hover, .navigation-menu .link-button:hover { background: var(--accent-soft); color: var(--accent-dark); }
.navigation-account { border-left: 1px solid var(--line); margin-left: 8px; padding-left: 8px; }
.navigation-toggle { display: none; }

.group-reminder-link { margin-top: 8px; }
.group-reminder-header, .group-batch-invoices, .group-mail-preview, .group-pdf-preview { margin: 24px 0; }
.group-step-picker { display: flex; align-items: end; gap: 12px; max-width: 540px; }
.group-step-picker label { display: block; margin-bottom: 6px; }
.group-step-picker > div { flex: 1; min-width: 0; }
.group-info-option { display: flex; align-items: center; gap: 10px; margin: 20px 0; }
.group-selection-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); padding: 20px 0; }
.group-row-email { display: block; color: var(--muted); overflow-wrap: anywhere; }
.group-delivery-summary { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 24px; padding: 20px 0; border-block: 1px solid var(--line); }
.group-delivery-summary span, .group-delivery-summary small { display: block; color: var(--muted); margin-bottom: 6px; }
.group-delivery-summary strong { display: block; margin-bottom: 8px; font-size: 20px; overflow-wrap: anywhere; }
.group-mail-preview dl { display: grid; grid-template-columns: 100px minmax(0,1fr); gap: 12px; }
.group-mail-preview dd { margin: 0; overflow-wrap: anywhere; }
.group-mail-preview pre { background: var(--panel); border: 1px solid var(--line); padding: 20px; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; font-size: 14px; line-height: 1.6; }
.group-resolution { border-top: 1px solid var(--line); padding: 24px 0; }
.group-resolution form { display: grid; gap: 16px; max-width: 550px; }
.group-resolution label { display: block; }
#group-pdf-pages { width: 100%; max-height: 850px; overflow: auto; background: #e3ebef; padding: 12px; border: 1px solid var(--line); border-radius: 6px; }
#group-pdf-pages canvas { display: block; max-width: 100%; height: auto; margin: 0 auto 16px; background: white; }
.group-invoice-table input[type="checkbox"], .group-info-option input[type="checkbox"], .group-send-confirmation input[type="checkbox"], .group-resolution input[type="checkbox"] { width: 18px; height: 18px; min-height: 18px; padding: 0; margin: 0; flex: 0 0 18px; }
.group-invoice-table td:first-child, .group-invoice-table th:first-child { width: 70px; text-align: center; }
.group-send-confirmation { border-top: 1px solid var(--line); padding: 24px 0; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.group-send-confirmation label { display: flex; align-items: center; gap: 10px; }
@media (max-width: 700px) {
  .group-selection-footer, .group-send-confirmation, .group-step-picker { flex-direction: column; align-items: stretch; }
  .group-delivery-summary { grid-template-columns: 1fr; }
  #group-pdf-pages { max-height: 550px; }
}

.revenue-year-form { min-width: 190px; }
.revenue-year-form > div { display: flex; gap: 8px; margin-top: 6px; }
.revenue-year-form select { min-width: 100px; }
.revenue-kpis .kpi-card { min-width: 0; }
.revenue-kpis .kpi-card strong { font-size: 28px; overflow-wrap: anywhere; }
.revenue-target-section, .revenue-chart-section, .revenue-month-section, .revenue-customer-section, .revenue-source {
  padding: 24px 0; border-top: 1px solid var(--line); margin-top: 20px;
}
.revenue-warning { border-left: 3px solid var(--warning); padding: 4px 16px; background: #fff5e6; margin-bottom: 20px; }
.revenue-warning p { margin: 8px 0; font-size: 14px; }
.revenue-progress { height: 14px; position: relative; background: var(--line); border-radius: 4px; margin: 24px 0; }
.revenue-progress > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.revenue-progress > i { position: absolute; top: -5px; bottom: -5px; border-left: 2px solid var(--text); }
.revenue-target-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 20px; }
.revenue-target-metrics span { display: block; color: var(--muted); font-size: 14px; }
.revenue-target-metrics strong { display: block; margin-top: 6px; font-size: 22px; overflow-wrap: anywhere; }
.revenue-negative { color: var(--danger); }
.revenue-target-editor { margin-top: 20px; }
.revenue-target-editor summary { cursor: pointer; font-weight: 650; }
.revenue-target-editor form { display: flex; align-items: end; gap: 12px; margin-top: 16px; max-width: 540px; }
.revenue-target-editor form > div { flex: 1; min-width: 0; }
.revenue-target-editor label { display: block; margin-bottom: 6px; }
.revenue-chart { margin-top: 24px; }
.revenue-chart-scale { margin: 0 150px 12px 60px; display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.revenue-chart-row { display: grid; grid-template-columns: 48px minmax(0,1fr) 138px; align-items: center; gap: 12px; margin: 12px 0; min-height: 30px; }
.revenue-month-label { font-size: 14px; color: var(--muted); }
.revenue-chart-track { height: 30px; position: relative; background: rgba(255,255,255,.6); }
.revenue-zero { position: absolute; height: 100%; border-left: 1px solid #9eb6c4; }
.revenue-bar { position: absolute; height: 11px; min-width: 0; border-radius: 0 2px 2px 0; }
.revenue-bar.current { top: 2px; background: var(--accent); }
.revenue-bar.previous { bottom: 2px; background: #859ba8; }
.revenue-bar.negative { background: var(--danger); }
.revenue-target-marker { position: absolute; height: 100%; border-left: 2px dashed #b95f00; z-index: 1; }
.revenue-chart-value { font-variant-numeric: tabular-nums; font-size: 14px; text-align: right; white-space: nowrap; }
.revenue-legend { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 20px; font-size: 13px; color: var(--muted); }
.revenue-legend span { display: inline-flex; align-items: center; gap: 7px; }
.revenue-legend i { display: inline-block; width: 14px; height: 8px; background: var(--accent); }
.revenue-legend i.previous { background: #859ba8; }
.revenue-legend i.target { background: none; border-top: 2px dashed #b95f00; height: 0; }
.revenue-table td, .revenue-table th:not(:first-child), .revenue-customer-table td:not(:first-child), .revenue-customer-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.revenue-table tfoot { background: var(--panel-tint); font-weight: 750; }
.revenue-future { color: var(--muted); }
.revenue-source { color: var(--muted); font-size: 14px; line-height: 1.6; }
.revenue-source h2 { font-size: 17px; color: var(--text); }
@media (max-width: 600px) {
  .revenue-target-metrics { grid-template-columns: 1fr; }
  .revenue-target-editor form { align-items: stretch; flex-direction: column; }
  .revenue-chart-row { grid-template-columns: 28px minmax(0,1fr) 104px; gap: 8px; }
  .revenue-chart-value { font-size: 12px; }
  .revenue-chart-scale { margin-right: 112px; margin-left: 36px; font-size: 11px; }
  .revenue-year-form { width: 100%; }
  .revenue-kpis .kpi-card strong { font-size: 26px; }
}
.brand img { max-width: 180px; object-fit: contain; }
.brand-company { max-width: 220px; overflow-wrap: anywhere; }
.main-navigation :focus-visible, .navigation-toggle:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 2px; }

@media (max-width: 1150px) {
  .topbar { flex-wrap: wrap; gap: 12px; flex-direction: row; align-items: center; padding: 12px 20px; }
  .navigation-toggle { display: block; background: var(--panel-tint); border: 1px solid var(--line); color: var(--text); box-shadow: none; min-height: 40px; padding: 8px 14px; }
  .main-navigation { display: none; width: 100%; max-height: calc(100dvh - 100px); overflow-y: auto; align-items: stretch; gap: 4px; padding-top: 10px; border-top: 1px solid var(--line); }
  .main-navigation.is-open { display: flex; flex-direction: column; }
  .navigation-menu { position: static; min-width: 0; box-shadow: none; border: 0; border-left: 2px solid var(--line); border-radius: 0; margin: 4px 12px; }
  .navigation-account { border-left: 0; border-top: 1px solid var(--line); margin: 4px 0 0; padding: 4px 0 0; }
  .brand { gap: 8px; min-width: 0; max-width: calc(100% - 80px); }
  .brand img { max-width: 125px; height: 30px; }
  .brand-company { max-width: 145px; font-size: 13px; }
  .brand span { font-size: 14px; padding-left: 8px; }
}

.link-button {
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  min-height: 0;
  padding: 0;
}

.login-body {
  align-items: center;
  display: flex;
  min-height: 100vh;
  justify-content: center;
}

.login-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 440px;
  padding: 34px;
  text-align: center;
}

.login-logo {
  display: block;
  margin: 0 auto 24px;
  max-width: 260px;
  width: 100%;
  height: 96px;
  object-fit: contain;
}

.login-card p {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 22px;
}

.login-button {
  justify-content: center;
  width: 100%;
}

.login-form {
  display: grid;
  gap: 10px;
  text-align: left;
}

.login-form .login-button {
  margin-top: 8px;
}

main {
  margin: 0 auto;
  max-width: 1320px;
  padding: 28px;
}

.page-title {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 22px;
}

h1,
h2 {
  line-height: 1.2;
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

.page-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.kpi-grid,
.stats-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 26px;
}

.stat,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.stat span,
.detail span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.stat strong {
  display: block;
  font-size: 28px;
  margin-top: 8px;
}

.kpi-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 251, 253, 0.98));
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: inherit;
  display: grid;
  gap: 8px;
  min-height: 132px;
  padding: 18px;
  text-decoration: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.kpi-card:hover,
.aging-bucket:hover,
.attention-item:hover {
  border-color: #9fdceb;
  transform: translateY(-1px);
}

.kpi-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-card strong {
  font-size: 28px;
  line-height: 1.05;
}

.kpi-card em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.kpi-card.primary {
  border-left-color: var(--accent);
}

.kpi-card.danger {
  border-left-color: var(--danger);
}

.kpi-card.warning {
  border-left-color: var(--warning);
}

.kpi-card.success {
  border-left-color: #3fb6d8;
}

.aging-panel {
  margin-bottom: 26px;
}

.followup-panel {
  margin-bottom: 26px;
}

.followup-grid {
  display: grid;
  align-items: start;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.followup-card {
  background: var(--panel-tint);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
}

.followup-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.followup-heading h3 { font-size: 15px; line-height: 24px; margin: 0; }
.followup-more { margin-top: 12px; }
.followup-more > summary {
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  min-height: 24px;
  line-height: 24px;
  list-style-position: inside;
}
.followup-more > summary::marker { color: var(--accent-dark); }
.followup-more > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.followup-more[open] > summary { margin-bottom: 12px; }
.followup-more .followup-less-label { display: none; }
.followup-more[open] .followup-more-label { display: none; }
.followup-more[open] .followup-less-label { display: inline; }
.followup-count { flex-shrink: 0; font-size: 12px; font-weight: 400; color: var(--muted); }
.followup-history-link { display: inline-block; font-size: 13px; margin-top: 14px; }
.reminder-stage-editor { margin-top: 12px; font-size: 13px; }
.reminder-stage-editor > summary { cursor: pointer; color: var(--muted); }
.reminder-stage-editor > form { margin-top: 10px; }
.row-actions > .reminder-stage-editor { flex-basis: 100%; order: 2; }
.invoice-history > div { min-width: 0; }

.followup-list {
  display: grid;
  gap: 8px;
}

.followup-item {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 10px;
  text-decoration: none;
}

.followup-item:hover {
  border-color: #9fdceb;
}

.followup-item strong,
.followup-item em,
.followup-meta small {
  display: block;
}

.followup-item em,
.followup-meta small {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  margin-top: 3px;
}

.followup-meta {
  text-align: right;
}

.compact-empty {
  margin: 0;
  padding: 10px;
}

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

.invoice-export-heading { flex-wrap: wrap; align-items: center; }
.invoice-export-heading .button { max-width: 100%; text-align: center; }
.brand span { overflow-wrap: anywhere; min-width: 0; line-height: 1.2; }

@media (max-width: 700px) {
  .brand { flex-direction: column; align-items: flex-start; gap: 4px; }
  .brand span { border-left: 0; padding-left: 0; white-space: nowrap; }
  .page-title .filters { flex-wrap: wrap; width: 100%; }
  .page-title .filters input { flex: 1 1 100%; min-width: 0; }
  .page-title .filters select { flex: 1 1 150px; min-width: 0; width: auto; }
}

.section-heading span,
.muted-line {
  color: var(--muted);
  font-size: 13px;
}

.aging-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.aging-bucket {
  background: var(--panel-tint);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  display: grid;
  gap: 6px;
  padding: 14px;
  text-decoration: none;
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.aging-bucket span {
  color: var(--muted);
  font-size: 13px;
}

.aging-bucket strong {
  font-size: 24px;
}

.aging-bucket em {
  color: var(--accent-dark);
  font-style: normal;
  font-weight: 700;
}

.muted-line {
  margin: 12px 0 0;
}

.split,
.detail-grid,
.dashboard-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-grid {
  grid-template-columns: 1fr 1fr 1fr;
  margin-bottom: 24px;
}

.dashboard-grid {
  margin-bottom: 26px;
}

.attention-list {
  display: grid;
  gap: 10px;
}

.attention-item {
  align-items: center;
  background: var(--panel-tint);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto minmax(120px, auto);
  padding: 12px;
  text-decoration: none;
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.attention-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.attention-item strong {
  font-size: 20px;
}

.attention-item em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  text-align: right;
}

.attention-item.needs-attention {
  border-color: #f8cc7a;
  background: #fff8e8;
}

.import-status {
  display: grid;
  gap: 14px;
}

.import-status > strong {
  word-break: break-word;
}

.import-status dl {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
}

.import-status div {
  background: var(--panel-tint);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.import-status dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.import-status dd {
  margin: 4px 0 0;
  font-weight: 700;
}

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

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

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

.subtle {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

th {
  background: #f4fafc;
  color: #4f6879;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

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

.badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 9px;
}

.badge.success {
  background: #d9f5f8;
  color: var(--success);
}

.badge.warning {
  background: #fef0c7;
  color: var(--warning);
}

.badge.danger {
  background: #fee4e2;
  color: var(--danger);
}

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

button,
.button {
  align-items: center;
  background: linear-gradient(180deg, #08a8df, var(--accent));
  border: 0;
  border-radius: 6px;
  box-shadow: 0 8px 18px rgba(0, 92, 130, 0.16);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  min-height: 38px;
  padding: 8px 12px;
  text-decoration: none;
  transition: filter 0.16s ease, transform 0.16s ease;
}

button.secondary,
.button.secondary {
  background: #e8f4f8;
  box-shadow: none;
  color: var(--text);
}

button:hover,
.button:hover {
  filter: brightness(0.98);
}

button:active,
.button:active {
  transform: translateY(1px);
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

label {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}

form {
  display: grid;
  gap: 10px;
}

.settings-panel fieldset {
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
  margin: 8px 0;
  min-width: 0;
  padding: 14px;
}

.settings-panel legend {
  font-weight: 700;
}

.switch-label {
  align-items: center;
  display: flex;
  gap: 12px;
  font-weight: 700;
}

.switch-label input {
  appearance: none;
  background: #cbd5db;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  height: 28px;
  min-height: 28px;
  padding: 0;
  position: relative;
  width: 48px;
  flex: 0 0 48px;
}

.switch-label input::after {
  background: white;
  border-radius: 50%;
  content: "";
  height: 22px;
  left: 3px;
  position: absolute;
  top: 3px;
  transition: transform 0.15s;
  width: 22px;
}

.switch-label input:checked { background: var(--accent); }
.switch-label input:checked::after { transform: translateX(20px); }

#auto-send-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 440px;
  padding: 24px;
  width: calc(100% - 32px);
}

#auto-send-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

.filters,
.inline-form {
  align-items: center;
  display: flex;
  gap: 10px;
}

.test-mail-actions {
  display: grid;
  gap: 10px;
}

.test-mail-actions form {
  display: block;
}

.test-mail-actions button {
  justify-content: center;
  width: 100%;
}

.row-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-actions form {
  display: block;
}

.reminder-step-form {
  display: grid;
  gap: 8px;
  min-width: 260px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button-row button {
  flex: 1 1 120px;
  justify-content: center;
}

.filters input {
  min-width: 240px;
}

.detail {
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
}

.detail:last-child {
  border-bottom: 0;
}

.notice {
  background: #fef0c7;
  border-radius: 6px;
  color: var(--warning);
  font-weight: 700;
  margin-top: 0;
  padding: 10px;
}

.success-notice {
  background: #d9f5f8;
  color: var(--success);
}

.safe-mail-notice {
  background: #e1f6fc;
  border: 1px solid #9fdceb;
  color: var(--accent-dark);
}

.settings-panel {
  max-width: 720px;
}

.settings-title { margin-bottom: 24px; }
.brand-workspace { display: grid; grid-template-columns: minmax(320px, 0.85fr) minmax(0, 1.4fr); gap: 32px; align-items: start; }
.brand-editor { background: white; padding: 0 22px; border-top: 1px solid var(--line); }
.brand-field-pair, .brand-color-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-top: 16px; }
.brand-field-pair + .settings-field { margin-top: 16px; }
.brand-editor .brand-field-pair .settings-field,
.brand-editor .brand-color-row .settings-field { margin-top: 0; }
.brand-color-row input { width: 64px; height: 40px; padding: 4px; }
.brand-logo-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 80px; margin-bottom: 14px; }
.brand-logo-row img { max-width: 160px; max-height: 70px; object-fit: contain; }
.brand-logo-row button { font-size: 12px; }
.brand-editor textarea { min-height: 130px; font-size: 13px; line-height: 1.6; }
.template-edit-panel textarea { min-height: 280px; }
.placeholder-toolbar { display: flex; gap: 8px; margin: 16px 0; }
.placeholder-toolbar select { min-width: 0; }
.placeholder-toolbar button { flex-shrink: 0; font-size: 12px; }
.branding-title { position: sticky; top: 64px; z-index: 4; background: var(--bg); padding: 12px 0; }
.brand-preview { position: sticky; top: 160px; min-width: 0; }
.brand-preview .settings-heading { margin-bottom: 12px; }
.brand-preview .settings-heading > span { max-width: 60%; text-align: right; overflow-wrap: anywhere; }
.preview-toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.preview-tabs { display: flex; border: 1px solid var(--line); border-radius: 6px; padding: 3px; background: white; gap: 3px; }
.preview-tabs button { min-width: 70px; min-height: 32px; box-shadow: none; background: transparent; color: var(--muted); }
.preview-tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-dark); }
.mail-preview-meta { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 8px; padding: 14px; font-size: 12px; background: white; border: 1px solid var(--line); border-bottom: 0; }
.mail-preview-meta > span { color: var(--muted); }
.mail-preview-meta strong { overflow-wrap: anywhere; }
.plain-mail-preview { margin: 0; padding: 24px; background: white; border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.6 Arial, sans-serif; min-height: 540px; }
.automation-overview { margin: 24px 0; padding: 20px 24px; background: white; border-top: 3px solid #91a5b1; }
.automation-active { border-top-color: #009ed3; background: #f5fcff; }
.automation-active .badge.primary { color: #006e94; background: #d9f3fb; }
.automation-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.automation-title h2 { font-size: 19px; margin: 0 0 5px; }
.automation-title p { font-size: 13px; margin: 0; color: var(--muted); }
.automation-title > div:last-child { display: flex; align-items: center; gap: 12px; }
.automation-metrics { display: grid; grid-template-columns: 1fr 1fr 1.5fr; gap: 24px; margin: 20px 0; }
.automation-metrics > div { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.automation-metrics span, .automation-metrics small { font-size: 12px; color: var(--muted); }
.automation-metrics strong { font-size: 16px; overflow-wrap: anywhere; }
.automation-metrics a, .automation-title a { font-size: 12px; }
.automation-error { color: #be3443; }
.login-card .login-company { margin: 0 0 20px; font-size: 16px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.login-card .payment-table { min-width: 0; width: 100%; table-layout: fixed; }
.login-card .payment-table td { padding: 12px 4px; overflow-wrap: anywhere; }
.login-card .payment-table td:first-child { width: 60%; }
.login-card .payment-table td:last-child { text-align: right; white-space: nowrap; }
.payment-button { justify-content: center; text-align: center; }
.settings-section.payment-settings-section { background: white; margin-top: 24px; padding: 24px 28px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); scroll-margin-top: 100px; }
.payment-settings-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; }
.payment-connection, .payment-authorization { min-width: 0; }
.payment-authorization { border-left: 1px solid var(--line); padding-left: 28px; }
.payment-save-row { display: flex; justify-content: flex-end; margin-top: 20px; }
.payment-save-row button { white-space: normal; }
.payment-live-notice { color: var(--warning); font-size: 12px; line-height: 1.5; margin: 14px 0 0; }
.payment-settings-section h3 { font-size: 14px; margin: 24px 0 12px; padding-top: 20px; border-top: 1px solid var(--line); }
@media (max-width: 800px) {
  .settings-section.payment-settings-section { padding: 24px 18px; }
  .payment-settings-form { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .payment-authorization { border-left: 0; border-top: 1px solid var(--line); padding: 20px 0 0; }
  .payment-save-row { justify-content: flex-start; }
}
.brand-company { max-width: 240px; font-size: 14px; overflow-wrap: anywhere; }
.payment-history-section { margin: 28px 0; scroll-margin-top: 100px; }
.payment-history-section .muted-line { max-width: 900px; margin-bottom: 16px; font-size: 13px; }
.history-pagination { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 20px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.user-invite-section { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 22px 0; }
.user-invite-form { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(220px, 1.4fr) 160px auto; gap: 16px; align-items: end; }
.user-invite-form label, .account-password-section label { display: block; margin-bottom: 8px; }
.user-invite-section .muted-line { font-size: 13px; margin-top: 14px; }
.user-access-form { display: flex; gap: 10px; align-items: center; min-width: 290px; }
.user-access-form select { width: 130px; }
.user-active-label { display: flex; align-items: center; gap: 6px; margin: 0; }
.user-active-label input { width: 16px; height: 16px; margin: 0; }
.account-password-section { max-width: 480px; padding: 22px 0; border-top: 1px solid var(--line); }
.account-password-section input { margin-bottom: 18px; }
@media (max-width: 850px) { .user-invite-form { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .user-invite-form { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .brand-company { max-width: calc(100vw - 160px); } }
.automation-footer { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 11px; color: var(--muted); }
@media (max-width: 700px) {
  .automation-overview { padding: 18px; }
  .automation-title, .automation-footer { flex-direction: column; }
  .automation-metrics { grid-template-columns: 1fr; gap: 18px; }
}
.brand-preview iframe { display: block; width: 100%; height: calc(100vh - 390px); min-height: 420px; border: 1px solid var(--line); background: white; }
.pdf-canvas-preview { height: calc(100vh - 390px); min-height: 420px; overflow: auto; background: #e8edf1; border: 1px solid var(--line); padding: 16px; }
.pdf-canvas-preview canvas { display: block; margin: 0 auto 16px; max-width: 100%; height: auto !important; background: white; }
.brand-workspace [hidden], .brand-logo-row [hidden] { display: none !important; }

@media (max-width: 900px) {
  .brand-workspace { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .brand-preview { position: static; }
  .branding-title { position: static; }
}
.settings-workspace {
  background: white;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0;
  padding: 0 28px;
}
.settings-column { min-width: 0; padding: 0 28px 0 0; }
.settings-column + .settings-column { border-left: 1px solid var(--line); padding: 0 0 0 28px; }
.settings-section { padding: 24px 0; }
.settings-section + .settings-section { border-top: 1px solid var(--line); }
.settings-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.settings-heading h2 { margin: 0; font-size: 17px; }
.settings-heading > span:not(.badge), .schedule-label, .optional-label { color: var(--muted); font-size: 12px; }
.automation-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.automation-switch-row label { margin: 0; color: var(--text); }
.schedule-label { white-space: nowrap; }
.schedule-label strong { color: var(--text); margin-left: 4px; }
.settings-field + .settings-field { margin-top: 16px; }
.settings-field label { color: var(--text); font-size: 13px; font-weight: 600; }
.settings-field input { min-width: 0; }
.settings-note { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 6px 0 0; }
.automation-note { margin-top: 14px; }
.term-row { display: grid; grid-template-columns: minmax(0, 1fr) 126px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.term-row label { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--text); font-size: 13px; margin: 0; }
.term-row label > span:not(.step-number) { color: var(--muted); font-size: 12px; flex-basis: 100%; }
.day-input { display: grid; grid-template-columns: 72px 1fr; align-items: center; gap: 8px; }
.day-input input { text-align: center; padding: 6px; min-width: 0; }
.day-input > span { color: var(--muted); font-size: 12px; }
.first-term-row { margin-bottom: 16px; border-bottom: 0; padding: 0; }
.term-table-heading { display: grid; grid-template-columns: minmax(0, 1fr) 126px; gap: 12px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.step-number { align-items: center; display: inline-flex; justify-content: center; width: 22px; height: 22px; background: var(--accent-soft); color: var(--accent-dark); border-radius: 4px; font-size: 12px; flex: 0 0 22px; }

@media (max-width: 800px) {
  .settings-workspace { grid-template-columns: minmax(0, 1fr); padding: 0 18px; }
  .settings-column, .settings-column + .settings-column { padding: 0; border-left: 0; }
  .settings-column + .settings-column { border-top: 1px solid var(--line); }
  .settings-title { flex-direction: row; align-items: center; }
  .automation-switch-row { align-items: flex-start; flex-direction: column; }
  .term-row, .term-table-heading { grid-template-columns: minmax(0, 1fr) 110px; }
  .day-input { grid-template-columns: 60px 1fr; }
}

.upload-panel {
  align-items: end;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px) auto;
  margin-bottom: 22px;
}

.upload-copy h2 {
  margin-bottom: 8px;
}

.upload-form {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.dropbox-import-form {
  display: block;
}

.field-help {
  color: var(--muted);
  font-size: 13px;
  margin: -4px 0 6px;
}

.notes {
  background: var(--panel-tint);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  min-height: 100px;
  padding: 10px;
  white-space: pre-wrap;
}

@media (max-width: 980px) {
  .stats-grid,
  .kpi-grid,
  .aging-grid,
  .followup-grid,
  .split,
  .detail-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

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

  nav {
    gap: 12px;
  }

  .page-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .page-actions .button,
  .page-actions button {
    justify-content: center;
    width: 100%;
  }

  .attention-item,
  .import-status dl,
  .upload-panel,
  .upload-form {
    grid-template-columns: 1fr;
  }

  .attention-item em {
    text-align: left;
  }
}
