:root {
  --bg: #f5f4f0; --panel: #ffffff; --ink: #1d2126; --muted: #6a7079; --line: #dedbd3; --soft: #efede7;
  --accent: #1d2126; --danger: #c0392b; --sel: #fff3bf;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) { :root {
  --bg: #15171a; --panel: #1e2125; --ink: #e7e9ec; --muted: #9299a3; --line: #33383f; --soft: #262a2f;
  --accent: #e7e9ec; --danger: #f07167; --sel: #4a4320;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
}}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, select, input, textarea {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: var(--soft); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--panel); border-color: var(--accent); }
button.primary:hover:not(:disabled) { opacity: .88; background: var(--accent); }
button.icon { padding: 3px 8px; }
button.wide { width: 100%; }
button.link { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; }
button.danger, .danger { color: var(--danger); }
input:focus, select:focus, button:focus-visible { outline: 2px solid #7aa7ff; outline-offset: -1px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

#app { display: flex; height: 100%; }

/* left */
#left { width: 260px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
#left.collapsed { width: 42px; }
#left.collapsed .hide-c { display: none; }
#left.collapsed .lhead { justify-content: center; padding: 10px 0; }
.lhead { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.lbody { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 0; min-height: 0; flex: 1; }
#search { width: 100%; }
#list { overflow: auto; flex: 1; margin: 0 -12px; padding: 4px 0; }
.item { display: flex; gap: 8px; align-items: center; padding: 7px 12px; cursor: pointer; border-left: 3px solid transparent; }
.item:hover { background: var(--soft); }
.item.on { background: var(--soft); border-left-color: var(--accent); }
.item .ic { width: 18px; height: 18px; flex: none; color: var(--muted); }
.item .tx { min-width: 0; }
.item .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.item .d { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 11px; }
.lrow { display: flex; gap: 6px; }
.lrow #search { flex: 1; min-width: 0; }
#sort { flex: none; display: flex; align-items: center; justify-content: center; width: 30px; padding: 0; color: var(--muted); }
#sort:hover { color: var(--ink); }
#sort svg { width: 16px; height: 16px; display: block; }
.pop button.chk { position: relative; padding-left: 26px; }
.pop button.chk.on::before { content: "\2713"; position: absolute; left: 9px; }
#fmenu { position: fixed; right: auto; z-index: 40; }
.fhead { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 10px; cursor: pointer; user-select: none; font-weight: 600; }
.fhead:hover { background: var(--soft); }
.fhead .caret { width: 12px; flex: none; color: var(--muted); font-size: 14px; line-height: 1; }
.fhead .fic { width: 16px; height: 16px; flex: none; color: var(--muted); }
.fhead .fic svg { width: 16px; height: 16px; display: block; }
.fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fhead input { flex: 1; min-width: 0; padding: 1px 5px; font-weight: 600; }
.fcount { color: var(--muted); font-size: 11px; font-weight: 400; }
.fmore { border: 0; background: none; padding: 0 4px; visibility: hidden; color: var(--muted); }
.fhead:hover .fmore, .fmore:focus-visible { visibility: visible; }
.fgroup.closed .fitems { display: none; }
.fgroup.real .item { padding-left: 28px; }
.fempty { padding: 3px 12px 7px 32px; }
.fgroup.loose .fempty { padding-left: 12px; }
.loosehead { padding: 10px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.fgroup.drop-in { background: var(--soft); box-shadow: inset 0 0 0 2px var(--accent); }
.fgroup.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.fgroup.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.dragging { opacity: .4; }
.lfoot { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }

/* center */
#center { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: auto; }
.empty { margin: auto; text-align: center; color: var(--muted); }
#editor { display: flex; flex-direction: column; gap: 12px; padding: 14px 20px 20px; min-height: 100%; }
.chead { display: flex; align-items: center; gap: 8px; }
.title-input { flex: 1; min-width: 120px; font-size: 18px; font-weight: 600; border-color: transparent; background: transparent; padding: 4px 6px; }
.title-input:hover { border-color: var(--line); }
.menu { position: relative; }
.pop { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; min-width: 160px; display: flex; flex-direction: column;
       background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; }
.pop button { border: 0; text-align: left; }
.pbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: var(--accent); color: var(--panel); border-color: var(--accent); position: relative; }
.pwrap { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 24px;
         background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 18px 18px;
         border: 1px solid var(--line); border-radius: 10px; overflow: auto; min-height: 420px; }
#preview { padding: 10px 12px; border-radius: 4px; box-shadow: var(--shadow); outline: 1px dashed var(--line); outline-offset: 3px; }
#linkLine { margin: 0; word-break: break-all; }

/* right */
#right { width: 330px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
#right.off { visibility: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; padding: 10px; border-bottom: 2px solid transparent; color: var(--muted); background: none; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
#form { overflow: auto; flex: 1; padding: 12px 14px 30px; }
.sec { margin-bottom: 16px; }
.sec > h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.fld > span { color: var(--muted); font-size: 12px; }
.fld select, .fld input[type=text], .fld input[type=number] { width: 100%; }
.row { display: flex; gap: 6px; align-items: center; }
.row > * { min-width: 0; }
.rule { display: grid; grid-template-columns: 1fr 26px; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: var(--soft); }
.rule .rparts { display: flex; flex-direction: column; gap: 4px; }
.rule select, .rule input { width: 100%; }
.rule .x { padding: 2px; border: 0; background: none; color: var(--muted); align-self: start; }
.types { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.types button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px; font-size: 11px; }
.types button svg { width: 24px; height: 24px; }
.types button.on { outline: 2px solid var(--accent); outline-offset: -1px; }
.swatches { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 4px; }
.swatches i { width: 16px; height: 16px; border-radius: 3px; border: 1px solid var(--line); }
.check { display: flex; gap: 6px; align-items: center; }
.slider input[type=range] { flex: 1; padding: 0; border: 0; background: none; accent-color: var(--accent); }
.slider > span { width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.warn { color: var(--danger); font-size: 12px; }
.missing { border-color: var(--danger) !important; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel);
         padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; }

/* login */
body.login { display: grid; place-items: center; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: 300px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.login-box h1 { margin: 0; font-size: 18px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.login-box input { color: var(--ink); }
.err { color: var(--danger); margin: 0; }

@media (max-width: 1000px) {
  #app { flex-direction: column; height: auto; }
  #left, #right { width: auto; }
}
