/* Tokens copied from kings_finances_design_reference.html */
:root{
  --surface-2:#ffffff;
  --surface-1:#f4f3ef;
  --surface-0:#ecebe5;
  --text-primary:#18181a;
  --text-secondary:#63625d;
  --text-muted:#8f8e88;
  --text-success:#3b6d11;
  --text-danger:#a32d2d;
  --text-accent:#185fa5;
  --border:rgba(0,0,0,.08);
  --border-strong:rgba(0,0,0,.18);
  --border-accent:#378add;
  --bg-accent:#e6f1fb;
  --fill-primary:#18181a;
  --on-primary:#ffffff;
  --radius:8px;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0;overscroll-behavior:none}
body{
  background:var(--surface-0); color:var(--text-primary);
  font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,
       "Apple SD Gothic Neo","Malgun Gothic",sans-serif;
  -webkit-text-size-adjust:100%;
}
button{font-family:inherit;font-size:inherit;color:inherit;border:none;background:none;cursor:pointer;
  touch-action:manipulation;-webkit-tap-highlight-color:transparent}
h1,h2,h3,p{margin:0}
.sprite{display:none}
.i{width:1em;height:1em;fill:none;stroke:currentColor;stroke-width:2;
  stroke-linecap:round;stroke-linejoin:round;flex:0 0 auto}

/* ---------- desktop: phone preview + settings pane ---------- */
.layout{display:flex;gap:32px;align-items:flex-start;justify-content:center;
  padding:40px 24px;min-height:100vh}
.phone-bezel{width:360px;height:720px;background:#111214;border-radius:46px;padding:10px;
  box-shadow:0 0 0 1px var(--border);flex-shrink:0}
.phone-screen{position:relative;width:100%;height:100%;background:var(--surface-2);
  border-radius:36px;overflow:hidden;display:flex;flex-direction:column}
.notch{position:absolute;top:8px;left:50%;transform:translateX(-50%);width:90px;height:20px;
  background:#111214;border-radius:12px;z-index:5}
.status-bar{flex:0 0 auto;height:36px;display:flex;align-items:center;justify-content:space-between;
  padding:0 26px;font-size:13px;font-weight:600}
.sb-icons{display:flex;align-items:center;gap:5px;font-size:15px}
.home-indicator{flex:0 0 auto;height:18px;display:flex;align-items:center;justify-content:center}
.home-indicator span{width:120px;height:5px;border-radius:3px;background:var(--text-muted);opacity:.5}

.settings-pane{width:340px;background:var(--surface-2);border:1px solid var(--border);
  border-radius:16px;padding:20px;flex-shrink:0}
.settings-pane h2{font-size:16px;margin-bottom:4px}
.settings-hint{font-size:12px;color:var(--text-muted);margin-bottom:18px;line-height:1.5}

/* ---------- app shell: header / one scroller / tabs ---------- */
#head{flex:0 0 auto;display:flex;align-items:center;gap:8px;padding:12px 16px 10px}
#head .screen-title{flex:1;display:flex;align-items:center;justify-content:center;gap:8px;
  font-size:15px;font-weight:600}
.iconbtn{flex:0 0 auto;display:grid;place-items:center;width:28px;height:28px;font-size:20px;
  color:var(--text-secondary);border-radius:var(--radius)}
.iconbtn:active{background:var(--surface-1)}
.mbtn{display:grid;place-items:center;width:24px;height:24px;font-size:18px;color:var(--text-muted)}

#content{flex:1 1 auto;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;
  overscroll-behavior:contain;touch-action:pan-y;padding-bottom:20px}
.scroll{scrollbar-width:none;-ms-overflow-style:none}
.scroll::-webkit-scrollbar{display:none}

#tabs{flex:0 0 auto;display:flex;border-top:1px solid var(--border);padding:8px 4px 4px;
  background:var(--surface-2);padding-bottom:max(4px,env(safe-area-inset-bottom))}
#tabs button{flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;padding:4px 0;
  color:var(--text-muted)}
#tabs button .i{font-size:20px}
#tabs button span{font-size:10px}
#tabs button.on{color:var(--text-accent)}

/* ---------- shared ---------- */
.pad{padding:0 16px}
.sec-title{padding:10px 16px 4px;font-size:13px;color:var(--text-secondary)}
.empty{color:var(--text-muted);font-size:13px;text-align:center;padding:18px 0}
.neg{color:var(--text-danger)}
.pos{color:var(--text-success)}
.num{font-variant-numeric:tabular-nums}

.primary-btn,.ghost-btn{border-radius:var(--radius);font-weight:600;
  display:flex;align-items:center;justify-content:center;gap:6px}
.primary-btn{background:var(--fill-primary);color:var(--on-primary);height:40px;font-size:14px}
.ghost-btn{background:transparent;color:var(--text-secondary);border:1px solid var(--border-strong);
  height:38px;font-size:13px;font-weight:400}
.primary-btn:active,.ghost-btn:active{opacity:.75}
.wide{width:calc(100% - 32px);margin:10px 16px}
.del{display:grid;place-items:center;width:24px;height:24px;font-size:15px;color:var(--text-muted);
  flex:0 0 auto}
.del:active{color:var(--text-danger)}

input[type=text],input[type=number],input[type=date],select{
  height:36px;border:1px solid var(--border);border-radius:var(--radius);padding:0 10px;
  font-size:13px;font-family:inherit;background:var(--surface-2);color:var(--text-primary);width:100%}
input:focus,select:focus{outline:none;border-color:var(--border-accent)}

/* click-to-edit text */
.ed{cursor:text;outline:none;border-bottom:1px dashed transparent;padding:0 1px;border-radius:3px}
.ed:hover{border-bottom-color:var(--border-strong)}
.ed:focus{border-bottom-color:var(--border-accent);background:var(--bg-accent)}

/* ---------- home ---------- */
.metric-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;padding:4px 16px 14px}
.metric-btn{text-align:left;background:var(--surface-1);border-radius:var(--radius);padding:10px 12px;
  cursor:pointer;touch-action:manipulation;-webkit-tap-highlight-color:transparent}
.metric-btn:active{background:var(--surface-0)}
.metric-btn.flat{cursor:default}          /* 이동 대상이 없는 카드 */
.metric-btn.flat:active{background:var(--surface-1)}
.metric-label-row{display:flex;align-items:center;gap:4px;margin-bottom:2px}
.metric-label{font-size:12px;color:var(--text-muted)}
.metric-value{font-size:17px;font-weight:600;font-variant-numeric:tabular-nums}
/* 손가락 표적. 15px 아이콘 그대로 두면 폰에서 빗나가 카드가 눌리고 화면이 이동해 버린다.
   음수 마진으로 카드 높이는 그대로 두고 누를 수 있는 영역만 넓힌다. */
.pencil{margin-left:auto;display:inline-grid;place-items:center;
  width:32px;height:32px;margin-top:-8px;margin-right:-8px;
  font-size:14px;color:var(--text-muted);cursor:pointer;
  touch-action:manipulation;-webkit-tap-highlight-color:transparent}
.pencil:active{color:var(--text-primary);background:var(--surface-0);border-radius:var(--radius)}

.cat-list{padding:6px 16px 16px;display:flex;flex-direction:column;gap:14px}
.cat-row{cursor:pointer}
.cat-row-top{display:flex;justify-content:space-between;font-size:13px;margin-bottom:5px}
.gauge-track{position:relative;height:6px;background:var(--surface-1);border-radius:4px}
.gauge-target{position:absolute;top:0;height:100%;background:var(--border-strong);opacity:.45;
  border-radius:4px}
.gauge-fill{position:absolute;top:0;left:0;height:100%;border-radius:4px}

/* ---------- rows (budget / ledger / bank) ---------- */
.list-wrap{padding:0 16px 6px;display:flex;flex-direction:column}
.row{display:flex;align-items:center;gap:8px;padding:10px 0;border-bottom:1px solid var(--border)}
.row:last-child{border-bottom:none}
.row-main{flex:1;min-width:0}
.row-name{font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.row-meta{font-size:11px;color:var(--text-muted);margin-top:2px}
.row-right{text-align:right;flex:0 0 auto;white-space:nowrap}
.row-amt{font-size:13px;font-variant-numeric:tabular-nums}
.row-sub{font-size:11px;color:var(--text-muted);font-variant-numeric:tabular-nums}
.row.total{border-top:1px solid var(--border-strong);border-bottom:none;font-weight:600}
.dot{width:6px;height:6px;border-radius:50%;flex:0 0 auto}

.chip-row{display:flex;gap:6px;padding:0 16px 10px;flex-wrap:wrap}
.chip{font-size:12px;padding:6px 10px;border-radius:999px;cursor:pointer;border:1px solid var(--border);
  background:var(--surface-1);color:var(--text-secondary);touch-action:manipulation;
  -webkit-user-select:none;user-select:none}
.chip.active{border-color:var(--border-accent);background:var(--bg-accent);color:var(--text-accent)}

.summary{margin:0 16px 14px;background:var(--surface-1);border-radius:var(--radius);padding:14px;
  display:flex;justify-content:space-between;gap:10px}
.summary p:first-child{font-size:12px;color:var(--text-muted);margin-bottom:4px}
.summary b{font-size:22px;font-weight:600;font-variant-numeric:tabular-nums}
.summary .right{text-align:right;font-size:12px;color:var(--text-muted)}
.summary .right b{font-size:15px;display:block;color:var(--text-primary)}
.summary .right b.neg{color:var(--text-danger)}

.form{margin:0 16px 16px;padding:12px;background:var(--surface-1);border-radius:var(--radius);
  display:flex;flex-direction:column;gap:8px}
.form .chip-row{padding:0}
.form .primary-btn{height:36px;font-size:13px}

.tag{font-size:13px;background:var(--surface-1);padding:2px 8px;border-radius:999px;
  color:var(--text-secondary)}
.arrow{font-size:16px}
.arrow.in{color:var(--text-success)}
.arrow.out{color:var(--text-danger)}
.amt-in{color:var(--text-success)}
.amt-out{color:var(--text-danger)}

/* ---------- flow accordion ---------- */
.acc-list{padding:0 16px 16px;display:flex;flex-direction:column;gap:8px}
.acc{border:1px solid var(--border);border-radius:var(--radius);overflow:hidden}
.acc-head{width:100%;display:flex;align-items:center;justify-content:space-between;gap:8px;
  padding:10px 12px;background:var(--surface-1);font-size:13px}
.acc-head .caret{font-size:16px;color:var(--text-muted);transition:transform .15s}
.acc-head .caret.on{transform:rotate(180deg)}
.acc-body{padding:10px 12px}
.flow-sec{margin-bottom:10px}
.flow-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:4px;
  font-size:12px;font-weight:600;color:var(--text-secondary)}
.flow-row{display:flex;align-items:center;gap:8px;justify-content:space-between;font-size:12px;
  padding:4px 0;border-bottom:1px solid var(--border)}
.flow-row .row-main{flex:1;min-width:0}
.add-btn{font-size:11px;color:var(--text-accent);padding:4px 0;font-weight:600}
.flow-sec .form{margin:4px 0 8px;padding:10px}
.flow-sec .empty{padding:8px 0;font-size:12px}

/* ---------- settings (shared by the desktop pane and the mobile screen) ---------- */
.settings-section{margin-bottom:20px}
.settings-section h3{font-size:13px;color:var(--text-secondary);margin-bottom:10px;font-weight:600}
.settings-note{font-size:11px;color:var(--text-muted);margin:6px 0 10px;line-height:1.5}
.cat-edit-card{background:var(--surface-1);border-radius:var(--radius);padding:10px 12px;margin-bottom:8px}
.cat-edit-card label{display:block;font-size:11px;color:var(--text-muted);margin:8px 0 4px}
.cat-edit-card label:first-child{margin-top:0}
.target-row{display:flex;gap:8px;align-items:center}
.target-row span{font-size:12px;color:var(--text-muted)}
#content .settings-section{padding:0 16px}
#content .settings-section:first-child{padding-top:4px}

/* ---------- mobile: bare app, no bezel, no side pane ---------- */
@media (max-width:860px){
  .layout{display:block;padding:0;gap:0}
  .settings-pane{display:none}
  .phone-bezel{width:100%;height:100vh;height:100dvh;border-radius:0;padding:0;box-shadow:none}
  .phone-screen{border-radius:0}
  .notch,.status-bar,.home-indicator{display:none}
  #head{padding-top:max(12px,env(safe-area-inset-top))}
}
/* Desktop keeps the settings pane on screen, so the gear would be a second door.
   visibility, not display: the button must keep its slot or the title goes off-centre. */
@media (min-width:861px){ #gear{visibility:hidden!important} }
