:root {
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.86);
  --text: #172033;
  --muted: #667085;
  --line: #dfe5ef;
  --blue: #1463ff;
  --blue-dark: #0d46b7;
  --green: #0e8f6e;
  --radius-sm: 12px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow: 0 20px 60px rgba(23, 32, 51, 0.1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(20, 99, 255, 0.12), transparent 28rem),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 42%);
}

button,
input,
select {
  font: inherit;
}

input[type="date"] {
  appearance: none;
  -webkit-appearance: none;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid rgba(223, 229, 239, 0.72);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-mark {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border-radius: var(--radius-md);
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--green));
  font-weight: 800;
}

.brand h1,
.policy-shell h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(1.05rem, 2vw, 1.35rem);
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.top-nav {
  display: flex;
  gap: 0.45rem;
  padding: 0.28rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.nav-button,
.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
}

.nav-button {
  padding: 0 1rem;
  color: var(--muted);
  background: transparent;
}

.nav-button.active {
  color: white;
  background: var(--text);
}

main {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero,
.policy-shell,
.summary-panel,
.project-card {
  border: 1px solid rgba(223, 229, 239, 0.86);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.5rem;
  padding: clamp(1.2rem, 3vw, 2rem);
}

.tax-picker select,
label input,
label select,
.month-table input,
.month-table select {
  width: 100%;
  min-height: 2.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0 0.9rem;
  color: var(--text);
  background: white;
}

.parameter-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(8rem, 1fr));
  gap: 0.75rem;
}

.parameter-strip div,
.summary-grid div,
.result-box div {
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.74);
}

.parameter-strip span,
.summary-grid span,
.result-box span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.25rem;
  margin-top: 1.25rem;
  align-items: start;
}

.project-list {
  display: grid;
  grid-column: 1;
  grid-row: 1;
  gap: 1rem;
  min-width: 0;
}

.project-actions {
  display: flex;
  grid-column: 1;
  grid-row: 2;
  justify-content: flex-end;
  min-width: 0;
}

.project-card,
.summary-panel,
.policy-shell {
  padding: 1.4rem;
}

.project-card {
  min-width: 0;
  overflow: hidden;
}

.summary-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
  position: sticky;
  top: 6rem;
}

.project-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.1rem;
}

.delete-project {
  width: 2.35rem;
  min-width: 2.35rem;
  height: 2.35rem;
  min-height: 2.35rem;
  border-radius: 999px;
  padding: 0;
  flex: 0 0 auto;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}

.project-title-area {
  width: min(34rem, 100%);
}

.project-name-field {
  display: grid;
  grid-template-columns: auto minmax(12rem, 1fr);
  align-items: center;
  gap: 0.65rem;
}

.project-name-field span {
  margin: 0;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.project-name {
  width: 100%;
  min-height: 2.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0 0.9rem;
  background: white;
  color: var(--text);
  font-size: 1rem;
  font-weight: 750;
}

.form-grid,
.dynamic-fields,
.project-date-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.1rem;
}

label span {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.controls-box {
  margin: 1rem 0;
  padding: 1rem;
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.controls-box h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.measure-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.measure-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
}

.measure-item input {
  width: 1.05rem;
  height: 1.05rem;
}

.result-box,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.month-count {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 2.8rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: white;
}

.month-count span {
  color: var(--muted);
  font-size: 0.82rem;
}

.month-count strong {
  font-size: 1.25rem;
}

.month-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

.month-table {
  width: 100%;
  min-width: 1240px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

.month-table th,
.month-table td {
  padding: 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.month-table th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 0.78rem;
  font-weight: 700;
  height: 3.2rem;
  vertical-align: middle;
  white-space: nowrap;
}

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

.month-table select,
.month-table input {
  height: 2.45rem;
  min-height: 2.45rem;
  border-radius: var(--radius-sm);
  padding: 0 0.55rem;
  font-size: 0.86rem;
  white-space: nowrap;
}

.month-table th:first-child,
.month-table td:first-child {
  position: sticky;
  left: 0;
  width: 5.8rem;
  min-width: 5.8rem;
  max-width: 5.8rem;
  z-index: 2;
  background: #fff;
  box-shadow: 1px 0 0 var(--line);
  font-size: 0.82rem;
}

.month-table th:first-child {
  z-index: 3;
  background: #f8fafc;
}

.month-table .area-column {
  min-width: 15rem;
}

.month-table .stage-column {
  width: 10.5rem;
  min-width: 10.5rem;
}

.month-table .days-column {
  width: 7.2rem;
  min-width: 7.2rem;
}

.month-table td:nth-child(2) {
  width: 10.5rem;
  min-width: 10.5rem;
}

.month-table td:nth-child(3) {
  width: 7.2rem;
  min-width: 7.2rem;
}

.month-table td:nth-child(2) select,
.month-table td:nth-child(3) input {
  width: 100%;
}

.month-table td:nth-child(7) {
  width: 7.2rem;
  min-width: 7.2rem;
}

.primary-measures {
  display: grid;
  gap: 0.35rem;
  min-width: 15rem;
}

.primary-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 1.8rem;
  color: var(--text);
  font-size: 0.82rem;
}

.primary-check input {
  width: 1rem;
  min-height: 1rem;
  height: 1rem;
  accent-color: var(--blue);
}

.primary-check span {
  margin: 0;
  color: var(--text);
  line-height: 1.35;
}

.area-fields {
  min-width: 15rem;
}

.compact-field {
  display: grid;
  grid-template-columns: 6.5rem minmax(5rem, 1fr);
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}

.compact-field:last-child {
  margin-bottom: 0;
}

.compact-field span {
  margin: 0;
  font-size: 0.76rem;
}

.compact-field input {
  width: 100%;
}

.month-tax-result {
  display: block;
  color: var(--blue-dark);
  font-size: 1rem;
  white-space: nowrap;
}

.row-detail-button {
  min-height: 1.8rem;
  margin-top: 0.45rem;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 0.65rem;
  color: var(--text);
  background: #eef2f7;
  cursor: pointer;
  font-size: 0.78rem;
}

.project-summary {
  margin-top: 1rem;
}

.summary-grid {
  grid-template-columns: 1fr;
  margin: 1rem 0;
}

.project-tax-result,
#totalTax {
  color: var(--blue-dark);
}

.formula-details {
  margin-top: 1rem;
  color: var(--muted);
}

.formula-details summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
}

.formula-text {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.7rem;
  line-height: 1.7;
}

.primary-button {
  padding: 0 1.2rem;
  color: white;
  background: var(--blue);
}

.secondary-button {
  padding: 0 1rem;
  color: white;
  background: var(--text);
}

.ghost-button {
  padding: 0 1rem;
  color: var(--text);
  background: #eef2f7;
}

.summary-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.notice {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
}

.policy-shell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.policy-shell p {
  max-width: 44rem;
  color: var(--muted);
  line-height: 1.8;
}

.policy-layout {
  display: grid;
  gap: 1.1rem;
}

.policy-toolbar,
.policy-reader {
  border: 1px solid rgba(223, 229, 239, 0.86);
  border-radius: var(--radius-lg);
  padding: clamp(1.2rem, 3vw, 2rem);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.policy-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 24rem);
  align-items: end;
  gap: 1rem;
}

.policy-toolbar h2 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2rem);
}

.policy-search input {
  width: 100%;
  min-height: 2.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0 0.9rem;
  color: var(--text);
  background: white;
}

.policy-cards {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  gap: 0.85rem;
}

.policy-card {
  display: grid;
  min-height: 5.8rem;
  align-content: center;
  gap: 0.45rem;
  border: 1px solid rgba(223, 229, 239, 0.86);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  text-align: left;
  color: var(--text);
  background: #fff;
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.06);
  cursor: pointer;
  text-decoration: none;
}

.policy-card strong {
  font-size: 1rem;
  line-height: 1.45;
}

.policy-card span:last-child,
.empty-policy {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.empty-policy {
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  background: #fff;
}

.policy-reader {
  width: min(900px, 100%);
  margin: 0 auto;
}

.standalone-policy {
  margin-top: 1rem;
}

.policy-back-link {
  width: fit-content;
}

.policy-reader > .ghost-button {
  width: auto;
  margin-bottom: 1rem;
}

.policy-content {
  margin-top: 1rem;
}

.policy-content-head {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.policy-content h1,
.policy-content h2,
.policy-content h3 {
  margin: 1.3rem 0 0.55rem;
}

.policy-content-head h2 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.55rem, 3vw, 2rem);
}

.policy-content p,
.policy-content li {
  color: var(--muted);
  line-height: 1.9;
}

.policy-content ul {
  padding-left: 1.3rem;
}

.policy-content code {
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
  background: #eef2f7;
}

.policy-table-wrap {
  width: 100%;
  margin: 1rem 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
}

.policy-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.policy-table th,
.policy-table td {
  padding: 0.72rem 0.8rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.65;
}

.policy-table th {
  color: var(--text);
  background: #f8fafc;
  font-weight: 750;
}

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

.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(23, 32, 51, 0.42);
}

.detail-modal[hidden] {
  display: none;
}

.detail-dialog {
  width: min(34rem, 100%);
  max-height: min(78vh, 42rem);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: 0 24px 70px rgba(23, 32, 51, 0.22);
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.detail-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.detail-close {
  min-height: 2.15rem;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 0.8rem;
  color: var(--text);
  background: #eef2f7;
}

.detail-content {
  margin: 0;
  max-height: calc(min(78vh, 42rem) - 4.4rem);
  overflow: auto;
  padding: 1rem 1.1rem 1.2rem;
  color: var(--text);
  font: inherit;
  line-height: 1.75;
  text-align: left;
  white-space: pre-wrap;
}

.thirdparty-auth,
.thirdparty-toolbar,
.thirdparty-card,
.thirdparty-status,
.thirdparty-load-more {
  border: 1px solid rgba(223, 229, 239, 0.86);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.thirdparty-auth {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 24rem);
  align-items: end;
  gap: 1.2rem;
  padding: clamp(1.2rem, 3vw, 2rem);
}

.thirdparty-auth[hidden],
.thirdparty-shell[hidden] {
  display: none;
}

.thirdparty-auth h2,
.thirdparty-detail-title h3 {
  margin: 0;
}

.thirdparty-auth p {
  margin: 0.6rem 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.thirdparty-auth-form {
  display: grid;
  gap: 0.75rem;
}

.auth-message {
  min-height: 1.25rem;
  margin: 0;
  color: #c43b3b;
  font-size: 0.9rem;
}

.thirdparty-shell {
  display: grid;
  gap: 1rem;
  padding-bottom: 6rem;
}

.thirdparty-toolbar {
  position: sticky;
  top: 5.6rem;
  z-index: 8;
  display: grid;
  gap: 0.7rem;
  padding: 0.9rem;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.thirdparty-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 1rem;
}

.thirdparty-search input,
.thirdparty-filter-row input,
.thirdparty-filter-row select,
.thirdparty-auth-form input {
  width: 100%;
  min-height: 2.45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0 0.9rem;
  color: var(--text);
  background: white;
}

.thirdparty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.thirdparty-actions button {
  min-height: 2.45rem;
}

.thirdparty-filter-row {
  display: grid;
  grid-template-columns: minmax(8rem, 0.8fr) minmax(12rem, 1.4fr) minmax(10rem, 1fr) auto;
  gap: 0.55rem;
  align-items: end;
}

.thirdparty-filter-row > button {
  align-self: end;
}

.range-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.thirdparty-status {
  position: fixed;
  left: 50%;
  right: auto;
  bottom: 0.75rem;
  z-index: 12;
  width: min(1180px, calc(100% - 2rem));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0.55rem;
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(16px);
}

.thirdparty-status div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.65rem;
  background: #fff;
}

.thirdparty-status span,
.thirdparty-card-grid span,
.thirdparty-detail-item span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.thirdparty-status strong,
.thirdparty-card-grid strong,
.thirdparty-detail-item strong {
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}

.thirdparty-list {
  display: grid;
  gap: 0.85rem;
}

.thirdparty-card {
  position: relative;
  padding: 1rem;
  background: #fff;
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.06);
}

.thirdparty-card-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.thirdparty-card-head h3 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.45;
}

.thirdparty-select {
  display: none;
  width: 1.6rem;
  padding-top: 0.15rem;
}

.thirdparty-select.visible {
  display: block;
}

.thirdparty-select input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--blue);
}

.thirdparty-tax {
  color: var(--blue-dark);
  white-space: nowrap;
  max-width: 100%;
  grid-column: 2;
  justify-self: end;
  text-align: right;
}

.thirdparty-card-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 0.8fr 0.8fr;
  gap: 0.75rem;
  padding: 0.9rem 0;
}

.thirdparty-card-grid div {
  min-width: 0;
}

.thirdparty-card-actions,
.thirdparty-detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.thirdparty-load-more {
  padding: 0.9rem;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  box-shadow: none;
}

.thirdparty-detail-dialog {
  width: min(48rem, 100%);
}

.thirdparty-password-dialog {
  position: relative;
  width: min(25rem, calc(100% - 2rem));
  padding: 1.25rem;
  border-radius: 28px;
  overflow: visible;
}

.thirdparty-password-close {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  display: grid;
  width: 2.15rem;
  height: 2.15rem;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: #eef2f7;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.thirdparty-password-head {
  padding: 0.65rem 2.5rem 1rem;
  text-align: center;
}

.thirdparty-password-head h2 {
  margin: 0;
  font-size: 1.35rem;
}

.thirdparty-password-head p:last-child {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.thirdparty-password-body {
  display: grid;
  gap: 0.7rem;
}

.thirdparty-password-body label span {
  padding-left: 0.15rem;
}

.thirdparty-password-body input {
  width: 100%;
  min-height: 3rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 1rem;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.thirdparty-password-body input:focus {
  border-color: rgba(20, 99, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(20, 99, 255, 0.12);
  background: #fff;
}

.thirdparty-password-body .auth-message {
  min-height: 1rem;
  text-align: center;
}

.thirdparty-password-body .primary-button {
  width: 100%;
  min-height: 3rem;
  border-radius: 16px;
  font-weight: 750;
}

.thirdparty-detail-content {
  max-height: calc(min(78vh, 42rem) - 4.4rem);
  overflow: auto;
  padding: 1rem 1.1rem 1.2rem;
}

.thirdparty-detail-title {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.thirdparty-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.thirdparty-detail-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  background: #f8fafc;
}

.thirdparty-detail-item.wide {
  grid-column: 1 / -1;
}

@media (max-width: 900px) {
  .site-header,
  .hero,
  .policy-shell {
    align-items: stretch;
    flex-direction: column;
  }

  .site-header,
  .policy-shell {
    display: flex;
  }

  .hero,
  .workspace,
  .thirdparty-auth,
  .thirdparty-search-row {
    grid-template-columns: 1fr;
  }

  .project-list,
  .project-actions,
  .summary-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .parameter-strip,
  .form-grid,
  .dynamic-fields,
  .project-date-grid,
  .measure-list,
  .result-box,
  .thirdparty-card-grid {
    grid-template-columns: 1fr;
  }

  .thirdparty-actions {
    justify-content: stretch;
  }

  .thirdparty-actions button {
    flex: 1 1 7rem;
  }

  .thirdparty-status {
    width: calc(100% - 1rem);
    bottom: 0.5rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .thirdparty-card-head {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.35rem;
  }

  .thirdparty-tax {
    grid-column: 1;
    justify-self: stretch;
    width: 100%;
    font-size: 1.05rem;
    line-height: 1.2;
    text-align: right;
    white-space: normal;
  }

  .thirdparty-select.visible {
    position: absolute;
    top: 0.85rem;
    left: 0.85rem;
    display: block;
  }

  .thirdparty-select.visible + div {
    padding-left: 1.8rem;
  }

  .top-nav {
    width: 100%;
  }

  .nav-button {
    flex: 1;
  }
}

@media (max-width: 680px) {
  .site-header {
    position: static;
    padding: 1rem;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 2.7rem;
    height: 2.7rem;
  }

  .brand h1 {
    font-size: 1.12rem;
    line-height: 1.35;
  }

  main {
    width: min(100% - 1rem, 1180px);
    padding: 1rem 0 6.25rem;
  }

  .top-nav {
    gap: 0.25rem;
    border-radius: var(--radius-lg);
  }

  .nav-button {
    min-height: 3.05rem;
    border-radius: var(--radius-md);
  }

  .hero {
    display: none;
  }

  .project-card,
  .summary-panel,
  .policy-shell,
  .policy-toolbar,
  .policy-reader,
  .thirdparty-auth,
  .thirdparty-toolbar,
  .thirdparty-card {
    border-radius: var(--radius-lg);
    padding: 1rem;
  }

  .thirdparty-shell {
    gap: 0.75rem;
    padding-bottom: 0;
  }

  .thirdparty-toolbar {
    top: 0;
    gap: 0.55rem;
    padding: 0.65rem;
    border-radius: var(--radius-md);
  }

  .thirdparty-search-row {
    gap: 0.55rem;
  }

  .thirdparty-search span,
  .thirdparty-filter-row span {
    display: none;
  }

  .thirdparty-search input,
  .thirdparty-filter-row input,
  .thirdparty-filter-row select {
    min-height: 2.25rem;
    border-radius: 12px;
    padding: 0 0.7rem;
    font-size: 0.86rem;
  }

  .thirdparty-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .thirdparty-actions button {
    min-height: 2.15rem;
    padding: 0 0.35rem;
    border-radius: 12px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .thirdparty-filter-row {
    grid-template-columns: 5.9rem minmax(0, 1fr) 6.15rem 3.6rem;
    gap: 0.35rem;
  }

  .range-pair {
    gap: 0.3rem;
  }

  .thirdparty-filter-row > button {
    min-height: 2.25rem;
    padding: 0 0.35rem;
    border-radius: 12px;
    font-size: 0.78rem;
  }

  .thirdparty-status {
    width: calc(100% - 0.75rem);
    gap: 0.3rem;
    padding: 0.35rem;
    border-radius: var(--radius-md);
  }

  .thirdparty-status div {
    padding: 0.35rem 0.4rem;
    border-radius: 10px;
  }

  .thirdparty-status span {
    margin-bottom: 0.15rem;
    font-size: 0.62rem;
    line-height: 1.2;
  }

  .thirdparty-status strong {
    display: block;
    font-size: 0.78rem;
    line-height: 1.2;
    word-break: break-word;
  }

  .thirdparty-list {
    gap: 0.65rem;
  }

  .thirdparty-card {
    padding: 0.85rem;
  }

  .thirdparty-card-head {
    padding-bottom: 0.65rem;
  }

  .thirdparty-card-head h3 {
    font-size: 1rem;
    line-height: 1.38;
  }

  .thirdparty-card-grid {
    gap: 0.45rem;
    padding: 0.65rem 0;
  }

  .thirdparty-card-grid span {
    font-size: 0.74rem;
  }

  .thirdparty-card-grid strong {
    font-size: 0.92rem;
  }

  .thirdparty-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .thirdparty-card-actions button {
    min-height: 2.35rem;
    padding: 0 0.45rem;
  }

  .thirdparty-password-dialog {
    width: min(23rem, calc(100% - 1.25rem));
    padding: 1rem;
    border-radius: 24px;
  }

  .thirdparty-password-head {
    padding: 0.45rem 2.35rem 0.8rem;
  }

  .thirdparty-password-head h2 {
    font-size: 1.22rem;
  }

  .thirdparty-password-head p:last-child {
    font-size: 0.86rem;
  }

  .thirdparty-password-body input,
  .thirdparty-password-body .primary-button {
    min-height: 2.75rem;
  }

  .policy-toolbar {
    grid-template-columns: 1fr;
  }

  .thirdparty-status {
    position: static;
  }

  .thirdparty-card-head {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .thirdparty-tax {
    grid-column: 2;
  }

  .thirdparty-detail-grid {
    grid-template-columns: 1fr;
  }

  .project-actions {
    margin-top: -0.25rem;
  }

  .project-head {
    align-items: flex-start;
    flex-direction: row;
    gap: 0.75rem;
  }

  .project-title-area {
    min-width: 0;
    flex: 1;
  }

  .project-name-field {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .delete-project {
    width: 2.2rem;
    min-width: 2.2rem;
    height: 2.2rem;
    min-height: 2.2rem;
    padding: 0;
    flex: 0 0 auto;
    font-size: 1.2rem;
  }

  .tax-picker select,
  label input,
  label select,
  .month-table input,
  .month-table select,
  .project-name {
    min-width: 0;
    max-width: 100%;
  }

  .project-date-grid > label,
  .project-date-grid > div {
    min-width: 0;
  }

  .project-date-grid input,
  .project-date-grid select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    text-align: left;
  }

  .month-table-wrap {
    border-radius: var(--radius-md);
  }

  .month-table {
    min-width: 1120px;
  }

  .month-table th,
  .month-table td {
    padding: 0.65rem 0.55rem;
  }

  .month-table th:first-child,
  .month-table td:first-child {
    width: 4.9rem;
    min-width: 4.9rem;
    max-width: 4.9rem;
    font-size: 0.78rem;
  }

  .month-table .stage-column,
  .month-table td:nth-child(2) {
    width: 10rem;
    min-width: 10rem;
  }

  .month-table .days-column,
  .month-table td:nth-child(3) {
    width: 6.2rem;
    min-width: 6.2rem;
  }

  .month-table .area-column,
  .area-fields {
    min-width: 14rem;
  }

  .primary-measures {
    min-width: 13rem;
  }

  .compact-field {
    grid-template-columns: 6rem minmax(5rem, 1fr);
    gap: 0.35rem;
  }

  .compact-field input {
    width: 100%;
  }

  .summary-panel {
    position: static;
  }

  .primary-button,
  .secondary-button,
  .summary-actions .ghost-button {
    width: 100%;
  }

  .summary-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .detail-modal {
    place-items: center;
    padding: 1rem;
  }

  .detail-dialog {
    width: min(100% - 0.5rem, 34rem);
    max-height: 78vh;
    border-radius: 18px;
  }

  #thirdpartyView {
    padding-bottom: 4.8rem;
  }

  .thirdparty-status {
    position: fixed;
    left: 0.5rem;
    right: 0.5rem;
    bottom: calc(0.5rem + env(safe-area-inset-bottom));
    width: auto;
    transform: none;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .thirdparty-card-head {
    grid-template-columns: minmax(0, 1fr);
  }

  .thirdparty-tax {
    grid-column: 1;
    justify-self: end;
    max-width: 100%;
    width: auto;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: right;
    white-space: normal;
  }

  .thirdparty-card-head h3 {
    padding-right: 0;
    overflow-wrap: anywhere;
  }
}
