:root {
  --brand: #1670e8; --brand-600: #0f5bc4; --brand-50: #eef5ff;
  --ink: #0f172a; --muted: #64748b; --line: #e2e8f0; --bg: #f6f8fb; --danger: #e11d48;
  font-family: 'Pretendard Variable', Pretendard, -apple-system, system-ui, 'Malgun Gothic', sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5; word-break: keep-all; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }

.btn { border: 0; cursor: pointer; padding: 10px 16px; border-radius: 10px; font-weight: 700; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.primary:disabled { background: #cbd5e1; cursor: default; }
.btn.ghost { background: #fff; border: 1px solid var(--line); color: #334155; }
.btn.ghost:hover { background: #f1f5f9; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--danger); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(165deg, #1670e8, #0b2f66); }
.login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 20px; padding: 32px 28px; display: grid; gap: 12px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.login-card img { margin: 0 auto 4px; border-radius: 14px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.login-card input { padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; }
.login-card .btn { justify-content: center; padding: 13px; font-size: 16px; }
.error { color: var(--danger) !important; min-height: 1em; }
.back { font-size: 13px; color: var(--muted); }

/* App shell */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--brand); }
.brand img { border-radius: 8px; }
.top-actions { display: flex; gap: 8px; }
.layout { display: grid; grid-template-columns: 220px 1fr; gap: 24px; max-width: 1100px; margin: 0 auto; padding: 24px 20px 120px; }
.tabs { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 76px; align-self: start; }
.tabs button { text-align: left; border: 0; background: transparent; padding: 10px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; color: #334155; display: flex; justify-content: space-between; align-items: center; }
.tabs button:hover { background: #eef2f7; }
.tabs button.on { background: var(--brand); color: #fff; }
.tabs .off-dot { font-size: 11px; font-weight: 600; opacity: .7; }

.editor { min-width: 0; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.panel h2 { margin: 0; font-size: 20px; }
.help { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 13px; font-weight: 700; color: #334155; }
.field small { color: var(--muted); font-size: 12px; }
.field input[type=text], .field input[type=url], .field textarea, .field select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 15px; }
.field textarea { resize: vertical; min-height: 72px; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--brand-50); border-color: var(--brand); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 14px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; font-weight: 600; user-select: none; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 999px; background: #cbd5e1; position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(18px); }

.items { display: grid; gap: 12px; margin-top: 8px; }
.item { border: 1px solid var(--line); border-radius: 14px; padding: 16px 16px 2px; background: #fbfcfe; }
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.item-head b { font-size: 14px; color: var(--brand-600); }
.item-tools { display: flex; gap: 4px; }
.add { margin-top: 12px; width: 100%; justify-content: center; border: 1.5px dashed #b6d3fd; background: var(--brand-50); color: var(--brand-600); padding: 12px; }
.sub-title { font-size: 15px; margin: 24px 0 4px; }

.image-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.image-field .thumb { width: 88px; height: 88px; border-radius: 12px; object-fit: cover; background: #eef2f7; border: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.image-field label.btn { position: relative; overflow: hidden; }
.image-field input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.savebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.95); backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
.status { margin-right: auto; font-size: 14px; color: var(--muted); }
.status.dirty { color: #c2410c; font-weight: 700; }
.savebar .btn.primary { padding: 12px 24px; font-size: 15px; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px); background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 40; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; padding: 0 0 120px; gap: 0; }
  .tabs { position: sticky; top: 53px; z-index: 10; flex-direction: row; overflow-x: auto; gap: 4px; padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line); scrollbar-width: none; }
  .tabs button { flex: none; padding: 8px 12px; font-size: 14px; }
  .tabs .off-dot { display: none; }
  .editor { padding: 12px; }
  .panel { padding: 18px 16px; }
  .topbar { padding: 8px 12px; }
  .top-actions .btn { padding: 8px 10px; font-size: 13px; }
}

/* v2: 계정 · 레이아웃 */
.login-card > div { display: grid; gap: 12px; }
.login-card input { width: 100%; }
.whoami { font-size: 13px; color: var(--muted); align-self: center; margin-right: 4px; }
.whoami b { color: var(--ink); }
.tabs .group { font-size: 11px; font-weight: 800; letter-spacing: .08em; color: #94a3b8; padding: 14px 14px 4px; }
.field input[type=color] { width: 64px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.field input[type=range] { width: 100%; accent-color: var(--brand); }
.image-field .thumb.wide { width: 160px; height: 90px; }
.order-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.order-row .name { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-row .kind { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 6px; }
.order-row.fixed { background: #f8fafc; color: var(--muted); }
.order-list { display: grid; gap: 8px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 700; }
.badge-role { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--brand-50); color: var(--brand-600); }
.badge-role.owner { background: #fef3c7; color: #92400e; }
.invite-box { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.invite-box .field { flex: 1; min-width: 180px; margin: 0; }
.linkbox { margin-top: 14px; padding: 14px; border-radius: 12px; background: var(--brand-50); display: grid; gap: 8px; font-size: 14px; }
.linkbox code { word-break: break-all; font-size: 13px; background: #fff; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); }
.log li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 12px; }
.log { list-style: none; margin: 0; padding: 0; }
.log time { color: var(--muted); flex: none; width: 120px; }
.callout { padding: 14px 16px; border-radius: 12px; background: #fff7ed; color: #9a3412; font-size: 14px; margin-bottom: 16px; }
@media (max-width: 800px) { .whoami { display: none; } .tabs .group { display: none; } .log time { width: 90px; } }

/* v3: 아이디 저장 · 자동 로그인 */
.login-opts { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: #334155; padding: 0 2px; }
.login-opts label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.login-opts input { width: 18px; height: 18px; accent-color: var(--brand); margin: 0; }
.login-card .opt-hint { font-size: 12px; }
