:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1f2933;
  --muted: #657285;
  --accent: #176b87;
  --accent-dark: #0f5168;
  --green: #247a4d;
  --red: #a33d3d;
  --yellow: #9a6a00;
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

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

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
}

.header-actions,
.dialog-actions,
.toolbar,
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.ghost-button,
.upload-button,
.icon-button,
.tab {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
}

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

.ghost-button {
  padding: 10px 14px;
}

.danger-button {
  border-color: #d7a8a8;
  color: var(--red);
}

.upload-button {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border-color: var(--accent);
  padding: 10px 14px;
  background: #eaf5f8;
  color: var(--accent-dark);
  cursor: pointer;
}

.upload-button input {
  display: none;
}

.icon-button {
  width: 32px;
  height: 32px;
  font-weight: 700;
}

main {
  padding: 20px 32px 32px;
}

.summary-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.month-picker,
.metric {
  min-height: 88px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.month-picker span,
.metric span,
.field span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.month-picker input,
.field input,
.field select,
.field textarea,
.search {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}

.field textarea {
  resize: vertical;
  line-height: 1.5;
}

.metric strong {
  font-size: 24px;
}

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

.side-panel,
.main-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.side-panel {
  padding: 16px;
}

.panel-section + .panel-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.section-title {
  justify-content: space-between;
  margin-bottom: 10px;
}

.file-drop {
  display: grid;
  place-items: center;
  min-height: 86px;
  margin: 12px 0;
  border: 1px dashed #aeb8c6;
  border-radius: 8px;
  color: var(--accent);
  background: #f9fbfc;
  cursor: pointer;
}

.file-drop input {
  display: none;
}

.field {
  display: block;
  margin-top: 12px;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.card-item,
.rule-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.card-item + .card-item,
.rule-item + .rule-item {
  margin-top: 8px;
}

.card-item strong,
.rule-item strong {
  font-size: 14px;
}

.card-item span,
.rule-item span {
  color: var(--muted);
  font-size: 12px;
}

.main-panel {
  overflow: hidden;
}

.bank-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.bank-panel > .section-title {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.compact-file-button {
  display: inline-grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.compact-file-button input {
  display: none;
}

.bank-toolbar {
  border-bottom: 1px solid var(--line);
}

.bank-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.bank-metrics span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.bank-metrics strong {
  margin-left: 6px;
  color: var(--text);
}

.invoice-builder {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(520px, 1.1fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.invoice-builder.hidden {
  display: none;
}

.invoice-editor,
.invoice-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.invoice-editor {
  padding: 16px;
}

.invoice-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 12px;
  margin-top: 12px;
}

.invoice-form-grid .field:nth-last-child(-n + 2) {
  grid-column: span 1;
}

.invoice-lines-wrap {
  margin-top: 16px;
  overflow: auto;
}

.invoice-lines-table {
  min-width: 620px;
}

.invoice-lines-table td,
.invoice-lines-table th {
  padding: 8px;
}

.line-remove,
.row-delete {
  width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.row-delete {
  border-color: #d7a8a8;
  color: var(--red);
}

.invoice-preview {
  min-height: 760px;
  padding: 28px;
}

.invoice-paper {
  max-width: 760px;
  margin: 0 auto;
  color: #20242a;
  background: #fff;
}

.invoice-paper-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 3px solid #20242a;
  padding-bottom: 18px;
}

.invoice-paper h2 {
  font-size: 30px;
  letter-spacing: 0;
}

.invoice-meta {
  min-width: 210px;
  color: #424b57;
  font-size: 13px;
  line-height: 1.8;
}

.invoice-client-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 28px;
  margin-top: 28px;
}

.invoice-client {
  border-bottom: 1px solid #20242a;
  font-size: 18px;
  font-weight: 700;
  padding-bottom: 8px;
}

.invoice-issuer {
  white-space: pre-line;
  line-height: 1.65;
}

.invoice-total-box {
  display: inline-grid;
  grid-template-columns: auto auto;
  gap: 0;
  margin-top: 28px;
  border: 2px solid #20242a;
}

.invoice-total-box span,
.invoice-total-box strong {
  padding: 10px 18px;
}

.invoice-total-box span {
  background: #eef2f5;
  font-weight: 700;
}

.invoice-total-box strong {
  min-width: 180px;
  text-align: right;
  font-size: 20px;
}

.invoice-detail {
  width: 100%;
  min-width: 0;
  margin-top: 28px;
  border-collapse: collapse;
}

.invoice-detail th {
  background: #20242a;
  color: #fff;
}

.invoice-detail th,
.invoice-detail td {
  border: 1px solid #bcc4ce;
  padding: 10px;
}

.invoice-detail .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.invoice-summary {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 8px 18px;
  margin: 18px 0 0 auto;
  max-width: 360px;
  font-variant-numeric: tabular-nums;
}

.invoice-summary span:nth-child(odd) {
  color: #596575;
}

.invoice-summary span:nth-child(even) {
  text-align: right;
}

.invoice-summary .grand {
  border-top: 2px solid #20242a;
  padding-top: 8px;
  font-size: 18px;
  font-weight: 700;
}

.invoice-bank {
  margin-top: 34px;
  border-top: 1px solid #bcc4ce;
  padding-top: 16px;
  white-space: pre-line;
  line-height: 1.65;
}

.toolbar {
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab {
  min-width: 86px;
  padding: 8px 10px;
}

.tab.active {
  border-color: var(--accent);
  background: #eaf5f8;
  color: var(--accent-dark);
}

.search {
  max-width: 280px;
}

.table-wrap {
  overflow: auto;
}

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

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

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

td input,
td select {
  width: 100%;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 6px 8px;
  background: transparent;
}

td input:focus,
td select:focus {
  border-color: var(--accent);
  background: #fff;
  outline: none;
}

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

.status-expense {
  color: var(--green);
}

.status-private {
  color: var(--red);
}

.status-pending {
  color: var(--yellow);
}

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgba(31, 41, 51, 0.28);
}

.dialog-form {
  padding: 20px;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 20px;
}

.empty-state {
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 920px) {
  .app-header,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  main {
    padding: 16px;
  }

  .summary-grid,
  .workspace,
  .bank-toolbar,
  .invoice-builder,
  .invoice-form-grid {
    grid-template-columns: 1fr;
  }

  .header-actions,
  .tabs {
    flex-wrap: wrap;
  }

  .search {
    max-width: none;
  }
}

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

  .app-header,
  .summary-grid,
  .workspace,
  .bank-panel,
  .invoice-editor {
    display: none !important;
  }

  main {
    padding: 0;
  }

  .invoice-builder {
    display: block;
    margin: 0;
  }

  .invoice-preview {
    border: 0;
    border-radius: 0;
    min-height: auto;
    padding: 0;
  }

  .invoice-paper {
    max-width: none;
    padding: 14mm;
  }
}
