:root {
  color-scheme: light;
  --bg: #f4f8f6;
  --surface: #ffffff;
  --surface-soft: #eaf4f1;
  --text: #10231f;
  --muted: #5e716d;
  --border: #cfe0dc;
  --accent: #057c70;
  --accent-strong: #045f57;
  --amber: #8a5b00;
  --amber-bg: #fff4d8;
  --danger: #9c2f2f;
  --shadow: 0 18px 45px rgba(15, 35, 31, 0.1);
  --radius: 8px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1715;
  --surface: #16211e;
  --surface-soft: #1d2c28;
  --text: #edf7f4;
  --muted: #adc3bd;
  --border: #31443f;
  --accent: #4cc3b3;
  --accent-strong: #79ded2;
  --amber: #ffd27a;
  --amber-bg: #352817;
  --danger: #ffaaa2;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar,
.tool-actions,
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand img {
  width: 46px;
  height: 46px;
}

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

h1 {
  margin-bottom: 2px;
  font-size: clamp(1.6rem, 3vw, 2.35rem);
  line-height: 1.1;
}

.brand p,
.panel-heading p,
.input-group-heading p,
.muted {
  color: var(--muted);
  margin-bottom: 0;
}

.site-nav,
.tool-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.site-nav > a,
.tools-menu summary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: 0 12px;
  text-decoration: none;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.site-nav > a:hover,
.tools-menu[open] summary,
.tools-menu summary:hover {
  background: var(--surface-soft);
}

.icon-button,
.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 9px 12px;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

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

.theme-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  padding: 0;
  cursor: pointer;
}

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

.theme-button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tools-menu {
  position: relative;
}

.tools-menu summary {
  list-style: none;
}

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

.tools-menu summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.tools-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  display: grid;
  gap: 6px;
  width: min(320px, calc(100vw - 32px));
  max-height: min(70vh, 620px);
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tools-panel a {
  display: grid;
  gap: 3px;
  align-items: start;
  justify-content: stretch;
  width: 100%;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: var(--radius);
  padding: 10px;
  color: inherit;
  text-decoration: none;
  font-size: 13px;
}

.tools-panel a:hover,
.tools-panel a:focus,
.tools-panel a[aria-current="page"] {
  background: var(--surface-soft);
  text-decoration: none;
}

.tools-panel strong,
.tools-panel span,
.related-tool-grid span {
  display: block;
  width: 100%;
  text-decoration: none;
}

.tools-panel strong {
  font-size: 13px;
}

.tools-panel span,
.related-tool-grid span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tool-actions {
  justify-content: flex-end;
  margin-bottom: 14px;
}

.tool-actions .icon-button {
  min-height: 42px;
  border-color: var(--border);
  background: var(--surface);
  padding: 9px 12px;
  font-size: 1rem;
}

.ad-slot {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 18px;
  align-items: start;
}

.panel,
.content-section,
.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel,
.content-section {
  padding: 18px;
}

.panel-heading,
.input-group-heading {
  margin-bottom: 14px;
}

.panel-heading.inline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.form-grid,
.input-group {
  display: grid;
  gap: 14px;
}

.input-group {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-weight: 700;
}

label small {
  color: var(--muted);
  font-weight: 500;
}

.check-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 11px;
}

.check-control input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.amount-period {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(118px, 0.45fr);
  gap: 8px;
  align-items: end;
}

.amount-period input,
.amount-period select {
  min-width: 0;
  min-height: 46px;
}

.amount-period select {
  padding-right: 28px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 10px 11px;
  font: inherit;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.result-card {
  overflow: hidden;
}

.headline {
  padding: 20px;
  background: linear-gradient(135deg, var(--surface-soft), var(--surface));
}

.headline span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.headline strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(2rem, 6vw, 3.7rem);
  line-height: 1.05;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}

.metric {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 1.45rem;
}

.breakdown {
  padding: 0 18px 18px;
}

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

.breakdown th,
.breakdown td {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
  text-align: left;
  vertical-align: top;
}

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

body[data-tool="payslip"] #summaryMetrics,
body[data-tool="payslip"] #breakdown {
  display: none;
}

.inline-result-table {
  overflow-x: auto;
}

.result-inline-table {
  padding: 18px;
}

.inline-result-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}

.inline-result-table th,
.inline-result-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: right;
  vertical-align: top;
  white-space: nowrap;
}

.inline-result-table th:first-child,
.inline-result-table td:first-child {
  padding-left: 0;
  text-align: left;
  white-space: normal;
}

.inline-result-table th:last-child,
.inline-result-table td:last-child {
  padding-right: 0;
}

.inline-result-table tbody th {
  color: var(--text);
  font-weight: 800;
}

.inline-result-table tr.warning th,
.inline-result-table tr.warning td:last-child {
  color: var(--amber);
}

.notice {
  margin: 18px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
}

.notice.warning {
  border-color: color-mix(in srgb, var(--amber) 55%, var(--border));
  background: var(--amber-bg);
  color: var(--text);
}

.stack {
  display: grid;
  gap: 18px;
}

.content-grid,
.related-tool-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.content-card,
.related-tool-grid a {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.site-footer {
  margin-top: 18px;
  padding: 18px 0 0;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  color: var(--muted);
}

.site-footer span,
.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-nav,
  .tool-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace,
  .content-grid,
  .related-tool-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .two-col,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .content-section {
    padding: 14px;
  }

  .headline,
  .summary-grid,
  .breakdown {
    padding: 14px;
  }

  .result-inline-table {
    padding: 14px;
  }

  .inline-result-table table,
  .inline-result-table thead,
  .inline-result-table tbody,
  .inline-result-table tr,
  .inline-result-table th,
  .inline-result-table td {
    display: block;
  }

  .inline-result-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .inline-result-table tr {
    display: grid;
    gap: 6px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }

  .inline-result-table th,
  .inline-result-table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 0;
    text-align: right;
    white-space: normal;
  }

  .inline-result-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    text-align: left;
  }

  .notice {
    margin: 14px;
  }

  .tools-panel {
    left: 0;
    right: auto;
  }
}

@media (max-width: 430px) {
  .site-nav {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 7px;
    justify-content: stretch;
  }

  .tools-menu {
    min-width: 0;
  }

  .tools-menu summary {
    width: 100%;
  }

  .site-nav .icon-button {
    grid-column: 1 / -1;
  }

  .amount-period {
    grid-template-columns: 1fr;
  }
}
