:root {
  --navy: #1f3a5f; --navy2: #2d5384; --bg: #f4f6f9; --card: #fff; --line: #dde3ea; --text: #1d2733;
  --muted: #6b7785; --red: #c62828; --redbg: #fdecea; --ok: #2e7d32; --okbg: #e8f5e9;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif; }
input, select, textarea, button { font: inherit; color: inherit; }
.small { font-size: 12.5px; }
.muted { color: var(--muted); }
.warn { color: #a15c00; }
.red { color: var(--red); font-weight: 700; }

/* 上の切替 */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; background: var(--navy); padding: 0 8px; }
#tabs { display: flex; flex: 1; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
#tabs a { flex: none; color: #d8e3f0; text-decoration: none; padding: 12px 14px; border-bottom: 3px solid transparent; white-space: nowrap; }
#tabs a.on { color: #fff; border-bottom-color: #ffb74d; font-weight: 700; }
.badge { display: inline-block; margin-left: 5px; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.logout button { background: none; border: 1px solid #6f8db3; color: #d8e3f0; border-radius: 4px; padding: 3px 8px; font-size: 12px; cursor: pointer; white-space: nowrap; }

#app { max-width: 1100px; margin: 0 auto; padding: 14px 12px 60px; }
h2 { font-size: 15px; margin: 18px 0 6px; color: var(--navy); }

/* メモ欄 */
.memo-box { margin-bottom: 12px; }
textarea.memo { display: block; width: 100%; min-height: 64px; resize: vertical; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fffef5; line-height: 1.6; }
.memo-box .small { display: block; min-height: 18px; text-align: right; }

/* 表 */
.grid-wrap { overflow-x: auto; }
table.grid, table.ipo { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); }
table.grid th, table.ipo th { background: #eef2f7; color: var(--navy); font-size: 12.5px; font-weight: 600; text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td, table.ipo td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid input { width: 100%; min-width: 80px; border: 1px solid transparent; border-radius: 4px; padding: 5px 6px; background: transparent; }
table.grid input:hover { border-color: var(--line); }
table.grid input:focus { border-color: var(--navy2); background: #fff; outline: none; }
.num, table.grid input.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td:has(> input.num), table.grid th.num { width: 130px; }
@media (min-width: 900px) { table.grid td.wide { width: 34%; } }
table.grid tfoot td { font-weight: 700; background: #f8fafc; padding: 6px 12px; }
td.act { width: 36px; text-align: center; }
td.secret { min-width: 220px; }
.sec { display: flex; align-items: center; gap: 6px; }
.sec .mask { flex: 0 1 auto; color: var(--muted); letter-spacing: 1px; padding: 5px 6px; }
.sec input { flex: 1; min-width: 0; border: 1px solid var(--navy2); border-radius: 4px; padding: 5px 6px; background: #fff; font-family: ui-monospace, Consolas, monospace; }
.sbtn { flex: none; border: 1px solid #b0bec5; background: #fff; border-radius: 4px; padding: 2px 8px; font-size: 12.5px; cursor: pointer; color: var(--navy2); }
.sbtn:hover { background: #eef2f7; }
button.del, button.edit { border: none; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
button.del:hover { color: var(--red); background: var(--redbg); }
button.edit:hover { color: var(--navy); background: #eef2f7; }
button.edit.manual { color: #a15c00; }
button.add { margin-top: 8px; border: 1px dashed #9fb2c8; background: #fff; color: var(--navy2); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
button.add:hover { background: #eef2f7; }

/* IPO */
.alert { background: var(--redbg); color: var(--red); border: 1px solid #f5c2c0; border-radius: 6px; padding: 7px 12px; margin-bottom: 8px; font-weight: 700; }
.status { text-align: right; margin-bottom: 6px; }
table.ipo td.date { white-space: nowrap; }
table.ipo .nm { font-weight: 600; }
table.ipo .sub { font-size: 12px; color: var(--muted); }
table.ipo td.period { white-space: nowrap; }
table.ipo td.buy { color: var(--ok); }
.buy-tag { display: inline-block; margin-right: 4px; padding: 0 5px; border-radius: 3px; background: var(--okbg); border: 1px solid #81c784; font-size: 11px; color: var(--ok); }
.rank { min-width: 34px; border: none; border-radius: 4px; padding: 2px 8px; font-weight: 700; cursor: pointer; background: #eceff1; color: #555; }
.rank-S { background: #c62828; color: #fff; }
.rank-A { background: #ef6c00; color: #fff; }
.rank-B { background: #2e7d32; color: #fff; }
.rank-C { background: #90a4ae; color: #fff; }
.rank-D { background: #cfd8dc; color: #455a64; }
.few { margin-left: 5px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.apps { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid #b0bec5; background: #fff; border-radius: 14px; padding: 1px 9px 1px 4px; font-size: 13px; cursor: pointer; }
.chip .box { display: inline-block; width: 16px; height: 16px; border: 1px solid #90a4ae; border-radius: 3px; text-align: center; line-height: 14px; font-size: 12px; background: #fff; }
.chip.on { background: var(--okbg); border-color: #81c784; color: var(--ok); }
.chip.on .box { background: var(--ok); border-color: var(--ok); color: #fff; }
.chip.lost { background: #f1f3f5; border-color: #cfd8dc; color: #90a4ae; text-decoration: line-through; }
.chip.lost .box { background: #b0bec5; border-color: #b0bec5; color: #fff; text-decoration: none; }
.cnote { font-size: 11.5px; color: #a15c00; }
.skip { font-size: 14px; font-weight: 700; color: var(--red); padding: 0 4px; }
.rnote { width: 100%; font-size: 12px; color: #a15c00; }
tr.near td.period { background: var(--redbg); }
details.past { margin-top: 14px; }
details.past summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.ipo-add { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.ipo-add input { border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; flex: 1; min-width: 140px; }
.ipo-add input.short, input.short { flex: 0 0 90px; min-width: 70px; max-width: 110px; }
.ipo-add button.add { margin-top: 0; }

.pop { position: absolute; z-index: 30; min-width: 220px; max-width: 320px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: 10px 12px; }
.pop-t { font-weight: 700; font-size: 13px; margin-bottom: 4px; color: var(--navy); }
.pop table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pop td { padding: 2px 0; border-bottom: 1px dotted var(--line); }
.pop td.rk { text-align: right; font-weight: 700; background: none !important; }
.pop td.rank-S { color: #c62828; } .pop td.rank-A { color: #ef6c00; } .pop td.rank-B { color: #2e7d32; } .pop td.rank-C { color: #607d8b; } .pop td.rank-D { color: #90a4ae; }

/* 修正のダイアログ */
dialog.dlg { border: none; border-radius: 10px; padding: 16px; width: min(480px, calc(100vw - 24px)); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog.dlg::backdrop { background: rgba(20,30,45,.4); }
.dlg h3 { margin: 0 0 10px; font-size: 16px; color: var(--navy); }
.dlg label { display: block; margin: 6px 0; font-size: 13px; }
.dlg input:not([type=checkbox]), .dlg select { border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; }
.dlg .f2 { display: flex; gap: 8px; }
.dlg .f2 label:first-child { flex: 1; }
.dlg .f2 label input { display: block; width: 100%; }
.dlg > form > label > input { width: 100%; }
.dlg fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 8px 0; padding: 6px 10px; }
.dlg legend { font-size: 13px; color: var(--navy); }
.brow { display: flex; align-items: center; gap: 8px; }
.brow label { flex: 0 0 150px; margin: 3px 0; }
.brow .bnote { flex: 1; min-width: 0; padding: 3px 6px !important; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.btns button { border: 1px solid #b0bec5; background: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.btns button.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btns button.danger { color: var(--red); border-color: #e0a3a3; }

#toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #263238; color: #fff; padding: 7px 16px; border-radius: 18px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: .95; }
#toast.err { background: var(--red); }

/* ログイン・設定 */
main.auth { max-width: 380px; margin: 8vh auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 22px 22px 18px; }
main.auth h1 { margin: 0 0 14px; font-size: 20px; color: var(--navy); }
main.auth label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
main.auth input { display: block; width: 100%; margin-top: 3px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); }
main.auth input[readonly] { background: #f3f5f8; }
main.auth button, a.btn { display: inline-block; width: 100%; padding: 9px; border: none; border-radius: 6px; background: var(--navy); color: #fff; font-weight: 700; cursor: pointer; text-align: center; text-decoration: none; }
.err { color: var(--red); background: var(--redbg); border-radius: 6px; padding: 6px 10px; font-size: 13px; }
.qr { text-align: center; margin: 6px 0 12px; }
.qr img { border: 1px solid var(--line); }
code.secret { font-size: 13px; letter-spacing: .5px; word-break: break-all; }
ol.codes { columns: 2; font-size: 15px; }

/* スマホ: IPO の表はカードの形に */
@media (max-width: 680px) {
  #app { padding: 10px 8px 60px; }
  table.ipo, table.ipo tbody, table.ipo tr, table.ipo td { display: block; width: 100%; }
  table.ipo thead { display: none; }
  table.ipo { border: none; background: none; }
  table.ipo tr { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; padding: 6px 8px; }
  table.ipo td { border: none; padding: 2px 0; }
  table.ipo td[data-label]:not(.name)::before { content: attr(data-label); display: inline-block; width: 64px; font-size: 11.5px; color: var(--muted); }
  table.ipo td.name { padding-right: 34px; }
  table.ipo td.act { position: absolute; top: 4px; right: 4px; width: auto; }
  table.ipo td .apps { display: inline-flex; }
  tr.near td.period { background: none; }
  table.grid input { min-width: 90px; }
}
