:root {
  --navy: #1a1a2e;
  --navy-2: #22233c;
  --gold: #c9a84c;
  --gold-soft: #f4ead1;
  --paper: #fdfcfa;
  --line: #e8e1d4;
  --text: #222;
  --muted: #6f6b63;
  --green: #2d7a4f;
  --red: #b94338;
  --blue: #365b8c;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

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

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

button {
  min-height: 42px;
}

.kme-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  background: rgba(253, 252, 250, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.kme-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--navy);
  text-decoration: none;
  min-width: 210px;
}

.kme-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background: var(--navy);
  color: var(--gold);
  font-family: Georgia, serif;
  font-weight: 700;
}

.kme-brand strong {
  display: block;
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: 15px;
}

.kme-brand small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.kme-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
}

.kme-nav a,
.kme-nav span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 8px 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  border-bottom: 2px solid transparent;
}

.kme-nav span {
  color: var(--navy);
  border-bottom-color: var(--gold);
  font-weight: 700;
}

.kme-page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
}

.tax-page {
  display: flex;
  flex-direction: column;
}

.tax-page .intro-band {
  order: 1;
}

.tax-page .trust-strip {
  order: 2;
}

.tax-page #authPanel {
  order: 3;
}

.tax-page #workspacePanel {
  order: 4;
}

.tax-page .platform-cta-panel {
  order: 5;
}

.tax-page #city-tax-expansion {
  order: 6;
}

.tax-page #adminPanel {
  order: 7;
}

.intro-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 20px;
  align-items: end;
  padding: 28px 0 20px;
}

.intro-band h1 {
  max-width: 780px;
  margin: 6px 0 10px;
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.06;
}

.intro-band p {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.intro-proof {
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  background: #fff;
  border-radius: 8px;
}

.intro-proof strong,
.intro-proof span {
  display: block;
}

.intro-proof strong {
  margin-bottom: 6px;
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: 18px;
}

.intro-proof span {
  color: var(--muted);
  font-size: 12px;
}

.trust-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.trust-strip article {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.trust-strip strong,
.trust-strip span {
  display: block;
}

.trust-strip strong {
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: 17px;
}

.trust-strip span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 12px 34px rgba(26, 26, 46, 0.05);
}

.auth-panel {
  max-width: 920px;
  border-top: 4px solid var(--gold);
}

.panel-head,
.workspace-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.workspace-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.panel-head.compact {
  align-items: center;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h2,
h3 {
  margin: 4px 0 0;
  color: var(--navy);
  font-family: Georgia, serif;
  line-height: 1.14;
}

h2 {
  font-size: 26px;
}

h3 {
  font-size: 20px;
}

.pill,
.mini-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: #7b6323;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.mini-status {
  background: #f5f1e8;
  color: var(--muted);
}

.form-grid,
.calculator-grid,
.document-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.form-grid.single {
  grid-template-columns: 1fr;
}

label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid #d8d0c2;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.18);
}

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

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.check-row input {
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  margin-top: 1px;
  accent-color: var(--gold);
}

.action-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.primary-button,
.secondary-button,
.ghost-button {
  border: 0;
  border-radius: 6px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  background: var(--navy);
  color: var(--gold);
}

.secondary-button {
  background: var(--gold);
  color: var(--navy);
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.platform-cta-panel {
  max-width: 960px;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--navy);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.full {
  width: 100%;
  margin-top: 14px;
}

.status-text,
.hint,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.hint {
  margin: 8px 0 0;
}

.otp-panel {
  display: grid;
  grid-template-columns: minmax(160px, 220px) auto;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf7ed;
}

.workspace-panel {
  display: block;
}

.layout-grid {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.sidebar-panel {
  position: sticky;
  top: 82px;
}

.main-stack {
  display: grid;
  gap: 16px;
}

.calculator-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.timeline-card {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.timeline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.timeline-head h4 {
  margin: 3px 0 0;
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: 17px;
}

.compact-button {
  min-height: 34px;
  padding: 7px 11px;
}

.period-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.period-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.period-row .remove-period {
  min-width: 40px;
  min-height: 42px;
  border: 1px solid #ead8d5;
  border-radius: 6px;
  background: #fff7f6;
  color: var(--red);
  cursor: pointer;
  font-weight: 900;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
}

.ranked-results {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.rank-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.rank-card.best {
  border-color: rgba(45, 122, 79, 0.4);
  background: #f0faf4;
}

.rank-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.rank-card strong {
  display: block;
  margin-top: 5px;
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: 20px;
}

.rank-card small {
  display: block;
  margin-top: 4px;
  color: var(--green);
}

.table-wrap {
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th {
  position: sticky;
  top: 0;
  background: var(--navy);
  color: var(--gold);
  padding: 9px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

td {
  border-bottom: 1px solid #f0ebe2;
  padding: 9px;
  color: #32313b;
  font-size: 13px;
}

.table-subline,
.table-detail {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.table-detail {
  color: #3f4b5b;
}

.document-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.city-panel {
  margin-bottom: 18px;
}

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

.city-check {
  align-self: end;
  min-height: 42px;
}

.city-engine-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.city-engine-info strong,
.city-engine-info span,
.city-engine-info a {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdfa;
  color: var(--navy);
  text-decoration: none;
}

.city-engine-info strong {
  background: #f7f3e9;
}

.city-tax-result {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(45, 122, 79, 0.35);
  border-radius: 8px;
  background: #f0faf4;
}

.city-result-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--green);
}

.city-result-head strong {
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: 24px;
}

.city-result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.city-result-grid div {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.city-result-grid span,
.city-tax-result p {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.city-result-grid strong {
  display: block;
  margin-top: 3px;
  color: var(--navy);
}

.document-item,
.admin-metric {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.document-item strong,
.admin-metric strong {
  display: block;
  color: var(--navy);
}

.document-item span,
.admin-metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.document-item small {
  display: block;
  margin-top: 4px;
  color: var(--green);
  font-size: 11px;
}

.admin-panel summary {
  cursor: pointer;
  color: var(--navy);
  font-weight: 800;
}

.admin-inner {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.admin-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.admin-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  grid-column: 1 / -1;
}

.admin-section {
  grid-column: 1 / -1;
  padding-top: 6px;
}

.admin-section h4 {
  margin: 4px 0 8px;
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: 16px;
}

.mini-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.mini-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdfa;
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
}

.compact-table {
  max-height: 210px;
}

.event-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--navy);
  font-size: 12px;
}

.event-list span {
  color: var(--muted);
}

.is-error {
  color: var(--red);
}

.is-ok {
  color: var(--green);
}

@media (max-width: 920px) {
  .kme-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .kme-nav {
    width: 100%;
  }

  .intro-band,
  .layout-grid,
  .trust-strip {
    grid-template-columns: 1fr;
  }

  .sidebar-panel {
    position: static;
  }

  .calculator-grid,
  .city-grid,
  .ranked-results,
    .admin-summary,
    .admin-metrics,
    .period-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .period-row .remove-period {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .kme-page {
    padding: 12px;
  }

  .intro-band {
    padding-top: 18px;
  }

  .panel {
    padding: 14px;
  }

  .panel-head,
  .workspace-top {
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid,
  .calculator-grid,
  .city-grid,
  .document-grid,
  .toggle-grid,
  .ranked-results,
    .admin-summary,
    .admin-metrics,
  .period-row,
  .otp-panel {
    grid-template-columns: 1fr;
  }

  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .action-row button {
    width: 100%;
  }

  .link-button {
    width: 100%;
  }

  .kme-brand {
    min-width: 0;
  }

  .city-result-head {
    flex-direction: column;
  }

  .city-result-grid {
    grid-template-columns: 1fr;
  }
}
