:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #17201d;
  --ink2: #55615c;
  --line: #e2e5e0;
  --field: #fbfbf9;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ee;
  --pos: #0f766e;
  --neg: #c2410c;
  --warn-bg: #fff7e6;
  --warn-ink: #8a5300;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 2px 8px rgba(20, 30, 25, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614; --card: #181f1c; --ink: #e7ece9; --ink2: #98a59f; --line: #2a3430; --field: #141a18;
    --accent: #2bb3a3; --accent-ink: #062521; --accent-soft: #17302c; --pos: #34c3b1; --neg: #fb8b5a;
    --warn-bg: #2e2412; --warn-ink: #f2c46b; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--ink2); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 30; height: 52px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; gap: 8px; letter-spacing: -.2px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 22l6-7 4 4 7-9' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-weight: 600; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--ink2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.icon-btn { border: 0; background: none; font-size: 20px; cursor: pointer; padding: 4px 6px; }

/* layout */
.layout { display: grid; grid-template-columns: 272px 1fr; min-height: calc(100vh - 52px); }
.side {
  border-right: 1px solid var(--line); background: var(--card); padding: 14px; position: sticky; top: 52px;
  height: calc(100vh - 52px); overflow-y: auto;
}
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); margin-bottom: 10px; }
.item-list { display: flex; flex-direction: column; gap: 6px; }
.item {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; cursor: pointer; position: relative;
  background: var(--card);
}
.item:hover { border-color: var(--ink2); }
.item.on { border-color: var(--accent); background: var(--accent-soft); }
.item .t { font-weight: 600; padding-right: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .a { font-size: 12px; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .chips { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.chip { font-size: 11.5px; padding: 1px 7px; border-radius: 99px; background: var(--bg); color: var(--ink2); font-variant-numeric: tabular-nums; }
.chip.y { background: var(--accent-soft); color: var(--pos); font-weight: 600; }
.item .del { position: absolute; top: 6px; right: 6px; border: 0; background: none; color: var(--ink2); cursor: pointer; font-size: 15px; opacity: .5; }
.item .del:hover { opacity: 1; color: var(--neg); }
.empty { color: var(--ink2); font-size: 13px; padding: 14px 4px; line-height: 1.6; }

.main { padding: 18px 22px 80px; min-width: 0; }
.titlebar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.title-input {
  flex: 1; min-width: 220px; font-size: 19px; font-weight: 700; border: 0; border-bottom: 2px solid transparent;
  background: transparent; padding: 6px 2px; outline: none; letter-spacing: -.3px;
}
.title-input:focus { border-bottom-color: var(--accent); }
.save-group { display: flex; gap: 8px; align-items: center; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.col-in, .col-out { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.col-out { position: sticky; top: 68px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.card h2 { font-size: 14.5px; margin: 0 0 12px; letter-spacing: -.2px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--ink2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.field input:not([type=checkbox]), .field select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field);
  font-variant-numeric: tabular-nums; min-width: 0;
}
.field input:focus, .field select:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field input:disabled { opacity: .65; }
.hint { font-size: 11.5px; color: var(--ink2); min-height: 15px; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.row3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.card > .row3:first-of-type, .card > h2 + .field { margin-top: 0; }
.suffix { position: relative; }
.suffix input { padding-right: 38px !important; }
.suffix em { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--ink2); font-size: 12.5px; pointer-events: none; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink); white-space: nowrap; cursor: pointer; }
.check.inline { font-size: 12px; color: var(--ink2); font-weight: 400; }
.tip { font-style: normal; display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); font-size: 10px; cursor: help; }

.seg { display: inline-flex; background: var(--bg); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { white-space: nowrap; border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--ink2); font-size: 13px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg.full { display: flex; margin-bottom: 14px; }
.seg.full button { flex: 1; }

.region { margin-top: 12px; border-radius: 10px; background: var(--accent-soft); padding: 10px 12px; font-size: 13px; }
.region:empty { display: none; }
.region .hd { font-weight: 700; }
.region .warn { margin-top: 6px; background: var(--warn-bg); color: var(--warn-ink); padding: 6px 9px; border-radius: 7px; font-size: 12.5px; }
.region.bad { background: var(--warn-bg); color: var(--warn-ink); }

.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-top: 12px; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.tbl th { font-size: 12px; color: var(--ink2); font-weight: 600; }
.tbl td:first-child, .tbl th:first-child { text-align: left; color: var(--ink2); }
.tbl tr.strong td { font-weight: 700; color: var(--ink); }
.tbl.kv td:first-child { white-space: normal; }
.tbl input { width: 92px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); text-align: right; font-variant-numeric: tabular-nums; }
.tbl .x { border: 0; background: none; color: var(--ink2); cursor: pointer; font-size: 15px; }
.tbl .x:hover { color: var(--neg); }
.tbl tr.cur td { background: var(--accent-soft); }
.tbl-wrap { overflow-x: auto; }
.loan-tbl td:not(:first-child) { width: 34%; }

.more { margin-top: 10px; }
.more summary { cursor: pointer; font-size: 13px; color: var(--ink2); font-weight: 600; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-top: 4px; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 700; color: var(--ink2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 14.5px; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.kpi span { display: block; font-size: 12px; color: var(--ink2); }
.kpi b { font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.kpi.main { grid-column: 1 / -1; background: var(--accent-soft); }
.kpi.main b { font-size: 30px; color: var(--pos); }
.pos { color: var(--pos); }
.neg { color: var(--neg) !important; }

.answer { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--bg); line-height: 1.7; }
.answer b.big { font-size: 20px; color: var(--pos); }

.disclaimer { margin: 0 4px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(380px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog .field { margin-bottom: 12px; }
dialog h3 { margin: 0 0 14px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.err { color: var(--neg); font-size: 13px; min-height: 18px; margin: 0 0 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100; font-weight: 600; }
.toast.show { opacity: 1; transform: translateX(-50%); }

.only-mobile { display: none !important; }
.scrim { display: none; }

@media (max-width: 1080px) {
  .grid { grid-template-columns: 1fr; }
  .col-out { position: static; }
}
@media (max-width: 760px) {
  .only-mobile { display: flex !important; }
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 52px; bottom: 0; width: 290px; height: auto; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 52px 0 0 0; background: rgba(0,0,0,.3); z-index: 35; }
  .main { padding: 14px 16px 90px; }
  .row2 { grid-template-columns: 1fr; }
  .row3 { grid-template-columns: 1fr 1fr; }
  .brand { font-size: 14.5px; }
  #userName, #btnPw { display: none; }
  .card { padding: 14px; }
  .mbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 10px 16px; justify-content: space-between; align-items: center; z-index: 25; font-variant-numeric: tabular-nums; }
  .mbar b { font-size: 18px; color: var(--pos); }
}
