:root {
  color-scheme: light;
  --bg: #f4f8f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --brand: #58b9bd;
  --brand-dark: #3f9fa5;
  --muted: #5f6f7a;
  --line: #d7e1e3;
  --primary: #007c89;
  --primary-dark: #006775;
  --primary-light: #d8f0f2;
  --danger: #b42318;
  --gain: #067647;
  --loss: #b42318;
  --soft: #e8f5f6;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  padding: 0 14px;
}

button:hover {
  border-color: #91a5aa;
}

button:disabled {
  border-color: #d4dde1;
  background: #eef3f4;
  color: #8a99a3;
  cursor: not-allowed;
}

.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

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

.danger {
  border-color: #efb4ad;
  color: var(--danger);
}

button.complete {
  border-color: var(--primary);
  background: var(--soft);
  color: var(--primary-dark);
  font-weight: 700;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 32px;
  box-shadow: 0 24px 80px rgba(29, 39, 48, 0.12);
}

.login-panel h1,
.sidebar h1,
.topbar h2,
.section h3 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.stack {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span,
.section-head span,
.summary-grid span,
.muted {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.result-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.55;
}

input,
select {
  min-width: 0;
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 7px 10px;
}

input:focus,
select:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(0, 124, 137, 0.14);
}

input:disabled {
  border-color: #e3eaec;
  background: #f2f6f6;
  color: #84939b;
  cursor: not-allowed;
}

.error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
}

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

.form-message.is-error {
  color: var(--danger);
}

.form-message.is-success {
  color: var(--primary);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 18px;
  height: 100vh;
  border-right: 1px solid var(--brand-dark);
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #ffffff;
  padding: 22px;
}

.sidebar h1 {
  color: #ffffff;
}

.sidebar .eyebrow {
  color: rgba(255, 255, 255, 0.86);
}

.sidebar .app-subtitle,
.sidebar label span {
  color: rgba(255, 255, 255, 0.86);
}

.fiscal-selector {
  display: grid;
  gap: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom: 1px solid rgba(255, 255, 255, 0.28);
  padding: 14px 0;
}

.fiscal-selector button {
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.fiscal-selector button:hover {
  border-color: #ffffff;
  background: rgba(255, 255, 255, 0.16);
}

.company-panel,
.user-panel {
  position: fixed;
  z-index: 20;
  top: 50%;
  left: 50%;
  display: none;
  width: min(486px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  transform: translate(-50%, -50%);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 22px;
  box-shadow: 0 24px 80px rgba(29, 39, 48, 0.22);
}

.user-panel {
  width: min(860px, calc(100vw - 24px));
}

.company-panel.open,
.user-panel.open {
  display: grid;
}

.company-panel h2,
.user-panel h2 {
  margin: 0;
  font-size: 14px;
}

.company-panel button {
  width: 100%;
}

.company-panel label,
.company-panel > button,
.user-panel label {
  width: 100%;
}

.company-panel label span,
.user-panel label span {
  color: var(--muted);
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.company-panel label:has(#companyFiscalYearSelect) {
  display: none;
}

.company-draft-notice {
  margin: 0;
  border: 1px solid #d8a833;
  border-radius: 6px;
  background: #fff7df;
  color: #6f4d00;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.company-panel .table-wrap {
  width: max-content;
  max-width: 100%;
}

.company-panel .table-wrap table {
  width: auto;
  min-width: 430px;
}

.company-panel .table-wrap th,
.company-panel .table-wrap td {
  padding: 8px 12px;
  text-align: left;
}

.company-panel .table-wrap th:nth-child(1),
.company-panel .table-wrap td:nth-child(1),
.company-panel .table-wrap th:nth-child(2),
.company-panel .table-wrap td:nth-child(2) {
  width: 143px;
}

.company-panel .table-wrap th:nth-child(3),
.company-panel .table-wrap td:nth-child(3) {
  width: 144px;
}

.company-panel .table-wrap button {
  width: auto;
  min-width: 52px;
  padding: 0 10px;
}

.user-panel .table-wrap {
  width: 100%;
  overflow-x: hidden;
}

.user-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.user-table th,
.user-table td {
  padding: 9px 8px;
  text-align: left;
}

.user-table th {
  color: var(--muted);
}

.user-table td {
  color: var(--ink);
}

.user-table th:nth-child(1),
.user-table td:nth-child(1) {
  width: 20%;
}

.user-table th:nth-child(2),
.user-table td:nth-child(2) {
  width: 22%;
}

.user-table th:nth-child(3),
.user-table td:nth-child(3) {
  width: 20%;
}

.user-table th:nth-child(4),
.user-table td:nth-child(4) {
  width: 18%;
}

.user-table th:nth-child(5),
.user-table td:nth-child(5) {
  width: 20%;
}

.user-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-table .fiscal-year-actions {
  justify-content: flex-end;
}

.user-table button {
  min-width: 48px;
  padding: 0 8px;
}

.fiscal-year-actions {
  display: flex;
  gap: 6px;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.property-list {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
}

.property-group-title {
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: 12px;
  font-weight: 700;
}

.property-group-empty {
  margin: 0 0 6px;
}

.property-list .muted {
  color: rgba(255, 255, 255, 0.82);
}

.property-item {
  display: grid;
  gap: 5px;
  width: 100%;
  height: auto;
  min-height: 74px;
  justify-items: start;
  text-align: left;
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
}

.property-item.active {
  border-color: #ffffff;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(0, 96, 106, 0.22);
}

.property-item.completed {
  border-color: rgba(255, 255, 255, 0.72);
}

.property-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.status-badge {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
}

.settlement-dates {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.workspace {
  min-width: 0;
  padding: 0 24px 24px;
}

.topbar,
.section-head,
.form-actions,
.actions {
  display: flex;
  align-items: center;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  justify-content: space-between;
  gap: 16px;
  margin: 0 -24px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 248, 249, 0.96);
  padding: 22px 24px;
  backdrop-filter: blur(8px);
}

.actions,
.form-actions {
  gap: 10px;
}

.topbar .actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-company {
  margin: 0 8px 0 0;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
}

.purchase-save-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

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

.summary-grid article,
.calc-grid article {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.summary-grid strong {
  font-size: 22px;
}

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

.calc-grid strong {
  font-size: 18px;
}

.cost-analysis-table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}

.cost-analysis-table {
  min-width: 840px;
}

.cost-analysis-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.analysis-subtitle {
  margin: 16px 0 0;
  font-size: 14px;
}

.cost-analysis-summary article {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
  padding: 14px 16px;
}

.cost-analysis-summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.cost-analysis-summary strong {
  justify-self: end;
  font-size: 20px;
}

.tax-reference {
  margin-top: 18px;
}

.tax-reference h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.tax-reference article {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr);
  align-items: center;
  gap: 12px;
  max-width: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
  padding: 14px 16px;
}

.tax-reference span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tax-reference strong {
  justify-self: end;
  font-size: 20px;
}

.simulation-sheet {
  display: grid;
  gap: 22px;
}

.simulation-entry {
  max-width: 640px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

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

.section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

.section-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.tax-rate-field {
  width: 140px;
}

.fields {
  display: grid;
  gap: 12px;
}

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

.usage-notice {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
  background: #f8fbfb;
  padding: 14px 16px;
}

.usage-notice > div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px 12px;
}

.usage-notice span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.usage-notice strong {
  font-size: 14px;
}

.usage-notice p {
  margin: 0;
  line-height: 1.65;
}

.usage-notice ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.usage-notice-caution {
  border-color: #d8a833;
  background: #fff8e6;
}

.usage-notice-confirm {
  border-color: #a5b4fc;
  background: #eef2ff;
}

.usage-notice-ok {
  border-color: #9ad4bd;
  background: #effaf4;
}

.related-doc-field {
  grid-column: 1 / -1;
}

.related-doc-preview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
  padding: 12px 14px;
}

.related-doc-preview div {
  min-width: 0;
}

.related-doc-preview span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.related-doc-preview strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.related-doc-preview a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

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

.stacked-field {
  grid-column: 1 / -1;
  max-width: 320px;
}

.asset-table,
.result-table {
  width: 100%;
  overflow-x: auto;
  margin-top: 16px;
}

.extra-costs {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 16px;
}

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

.extra-costs h4 {
  margin: 0;
  font-size: 16px;
}

.extra-cost-list {
  display: grid;
  gap: 10px;
  overflow-x: auto;
}

.empty-costs {
  margin: 0;
}

.extra-cost-entry {
  display: grid;
  grid-template-columns: 150px 150px minmax(180px, 1fr) minmax(220px, 1.3fr) 180px 140px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.extra-cost-table {
  min-width: 900px;
}

.extra-cost-table .editing-row td {
  background: var(--soft);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.extra-cost-total {
  display: grid;
  grid-template-columns: auto auto auto auto;
  justify-content: end;
  gap: 10px 16px;
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 12px;
}

.extra-cost-total span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  background: #f8fbfb;
}

td input {
  text-align: right;
}

.amount {
  font-variant-numeric: tabular-nums;
}

.gain {
  color: var(--gain);
}

.loss {
  color: var(--loss);
}

.form-actions {
  justify-content: flex-end;
  padding-bottom: 32px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .summary-grid,
  .calc-grid,
  .cost-analysis-summary,
  .form-grid,
  .fields.two,
  .fields.three,
  .extra-cost-entry,
  .extra-cost-total {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

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

  .simulation-entry {
    max-width: none;
  }
}
