:root {
  --cash-bg: #bebebe;
  --cash-panel: #ffffff;
  --cash-panel-soft: #f8fafc;
  --cash-line: rgba(87, 76, 66, 0.18);
  --cash-text: #211c17;
  --cash-muted: rgba(64, 55, 48, 0.66);
  --cash-orange: #f18f01;
  --cash-orange-dark: #b86700;
  --cash-green: #157a4f;
  --cash-red: #b43c2d;
  --cash-shadow: 0 16px 28px rgba(82, 60, 46, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "IBM Plex Sans KR", "Malgun Gothic", "Segoe UI", sans-serif;
  color: var(--cash-text);
  background: linear-gradient(180deg, #c6c6c6 0%, var(--cash-bg) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 120px 120px;
  opacity: 0.22;
}

.cash-flow-page {
  position: relative;
  width: min(1480px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  gap: 10px;
  align-content: start;
}

[hidden] {
  display: none !important;
}

.cash-flow-page .page-header,
.cash-flow-panel,
.cash-flow-summary-card {
  border: 1px solid var(--cash-line);
  border-radius: 0;
  background: linear-gradient(180deg, var(--cash-panel), var(--cash-panel-soft));
  box-shadow: var(--cash-shadow);
}

.cash-flow-page .page-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  min-height: 0;
  height: auto;
  padding: 24px 16px 14px;
  overflow: hidden;
}

.cash-flow-page .page-header::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 16px;
  right: 16px;
  height: 1px;
  background: rgba(241, 143, 1, 0.34);
}

.cash-flow-page .subpage-title {
  position: relative;
  z-index: 1;
  margin: 0;
  color: var(--cash-orange);
  font-weight: 700;
  letter-spacing: 0;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.02;
}

.cash-flow-page .home-link {
  border: 1px solid rgba(241, 143, 1, 0.32);
  border-radius: 0;
  background: rgba(255, 255, 254, 0.98);
  color: var(--cash-orange);
  box-shadow: none;
}

.cash-flow-page .home-link:hover {
  background: var(--cash-orange);
  color: #fffaf1;
  border-color: var(--cash-orange);
}

.cash-flow-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
}

.cash-flow-auth-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 0;
  padding: 12px;
}

.cash-flow-auth-form,
.cash-flow-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cash-flow-field {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid rgba(109, 96, 86, 0.16);
  background: rgba(255, 255, 255, 0.99);
}

.cash-flow-field span {
  padding: 0 10px;
  color: var(--cash-muted);
  font-size: 13px;
  font-weight: 800;
}

.cash-flow-field input {
  width: 84px;
  height: 40px;
  border: 0;
  border-left: 1px solid rgba(109, 96, 86, 0.12);
  background: transparent;
  color: #3f352d;
  font: inherit;
  font-weight: 800;
  text-align: center;
  outline: none;
}

.cash-flow-auth-form .cash-flow-field input {
  width: 160px;
  text-align: left;
  padding: 0 12px;
}

.cash-flow-button {
  min-width: 76px;
  height: 42px;
  border: 1px solid var(--cash-orange);
  border-radius: 0;
  background: var(--cash-orange);
  color: #fffaf1;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.cash-flow-button:hover:not(:disabled),
.cash-flow-button:focus-visible {
  background: var(--cash-orange-dark);
  border-color: var(--cash-orange-dark);
}

.cash-flow-button:disabled {
  opacity: 0.62;
  cursor: wait;
}

.cash-flow-status {
  color: var(--cash-muted);
  font-size: 13px;
  font-weight: 800;
}

.cash-flow-status[data-tone="error"] {
  color: var(--cash-red);
}

.cash-flow-status[data-tone="success"] {
  color: var(--cash-green);
}

.cash-flow-content {
  display: grid;
  gap: 10px;
}

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

.cash-flow-summary-card {
  display: grid;
  gap: 6px;
  min-height: 82px;
  padding: 16px;
}

.cash-flow-summary-card span {
  color: var(--cash-muted);
  font-size: 13px;
  font-weight: 800;
}

.cash-flow-summary-card strong {
  color: #3d352e;
  font-size: clamp(20px, 2.6vw, 30px);
  font-weight: 900;
  line-height: 1;
  word-break: keep-all;
}

.cash-flow-summary-card strong[data-sign="negative"] {
  color: var(--cash-red);
}

.cash-flow-summary-card strong[data-sign="positive"] {
  color: var(--cash-green);
}

.cash-flow-sections {
  display: grid;
  gap: 10px;
}

.cash-flow-section {
  padding: 18px;
}

.cash-flow-section-head,
.cash-flow-group-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.cash-flow-section-head h2,
.cash-flow-group-head h3 {
  margin: 0;
  color: #3e362f;
  font-size: 20px;
  line-height: 1.15;
}

.cash-flow-group-head h3 {
  font-size: 16px;
}

.cash-flow-group-head p {
  margin: 5px 0 0;
  color: var(--cash-muted);
  font-size: 12px;
  font-weight: 800;
}

.cash-flow-section-summary,
.cash-flow-group-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--cash-muted);
  font-size: 12px;
  font-weight: 900;
}

.cash-flow-section-summary strong,
.cash-flow-group-summary strong {
  color: #3e362f;
}

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

.cash-flow-group {
  min-width: 0;
  display: grid;
  gap: 10px;
  align-content: start;
  grid-template-rows: max-content max-content;
  padding-top: 12px;
  border-top: 2px solid rgba(241, 143, 1, 0.22);
}

.cash-flow-table-wrap {
  overflow-x: auto;
  border: 1px solid rgba(109, 96, 86, 0.16);
  background: #fff;
}

.cash-flow-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  table-layout: fixed;
}

.cash-flow-table th,
.cash-flow-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(109, 96, 86, 0.1);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  line-height: 1.35;
}

.cash-flow-table th {
  background: #fff8ec;
  color: #5c5148;
  font-weight: 900;
  white-space: nowrap;
}

.cash-flow-table th:nth-child(1) {
  width: 22%;
}

.cash-flow-table th:nth-child(2) {
  width: 18%;
}

.cash-flow-table th:nth-child(3) {
  width: 18%;
}

.cash-flow-table th:nth-child(4) {
  width: 26%;
}

.cash-flow-table th:nth-child(5) {
  width: 7%;
}

.cash-flow-table th:nth-child(6) {
  width: 9%;
}

.cash-flow-name-cell {
  display: grid;
  gap: 4px;
  padding-left: calc(var(--depth, 0) * 14px);
}

.cash-flow-name-cell strong {
  color: #3e362f;
  font-weight: 900;
  word-break: keep-all;
}

.cash-flow-direction {
  display: inline-flex;
  width: fit-content;
  min-height: 20px;
  align-items: center;
  padding: 2px 6px;
  border: 1px solid rgba(90, 80, 70, 0.14);
  background: #f6f6f6;
  color: #675d55;
  font-size: 11px;
  font-weight: 900;
}

.cash-flow-direction[data-direction="inflow"] {
  border-color: rgba(21, 122, 79, 0.2);
  background: rgba(21, 122, 79, 0.08);
  color: var(--cash-green);
}

.cash-flow-direction[data-direction="outflow"] {
  border-color: rgba(180, 60, 45, 0.2);
  background: rgba(180, 60, 45, 0.08);
  color: var(--cash-red);
}

.cash-flow-table td:nth-child(2) strong {
  display: block;
  color: #2e2823;
  font-size: 14px;
  font-weight: 900;
  text-align: right;
}

.cash-flow-amount-stack {
  display: grid;
  gap: 3px;
}

.cash-flow-amount-stack span {
  color: var(--cash-muted);
  font-size: 11px;
  font-weight: 800;
  text-align: right;
}

.cash-flow-amount-button {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid rgba(241, 143, 1, 0.3);
  background: #fffaf1;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.cash-flow-amount-button:hover,
.cash-flow-amount-button:focus-visible {
  border-color: var(--cash-orange);
  background: #fff2dc;
  outline: 2px solid rgba(241, 143, 1, 0.18);
}

.cash-flow-amount-hint {
  display: block;
  margin-top: 3px;
  color: var(--cash-orange-dark);
  font-size: 10px;
  font-weight: 900;
  text-align: right;
}

.cash-flow-detail-dialog {
  width: min(1180px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid rgba(87, 76, 66, 0.24);
  background: #fff;
  color: var(--cash-text);
  box-shadow: 0 24px 70px rgba(43, 34, 27, 0.28);
}

.cash-flow-detail-dialog::backdrop {
  background: rgba(31, 27, 23, 0.55);
  backdrop-filter: blur(2px);
}

.cash-flow-detail-shell {
  display: grid;
  max-height: calc(100vh - 34px);
  grid-template-rows: auto auto minmax(0, 1fr);
}

.cash-flow-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--cash-line);
  background: #fff8ec;
}

.cash-flow-detail-kicker {
  color: var(--cash-orange-dark);
  font-size: 11px;
  font-weight: 900;
}

.cash-flow-detail-header h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.cash-flow-detail-header p {
  margin: 5px 0 0;
  color: var(--cash-muted);
  font-size: 13px;
  font-weight: 800;
}

.cash-flow-detail-close {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(87, 76, 66, 0.18);
  background: #fff;
  color: #4a4038;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.cash-flow-detail-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  border-bottom: 1px solid var(--cash-line);
  background: var(--cash-line);
}

.cash-flow-detail-summary div {
  display: grid;
  gap: 4px;
  padding: 13px 18px;
  background: #fff;
}

.cash-flow-detail-summary span {
  color: var(--cash-muted);
  font-size: 12px;
  font-weight: 800;
}

.cash-flow-detail-summary strong {
  color: #302923;
  font-size: 20px;
  text-align: right;
}

.cash-flow-detail-body {
  display: grid;
  gap: 18px;
  overflow: auto;
  padding: 18px 22px 24px;
  background: #f7f7f5;
}

.cash-flow-detail-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.cash-flow-detail-section h3 span {
  color: var(--cash-muted);
  font-size: 12px;
}

.cash-flow-detail-section[data-tone="outstanding"] h3 {
  color: var(--cash-red);
}

.cash-flow-detail-section[data-tone="paid"] h3 {
  color: var(--cash-green);
}

.cash-flow-detail-table-wrap {
  overflow: auto;
  border: 1px solid var(--cash-line);
  background: #fff;
}

.cash-flow-detail-table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
}

.cash-flow-detail-table th,
.cash-flow-detail-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(109, 96, 86, 0.1);
  text-align: right;
  vertical-align: top;
  font-size: 12px;
}

.cash-flow-detail-table th {
  position: sticky;
  top: 0;
  background: #fff8ec;
  color: #5c5148;
  font-weight: 900;
  white-space: nowrap;
}

.cash-flow-detail-table th:first-child,
.cash-flow-detail-table td:first-child,
.cash-flow-detail-table th:last-child,
.cash-flow-detail-table td:last-child {
  text-align: left;
}

.cash-flow-detail-table td:first-child strong,
.cash-flow-detail-table td:first-child span,
.cash-flow-detail-table td:last-child small {
  display: block;
}

.cash-flow-detail-table td:first-child span,
.cash-flow-detail-table td:last-child small {
  margin-top: 3px;
  color: var(--cash-muted);
  font-size: 10px;
}

.cash-flow-detail-status {
  display: inline-flex;
  padding: 2px 6px;
  border: 1px solid rgba(180, 60, 45, 0.22);
  background: rgba(180, 60, 45, 0.08);
  color: var(--cash-red);
  font-size: 11px;
  font-weight: 900;
}

.cash-flow-detail-status[data-status="paid"] {
  border-color: rgba(21, 122, 79, 0.22);
  background: rgba(21, 122, 79, 0.08);
  color: var(--cash-green);
}

.cash-flow-detail-status[data-status="partial"] {
  border-color: rgba(241, 143, 1, 0.28);
  background: rgba(241, 143, 1, 0.1);
  color: var(--cash-orange-dark);
}

.cash-flow-child-row td {
  background: #fffdf8;
}

.cash-flow-parent-row td {
  border-top: 2px solid rgba(241, 143, 1, 0.55);
  border-bottom-color: rgba(241, 143, 1, 0.3);
  background: #fff3df;
}

.cash-flow-parent-row .cash-flow-name-cell strong {
  color: #b86800;
  font-size: 14px;
}

.cash-flow-group-label {
  width: fit-content;
  padding: 2px 6px;
  border: 1px solid rgba(241, 143, 1, 0.4);
  background: #fff;
  color: #a75d00;
  font-size: 10px;
  font-weight: 900;
}

.cash-flow-child-row td:first-child {
  border-left: 4px solid rgba(241, 143, 1, 0.48);
}

.cash-flow-child-row .cash-flow-name-cell {
  position: relative;
  padding-left: 28px;
}

.cash-flow-child-row .cash-flow-name-cell::before {
  content: "·";
  position: absolute;
  left: 10px;
  top: 23px;
  color: #d77b00;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.cash-flow-child-last td {
  border-bottom: 2px solid rgba(241, 143, 1, 0.38);
}

.cash-flow-range-separator {
  display: block;
  color: rgba(64, 55, 48, 0.38);
}

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

@media (max-width: 980px) {
  .cash-flow-page {
    width: min(100vw, 760px);
    padding: 10px;
  }

  .cash-flow-auth-panel,
  .cash-flow-toolbar,
  .cash-flow-section-head,
  .cash-flow-group-head {
    align-items: stretch;
    flex-direction: column;
  }

  .cash-flow-status {
    min-height: 18px;
  }

  .cash-flow-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cash-flow-groups {
    grid-template-columns: minmax(0, 1fr);
  }

  .cash-flow-section-summary,
  .cash-flow-group-summary {
    justify-content: flex-start;
  }
}

@media (max-width: 520px) {
  .cash-flow-page {
    width: 100vw;
    padding: 8px;
  }

  .cash-flow-page .page-header {
    padding: 22px 12px 12px;
  }

  .cash-flow-auth-panel,
  .cash-flow-toolbar,
  .cash-flow-section {
    padding: 12px;
  }

  .cash-flow-summary {
    grid-template-columns: minmax(0, 1fr);
  }

  .cash-flow-field input {
    width: 72px;
  }

  .cash-flow-auth-form .cash-flow-field input {
    width: 100%;
  }

  .cash-flow-button {
    flex: 1 1 100%;
  }

  .cash-flow-detail-dialog {
    width: calc(100vw - 12px);
    max-height: calc(100vh - 12px);
  }

  .cash-flow-detail-shell {
    max-height: calc(100vh - 14px);
  }

  .cash-flow-detail-header,
  .cash-flow-detail-body {
    padding-left: 12px;
    padding-right: 12px;
  }

  .cash-flow-detail-summary {
    grid-template-columns: minmax(0, 1fr);
  }
}
