: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;
}

.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%;
}

.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;
}

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

.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;
}

.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%;
}

.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;
}

.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,
  .split,
  .detail-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .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 {
    grid-template-columns: 1fr;
  }

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