:root {
  --bg: #f5f7f2;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --ink: #1c2420;
  --muted: #66736b;
  --line: #d8ded7;
  --accent: #167a64;
  --accent-dark: #0e5849;
  --warn: #b54f2a;
  --shadow: 0 20px 55px rgba(29, 45, 37, 0.12);
}

* {
  box-sizing: border-box;
}

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

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

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  grid-template-areas:
    "brand account"
    "nav nav";
  align-items: end;
  gap: 14px 24px;
  padding: 22px clamp(18px, 4vw, 56px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar > div:first-child {
  grid-area: brand;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-link {
  display: inline-block;
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
  text-transform: uppercase;
}

.brand-link:hover {
  color: var(--accent-dark);
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1;
}

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

.tool-nav {
  grid-area: nav;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  justify-content: flex-start;
  max-width: none;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.nav-search {
  width: min(220px, 100%);
  color: var(--muted);
  font-size: 12px;
}

.nav-search input {
  min-height: 40px;
  padding: 0 12px;
}

.account-actions {
  grid-area: account;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-btn,
.primary-btn,
.secondary-btn,
.danger-btn {
  flex: 0 0 auto;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  color: var(--ink);
  background: var(--surface);
  font-weight: 750;
}

.nav-btn.active,
.primary-btn {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.nav-btn:hover,
.secondary-btn:hover {
  border-color: var(--accent);
}

.primary-btn:hover {
  background: var(--accent-dark);
}

.danger-btn {
  color: var(--warn);
}

main {
  padding: 18px clamp(18px, 4vw, 56px) 40px;
}

.ad-band {
  display: grid;
  gap: 6px;
  place-items: center;
  min-height: 96px;
  border: 1px dashed #b7c4bc;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  border-radius: 8px;
  margin-bottom: 18px;
}

.ad-label {
  align-self: end;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.ad-slot {
  width: min(728px, 100%);
  min-height: 60px;
  display: grid;
  place-items: center;
}

.ad-slot:empty::before {
  content: "Ad space";
  color: #7d8982;
  font-size: 13px;
}

.ad-band.bottom {
  margin-top: 22px;
}

.hidden {
  display: none !important;
}

.account-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.35fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.account-panel h2 {
  margin-bottom: 0;
}

.tool-finder {
  display: grid;
  grid-template-columns: minmax(220px, 0.34fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tool-finder h2 {
  margin-bottom: 0;
}

.quick-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.quick-tools button,
.quick-tools a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fbfcfb;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.quick-tools button:hover,
.quick-tools a:hover {
  border-color: var(--accent);
}

.focus-pulse {
  animation: focusPulse 1.2s ease;
}

@keyframes focusPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(22, 122, 100, 0.32);
  }
  55% {
    box-shadow: 0 0 0 8px rgba(22, 122, 100, 0.12);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

.activity-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
}

.activity-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.activity-card strong {
  font-size: 15px;
}

.activity-card span,
.activity-card p {
  color: var(--muted);
  font-size: 13px;
}

.activity-card p {
  margin-bottom: 0;
}

.tool-panel {
  display: none;
}

.tool-panel.active {
  display: block;
}

.invoice-workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.95fr) minmax(420px, 1.05fr);
  gap: 22px;
  align-items: start;
}

.editor,
.calc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.section-head:first-child {
  margin-top: 0;
}

.field-grid {
  display: grid;
  gap: 12px;
}

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

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.wide {
  grid-column: 1 / -1;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 122, 100, 0.14);
}

textarea {
  resize: vertical;
}

.line-items {
  display: grid;
  gap: 10px;
}

.line-item {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 82px 98px 102px 42px;
  gap: 8px;
  align-items: end;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--warn);
  background: var(--surface);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(19, 29, 25, 0.42);
}

.account-modal {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.mode-toggle {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.form-message {
  min-height: 20px;
  margin-bottom: 0;
  color: var(--warn);
  font-size: 13px;
  font-weight: 750;
}

.small-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.invoice-preview {
  position: sticky;
  top: 118px;
}

.paper {
  min-height: 780px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(24px, 4vw, 42px);
}

.preview-top {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 36px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 22px;
  font-weight: 900;
}

.preview-title {
  text-align: right;
}

.preview-title h2 {
  margin: 0 0 6px;
  font-size: 34px;
}

.preview-meta,
.preview-address {
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-line;
}

.bill-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
}

.preview-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

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

.invoice-table th,
.invoice-table td {
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

.invoice-table th:first-child,
.invoice-table td:first-child {
  text-align: left;
}

.invoice-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.totals {
  display: grid;
  gap: 10px;
  width: min(320px, 100%);
  margin-left: auto;
  margin-top: 22px;
}

.total-line {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.grand-total {
  padding-top: 12px;
  border-top: 2px solid var(--ink);
  font-size: 22px;
  font-weight: 900;
}

.notes {
  margin-top: 36px;
  color: var(--muted);
  line-height: 1.55;
}

.calculator-grid {
  max-width: 900px;
}

.tool-hub-grid {
  display: none;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 18px;
}

.tool-hub-grid.active {
  display: grid;
}

.calc-card {
  max-width: 820px;
}

.tool-hub-grid .calc-card,
.wide-card {
  max-width: none;
}

.wide-card {
  grid-column: 1 / -1;
}

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

.result-row:last-child {
  border-bottom: 0;
}

.result-row span {
  color: var(--muted);
}

.result-row strong {
  font-size: 22px;
}

.name-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.name-chip {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  font-weight: 800;
}

.text-output {
  min-height: 180px;
  max-height: 420px;
  overflow: auto;
  margin: 16px 0 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  white-space: pre-wrap;
  line-height: 1.55;
}

.compact-output {
  min-height: 72px;
  max-height: 160px;
}

.directory-results {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.result-card {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.result-card strong {
  display: block;
  margin-bottom: 4px;
}

.result-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.quiz-options {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.quiz-options button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  padding: 0 12px;
}

.quiz-options button.correct {
  border-color: var(--accent);
  background: rgba(22, 122, 100, 0.12);
}

.quiz-options button.wrong {
  border-color: var(--warn);
  background: rgba(181, 79, 42, 0.12);
}

.qr-workspace {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  gap: 16px;
  align-items: center;
  margin-top: 16px;
}

#qr-canvas {
  width: min(256px, 100%);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.site-footer {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  color: var(--muted);
  font-size: 13px;
}

.site-footer a {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.content-page {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px clamp(18px, 4vw, 56px);
}

.content-page article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 40px);
  line-height: 1.65;
}

.content-page h1 {
  margin-bottom: 18px;
}

.content-page a {
  color: var(--accent);
  font-weight: 800;
}

@media (max-width: 980px) {
  .invoice-workspace,
  .account-panel,
  .tool-finder,
  .preview-top,
  .bill-grid {
    display: block;
  }

  .topbar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "account"
      "nav";
    align-items: start;
  }

  .tool-nav,
  .account-actions {
    justify-content: flex-start;
  }

  .quick-tools {
    justify-content: flex-start;
    margin-top: 12px;
  }

  .nav-search {
    width: 100%;
  }

  .activity-list {
    margin-top: 14px;
  }

  .invoice-preview {
    position: static;
    margin-top: 20px;
  }

  .preview-title {
    text-align: left;
    margin-top: 18px;
  }
}

@media (max-width: 720px) {
  main {
    padding-inline: 12px;
  }

  .topbar {
    padding-inline: 12px;
    position: static;
  }

  .tool-nav {
    margin-inline: -12px;
    padding: 0 12px 8px;
  }

  .nav-btn,
  .primary-btn,
  .secondary-btn {
    min-height: 44px;
  }

  h1 {
    font-size: 30px;
  }

  .field-grid.two,
  .field-grid.three,
  .name-results,
  .tool-hub-grid {
    grid-template-columns: 1fr;
  }

  .wide-card {
    grid-column: auto;
  }

  .line-item {
    grid-template-columns: 1fr 1fr;
  }

  .qr-workspace {
    grid-template-columns: 1fr;
  }

  .line-item label:first-child {
    grid-column: 1 / -1;
  }

  .paper {
    padding: 18px;
  }

  .invoice-table {
    font-size: 13px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .editor,
  .ad-band {
    display: none !important;
  }

  main {
    padding: 0;
  }

  .tool-panel {
    display: none !important;
  }

  #invoice-tool {
    display: block !important;
  }

  .invoice-workspace {
    display: block;
  }

  .invoice-preview {
    position: static;
  }

  .paper {
    min-height: auto;
    border: 0;
    box-shadow: none;
    border-radius: 0;
  }
}
