:root {
  --navy: #0a1f44;
  --navy-2: #12295a;
  --navy-3: #1c3a78;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, .18);
  --text: #fff;
  --sub: #9db4d8;
  --line: #27447f;
  --yellow: #ffe600;
  --red: #ff8a8a;
  --green: #6ee7a8;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { height: 100%; margin: 0; background: var(--navy); color: var(--text); overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif; }
html { background: var(--navy-2); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select { font: inherit; color: inherit; }
h3 { margin: 18px 16px 6px; font-size: 14px; color: var(--accent); font-weight: 600; }

#shell { position: fixed; inset: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--navy); }
#app { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: none;
  padding-bottom: 28px; width: 100%; max-width: 640px; margin: 0 auto; }
#app::-webkit-scrollbar { display: none; }

#tabs { flex: none; display: flex; background: var(--navy-2); border-top: 1px solid var(--line); }
#tabs:empty { display: none; }
#tabs a { flex: 1; text-align: center; padding: 8px 0 calc(4px + env(safe-area-inset-bottom) * 0.35); font-size: 11px; color: #fff;
  opacity: .6; text-decoration: none; position: relative; }
#tabs a svg { display: block; width: 24px; height: 24px; margin: 0 auto 3px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { opacity: 1; background: var(--accent-soft); }
#tabs .dot { position: absolute; top: 4px; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--navy); font-size: 11px; font-weight: 700; line-height: 17px; }

.header { background: var(--navy-2); padding: calc(env(safe-area-inset-top) + 12px) 14px 14px; display: flex; align-items: center;
  justify-content: space-between; min-height: 56px; }
.header h1 { margin: 0; font-size: 18px; font-weight: 700; text-align: center; flex: 1; }
.header .sp { width: 40px; }

/* 支出/収入の切り替え */
.seg { display: flex; margin: 14px 16px 4px; background: var(--navy-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 11px 0; border-radius: 10px; font-weight: 700; font-size: 16px; color: var(--sub); }
.seg button.on { background: var(--accent); color: var(--navy); }

.form { padding: 4px 16px 0; }
.field { margin-top: 14px; }
.field label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 6px; }
.field input[type=text], .field input[type=date], .field input[type=email], .field input[type=password], .field select {
  width: 100%; height: 48px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--navy-3);
  color: #fff; font-size: 17px; /* 16px未満だとiPhoneで入力時に拡大される */ appearance: none; -webkit-appearance: none; }
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.field select:disabled { opacity: .7; }
.field input::placeholder { color: #7f98c4; }
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.datebox { display: flex; gap: 8px; align-items: center; }
.datebox input { flex: 1; min-width: 0; }
.chip { flex: none; height: 48px; padding: 0 14px; border-radius: 10px; background: var(--navy-3); border: 1px solid var(--line); font-size: 15px; color: var(--accent); }
.hint { font-size: 12px; color: var(--sub); margin-top: 6px; line-height: 1.5; min-height: 0; }
.check { display: flex !important; align-items: center; gap: 8px; font-size: 15px !important; color: #fff !important; margin: 0 !important; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.fxrow { display: flex; gap: 8px; margin-top: 10px; }
.fxrow select { width: 110px; flex: none; }
.fxrow input { flex: 1; min-width: 0; }

.btn { display: block; width: calc(100% - 32px); margin: 22px 16px 0; padding: 15px; border-radius: 12px; background: var(--accent);
  color: var(--navy); font-weight: 700; text-align: center; font-size: 17px; }
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.btn.gray { background: var(--navy-3); color: #fff; border: 1px solid var(--line); }
.btn.small { width: auto; display: inline-block; margin: 0 6px 0 0; padding: 10px 18px; font-size: 15px; }
.row2 { display: flex; }
.row2 .btn { flex: 1; width: auto; margin-right: 0; }
.row2 .btn:first-child { margin-right: 0; }
.status { text-align: center; color: var(--sub); font-size: 13px; margin: 14px 16px 0; }

/* 履歴 */
.item { display: flex; justify-content: space-between; gap: 10px; margin: 0 12px 6px; padding: 12px 14px; background: var(--navy-2); border-radius: 12px; }
.item.tap { cursor: pointer; }
.item.tap:active { background: var(--navy-3); }
.item .l { min-width: 0; flex: 1; }
.item .c { font-size: 16px; font-weight: 600; word-break: break-word; }
.item .s { font-size: 12px; color: var(--sub); margin-top: 3px; word-break: break-word; }
.item .r { flex: none; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.amt { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.amt.neg { color: var(--green); }
.blank { background: var(--yellow); color: #3a3000; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px; }
.inc { color: var(--green); font-weight: 700; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 8px; font-weight: 600; }
.badge.todo { background: var(--accent-soft); color: var(--accent); }
.badge.done { background: rgba(255,255,255,.1); color: var(--sub); }
.badge.wait { background: rgba(255, 230, 0, .2); color: var(--yellow); }
.err { color: var(--red); font-size: 12px; margin-top: 4px; line-height: 1.5; }
.warn { margin: 12px; padding: 12px 14px; border-radius: 12px; background: rgba(255, 230, 0, .15); color: var(--yellow); font-size: 13px; line-height: 1.6; }
.empty { text-align: center; color: var(--sub); padding: 48px 16px; }
.foot { margin: 20px 12px 0; text-align: center; }
.foot p { color: var(--sub); font-size: 12px; margin: 14px 0 0; }

/* 編集ポップアップ */
#modal { position: fixed; inset: 0; display: none; background: rgba(0,0,0,.55); z-index: 30; align-items: flex-end; justify-content: center; }
#modal.open { display: flex; }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--navy); border-radius: 18px 18px 0 0;
  padding: 18px 0 calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 16px; font-size: 18px; }
.sheet .btn { margin-top: 14px; }
.sheet .row2 { margin: 0 16px; gap: 10px; }
.sheet .row2 .btn { width: auto; margin: 14px 0 0; }

#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #fff; color: var(--navy);
  padding: 11px 18px; border-radius: 22px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: 90vw; text-align: center; z-index: 50; }
#toast.show { opacity: .97; }

@media (min-width: 900px) {
  #modal { align-items: center; }
  .sheet { border-radius: 18px; max-width: 520px; }
  #toast { bottom: 32px; }
}

/* グラフ */
.gnote { margin: 12px 16px 0; font-size: 12px; color: var(--sub); }
.gsum { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 12px 0; }
.gsum > div { background: var(--navy-2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.gsum span { display: block; font-size: 11px; color: var(--sub); }
.gsum b { display: block; margin-top: 4px; font-size: 15px; font-variant-numeric: tabular-nums; }
.gsum b.neg, .gbig i.neg { color: var(--red); }
.gbig i.pos { color: var(--green); font-style: normal; }
.gbig i.neg { font-style: normal; }
.gcard { background: var(--navy-2); border-radius: 14px; margin: 12px 12px 0; padding: 14px 12px 12px; }
.gcard h3 { margin: 0 4px 10px; font-size: 15px; color: #fff; }
.cv { position: relative; height: 240px; }
.cv.pie { height: 210px; }
.gbig { margin: 0 4px 8px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.gbig b { font-size: 26px; font-variant-numeric: tabular-nums; }
.gbig span { font-size: 12px; color: var(--sub); }
.gfoot { margin: 10px 4px 0; font-size: 11px; color: var(--sub); line-height: 1.6; }
.gfoot.center { text-align: center; margin: 14px 16px 0; }
.plegend { list-style: none; margin: 12px 2px 0; padding: 0; }
.plegend li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.plegend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.plegend .nm { flex: 1; min-width: 0; word-break: break-word; }
.plegend .vl { font-variant-numeric: tabular-nums; }
.plegend .pc { width: 52px; text-align: right; color: var(--sub); font-variant-numeric: tabular-nums; }

/* PCへの依頼(今すぐ転記・グラフの更新) */
.runbox .btn { margin-top: 12px; }
.run { margin: 12px 16px 0; padding: 10px 14px; border-radius: 10px; font-size: 13px; line-height: 1.6; }
.run.wait { background: var(--accent-soft); color: var(--accent); }
.run.ok { background: rgba(110, 231, 168, .15); color: var(--green); }
.run.ng { background: rgba(255, 138, 138, .15); color: var(--red); }
.btn:disabled { opacity: .5; }
