:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e4e6eb;
  --line-strong: #d3d6dd;
  --text: #16181d;
  --muted: #6a707c;
  --faint: #9aa0ab;
  --accent: #2346d8;
  --accent-soft: #e9eeff;
  --warn: #b45309;
  --warn-soft: #fff4e5;
  --ok: #15803d;
  --danger: #c2261d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418; --surface: #1a1d23; --surface-2: #20242b; --line: #2b3038; --line-strong: #3a404a;
    --text: #e9ebef; --muted: #9aa1ad; --faint: #6c7380; --accent: #7c98ff; --accent-soft: #232c4d;
    --warn: #f0a650; --warn-soft: #3a2a14; --ok: #4ade80; --danger: #f87171;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-feature-settings: "tnum";
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: .55; cursor: default; }
.field {
  height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); min-width: 0;
}
.field:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* 상단 */
.topbar {
  position: sticky; top: 0; z-index: 10; height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 0 max(16px, calc((100vw - 1240px) / 2)); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { white-space: nowrap; font-weight: 800; font-size: 16px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 12px; }
.topbar .spacer { flex: 1; }
.me { color: var(--muted); }
.me b { color: var(--text); }

main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 80px; }

/* 링크 추가 */
.add {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow);
}
.add-row { display: flex; gap: 10px; align-items: stretch; }
.add textarea {
  flex: 1; min-height: 48px; max-height: 200px; resize: vertical; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface-2); line-height: 1.45;
}
.add .btn.primary { height: auto; min-height: 48px; padding: 0 22px; font-size: 15px; }
.add-hint { margin: 10px 2px 0; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.add-hint button { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; }
.log { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.log li { display: flex; gap: 8px; align-items: baseline; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); }
.log li .u { color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.log li.ok { color: var(--ok); }
.log li.warn { color: var(--warn); background: var(--warn-soft); }
.log li.err { color: var(--danger); }

.bm-panel {
  margin-top: 12px; padding: 14px 16px; border-radius: 10px; background: var(--accent-soft); display: none; gap: 10px;
}
.bm-panel.open { display: grid; }
.bm-panel h3 { margin: 0; font-size: 14px; }
.bm-panel ol { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.bm-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; background: var(--accent);
  color: #fff !important; font-weight: 700; cursor: grab; text-decoration: none !important; box-shadow: var(--shadow);
}
.bm-panel .small { color: var(--muted); font-size: 12.5px; }

/* 도구줄 · 합계 */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 22px 0 10px; align-items: center; }
.toolbar .search { flex: 1 1 220px; }
.toolbar select { flex: 0 1 150px; }
.summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 18px; padding: 12px 2px; color: var(--muted);
}
.summary .total { font-size: 20px; font-weight: 800; color: var(--text); letter-spacing: -.01em; }
.summary .total small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 8px; }
.summary .warn { color: var(--warn); }

/* 목록 */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: grid; align-items: center; gap: 12px;
  grid-template-columns: 64px minmax(0, 1fr) 128px 76px 118px 128px 108px 64px;
  padding: 10px 14px; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row.head {
  padding-top: 9px; padding-bottom: 9px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600;
}
.row.head .num { text-align: right; padding-right: 8px; }
.row.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }

.thumb {
  width: 64px; height: 64px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2) center/contain no-repeat;
  display: grid; place-items: center; color: var(--faint); font-size: 11px; overflow: hidden; padding: 0; text-align: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

.main { min-width: 0; display: grid; gap: 2px; }
.cell-input {
  width: 100%; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 4px 6px; min-width: 0;
}
.cell-input:hover { border-color: var(--line-strong); }
.cell-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
textarea.title {
  resize: none; font-weight: 600; line-height: 1.4; height: 2.9em; overflow: hidden; display: block;
}
textarea.title::placeholder { color: var(--warn); font-weight: 500; }
.meta { display: flex; flex-wrap: wrap; gap: 2px 10px; padding: 0 6px; color: var(--faint); font-size: 12px; align-items: center; }
.meta .site { color: var(--muted); font-weight: 600; }
.badge { font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
input.memo { font-size: 12.5px; color: var(--muted); padding-top: 2px; padding-bottom: 2px; }

.num { text-align: right; }
.price-wrap { display: flex; align-items: center; gap: 2px; }
.price-wrap select { border: 0; background: transparent; color: var(--faint); font-size: 11.5px; padding: 0; width: 42px; }
.amount { text-align: right; font-weight: 700; padding-right: 8px; white-space: nowrap; }
.amount.none { color: var(--faint); font-weight: 400; }
select.cell-input { padding-left: 4px; }
.actions { display: flex; justify-content: flex-end; gap: 0; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 7px; border: 0; background: transparent; color: var(--faint);
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.del:hover { color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.lbl { display: none; }

.empty { padding: 56px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

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

@media (max-width: 900px) {
  .row.head { display: none; }
  .row {
    grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1fr) 36px;
    grid-template-areas:
      "thumb main main act"
      "price price qty qty"
      "amount amount cat cat"
      "req req req req";
    gap: 6px 10px; padding: 14px;
  }
  .row > .thumb { grid-area: thumb; align-self: start; }
  .row > .main { grid-area: main; }
  .row > .c-price { grid-area: price; }
  .row > .c-qty { grid-area: qty; }
  .row > .c-amount { grid-area: amount; }
  .row > .c-cat { grid-area: cat; }
  .row > .c-req { grid-area: req; }
  .row > .actions { grid-area: act; flex-direction: column; align-self: start; }
  .c-price, .c-qty, .c-amount, .c-cat, .c-req { display: flex; align-items: center; gap: 8px; }
  .lbl { display: inline; color: var(--faint); font-size: 12px; min-width: 38px; }
  .amount, .row .num { text-align: left; }
  .c-price .price-wrap, .c-qty input, .c-cat input, .c-req select { flex: 1; }
  .c-req select { max-width: 160px; }
  .add-row { flex-direction: column; }
  .toolbar select { flex: 1 1 120px; }
  .me .who { display: none; }
  .topbar { gap: 4px; }
  .brand { white-space: normal; word-break: keep-all; font-size: 13.5px; line-height: 1.25; min-width: 0; }
  .brand .dot { flex: none; }
  .topbar .btn.ghost { padding: 0 8px; }
}

/* 로그인 · 담기 창 */
.center-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px; box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 4px; font-size: 20px; }
.card p.sub { margin: 0 0 20px; color: var(--muted); }
.card form { display: grid; gap: 10px; }
.card .field { height: 44px; font-size: 15px; }
.card .btn { height: 44px; font-size: 15px; }
.error { color: var(--danger); font-size: 13px; min-height: 1.2em; margin: 0; }

.clip { max-width: 520px; margin: 0 auto; padding: 18px 16px 24px; }
.clip h1 { font-size: 17px; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.clip-top { display: grid; grid-template-columns: 112px 1fr; gap: 14px; margin-bottom: 14px; }
.clip-top .thumb { width: 112px; height: 112px; }
.clip-form { display: grid; gap: 10px; }
.clip-form label { display: grid; gap: 4px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.clip-form .field, .clip-form textarea { width: 100%; }
.clip-form textarea { min-height: 66px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); resize: vertical; color: var(--text); font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.notice { padding: 9px 12px; border-radius: 8px; font-size: 13px; background: var(--accent-soft); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.clip .btn.primary { height: 46px; font-size: 15px; width: 100%; margin-top: 4px; }
.done { text-align: center; padding: 40px 0; }
.done .big { font-size: 40px; }

/* 사용법 페이지 */
.guide { max-width: 780px; line-height: 1.7; font-size: 15px; }
.guide h1 { font-size: 28px; margin: 8px 0 6px; letter-spacing: -.02em; }
.guide .lead { color: var(--muted); margin: 0 0 18px; }
.guide h2 { font-size: 20px; margin: 44px 0 12px; padding-top: 8px; letter-spacing: -.01em; scroll-margin-top: 72px; }
.guide section { scroll-margin-top: 64px; }
.guide h3 { font-size: 16px; margin: 26px 0 8px; display: flex; align-items: center; gap: 8px; }
.guide p { margin: 8px 0; }
.guide ul { padding-left: 20px; }
.guide li { margin: 4px 0; }
.guide code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: 13px; }
.guide kbd {
  display: inline-block; min-width: 22px; padding: 0 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 5px; background: var(--surface); font-family: inherit; font-size: 12.5px; line-height: 1.6; text-align: center;
}
.guide .muted { color: var(--muted); font-size: 14px; }
.guide .tag { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.guide .tag.gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.toc { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.toc a { padding: 6px 12px; border-radius: 8px; color: var(--text); font-weight: 600; font-size: 14px; }
.toc a:hover { background: var(--surface-2); text-decoration: none; }
.steps { padding-left: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.steps > li { counter-increment: s; position: relative; padding: 12px 14px 12px 50px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin: 0; }
.steps > li::before {
  content: counter(s); position: absolute; left: 14px; top: 12px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; line-height: 1;
}
.bm-drop { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 12px 0 6px; padding: 16px; border: 2px dashed var(--accent); border-radius: 12px; background: var(--accent-soft); }
.bm-drop .bm-link { font-size: 15px; padding: 9px 18px; }
.bm-drop .arrow { color: var(--accent); font-weight: 700; font-size: 14px; }
.guide .note { color: var(--warn); font-size: 13.5px; }
.callout { margin: 12px 0; padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); font-size: 14.5px; }
.table-wrap { overflow-x: auto; margin: 10px 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.guide table { width: 100%; border-collapse: collapse; font-size: 14px; }
.guide th, .guide td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.guide thead th { border-top: 0; background: var(--surface-2); color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.guide td.ok { color: var(--ok); font-weight: 600; }
.guide td.no { color: var(--warn); font-weight: 600; }
.guide td small { font-weight: 400; color: var(--muted); }
.guide .back { margin: 40px 0 0; }
