:root {
  color-scheme: light;
  --bg: #edf8f8;
  --panel: #ffffff;
  --panel-soft: #e2f3f4;
  --text: #122b33;
  --muted: #5c7479;
  --line: #cfe3e5;
  --brand: #159aa6;
  --brand-strong: #167f87;
  --brand-soft: #3fb4b2;
  --brand-pale: #e8f6f7;
  --table-head: #dff1f2;
  --table-sticky: #f7fbfb;
  --green: #18775b;
  --yellow: #8a6400;
  --red: #a13d3d;
  --shadow: 0 10px 24px rgba(13, 91, 99, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  background: var(--brand-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.secondary {
  background: #fff;
  color: var(--brand);
}

button.secondary:hover {
  background: var(--panel-soft);
}

button.danger {
  border-color: #c87a7a;
  background: #fff;
  color: var(--red);
}

button.danger:hover {
  background: #fff1f1;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 28px;
  background: var(--brand);
  color: #fff;
}

.app-header h1 {
  margin: 2px 0 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

.header-subtitle {
  color: #eefcfc;
  font-size: 13px;
  font-weight: 600;
  margin: 3px 0 0;
}

.eyebrow {
  margin: 0;
  color: #d6f4f5;
  font-size: 12px;
  text-transform: uppercase;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.side-panel,
.panel,
.metric-card,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.side-panel {
  background: var(--brand-soft);
  border-color: #36a9ad;
  height: fit-content;
  padding: 16px;
  display: grid;
  gap: 14px;
  min-width: 0;
}

.side-panel label {
  color: #f2ffff;
}

.side-panel .field-note {
  color: #d8f5f5;
}

.side-panel .status-box {
  background: #eefafa;
  color: #365a60;
}

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

.field-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

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

input:focus,
select:focus {
  border-color: var(--brand);
  outline: 2px solid rgba(21, 154, 166, 0.18);
}

.file-picker input {
  padding: 7px;
  max-width: 100%;
}

.status-box {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  padding: 10px;
  line-height: 1.5;
}

.status-warning {
  color: var(--yellow);
  display: inline-block;
  font-weight: 700;
  margin-top: 4px;
}

.inline-announcement {
  border: 1px solid #b8ded0;
  border-radius: 6px;
  background: #e9f7f1;
  color: var(--green);
  font-weight: 700;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.inline-warning {
  border: 1px solid #e3c36c;
  border-radius: 6px;
  background: #fff7df;
  color: var(--yellow);
  font-weight: 700;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.panel-note {
  color: var(--muted);
  font-size: 12px;
  margin: -4px 0 12px;
}

.actions-stack {
  display: grid;
  gap: 8px;
}

.actions-stack button,
.side-panel > button {
  width: 100%;
}

.side-panel button:not(.secondary):not(.danger) {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
}

.side-panel button:not(.secondary):not(.danger):hover {
  background: #0d6f78;
}

.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.content {
  min-width: 0;
  display: grid;
  gap: 14px;
  align-content: start;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px;
}

.metric-card {
  padding: 14px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.metric-card strong {
  font-size: 21px;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  min-height: 44px;
}

.tab {
  flex: 0 0 auto;
  min-height: 38px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 6px 6px 0 0;
}

.tab.active,
.tab:hover {
  background: var(--panel-soft);
  color: var(--brand-strong);
}

.panel {
  padding: 14px;
  overflow: hidden;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

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

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

.pl-table {
  min-width: 1320px;
}

.comparison-table {
  min-width: 860px;
}

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

th {
  position: sticky;
  top: 0;
  background: var(--table-head);
  color: #006875;
  font-size: 12px;
  z-index: 1;
}

.account-heading {
  left: 0;
  min-width: 220px;
  position: sticky;
  z-index: 2;
}

.account-name {
  background: var(--table-sticky);
  left: 0;
  min-width: 220px;
  position: sticky;
  z-index: 1;
}

.indent-account {
  padding-left: 28px;
}

.indent-classification-account {
  padding-left: 46px;
}

td.numeric,
th.numeric {
  text-align: right;
}

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

.total-row td {
  background: var(--brand-pale);
  font-weight: 700;
}

.total-row .account-name {
  background: var(--brand-pale);
}

.subtotal-row td {
  background: #d8eff0;
  color: var(--brand-strong);
  font-weight: 700;
}

.subtotal-row .account-name {
  background: #d8eff0;
}

.classification-row td {
  background: #eef9f9;
  color: #38474c;
  font-weight: 700;
}

.classification-row .account-name {
  background: #eef9f9;
  padding-left: 28px;
}

.classification-account-row .account-name {
  background: var(--table-sticky);
}

.ledger-status-provisional td {
  background: #f4f8ff;
}

.ledger-status-provisional td:first-child {
  border-left: 4px solid #4f7fcf;
}

.ledger-status-needs_review td {
  background: #fff8e5;
}

.ledger-status-needs_review td:first-child {
  border-left: 4px solid #c9911a;
}

.ledger-status-confirmed td {
  background: #fbfdfc;
}

.group-row td {
  background: var(--brand-strong);
  color: #fff;
  font-weight: 700;
}

.group-row .account-name {
  background: var(--brand-strong);
}

.ledger-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(180px, 260px) 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.pagination-bar {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-bottom: 10px;
}

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

.compare-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.master-form {
  align-items: end;
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(150px, 0.7fr) minmax(150px, 0.7fr) auto;
  gap: 10px;
  margin-bottom: 12px;
}

.account-order-form {
  grid-template-columns: minmax(220px, 1fr) minmax(120px, 0.35fr) auto;
}

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

.classification-rule-form {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.classification-rule-form button {
  align-self: stretch;
}

.subsection-title {
  font-size: 15px;
  margin: 16px 0 10px;
}

.classification-select,
.status-select {
  min-width: 126px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  background: #e9eef0;
  color: #4a5d62;
}

.tag.needs_review {
  background: #fff4d6;
  color: var(--yellow);
}

.tag.confirmed {
  background: #dff2eb;
  color: var(--green);
}

.tag.provisional {
  background: #e6eefb;
  color: #325b98;
}

.empty-state {
  padding: 42px;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.hidden {
  display: none;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

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

  .pagination-bar {
    justify-content: flex-start;
  }

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

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

  .form-actions {
    display: grid;
  }
}

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

  .metrics {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body {
    background: #fff;
    color: #111;
    font-size: 9pt;
  }

  .app-header,
  .side-panel,
  .tabs,
  .metrics,
  .no-print,
  .panel.hidden {
    display: none !important;
  }

  .workspace {
    display: block;
    padding: 0;
  }

  .content {
    display: block;
  }

  .panel {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    padding: 0;
  }

  .panel-header {
    margin-bottom: 8px;
  }

  .table-wrap {
    border: 0;
    border-radius: 0;
    overflow: visible;
  }

  table,
  .pl-table,
  .comparison-table {
    min-width: 0;
  }

  th,
  td {
    padding: 4px 5px;
    white-space: nowrap;
  }

  th,
  .account-heading,
  .account-name {
    position: static;
  }
}
