:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e3e6ea; --text: #1f2937; --muted: #6b7280;
  --accent: #16a34a; --accent-soft: #e8f6ed; --sel: #eef6ff; --danger: #dc2626;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; color: var(--text); background: var(--bg); }
input, select, textarea, button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.pad { padding: 12px; }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef0f3; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; font-size: 12px; }
.inline { display: inline; margin: 0; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; }
.login-box { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 340px; display: grid; gap: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.05); }
.login-box h1 { margin: 0 0 4px; font-size: 20px; }
.err { color: var(--danger); margin: 0; }

label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: #374151; }
label .muted, label .cnt { font-weight: 400; }
input:not([type=checkbox]), select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; font-size: 14px; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bbf7d0; border-color: var(--accent); }
textarea { resize: vertical; field-sizing: content; min-height: 3em; }

/* päis */
.top { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { margin-right: 8px; }
#search { width: 260px; }
#prioFilter { width: auto; }
#saveState { font-size: 12px; min-width: 110px; text-align: right; }

.layout { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.1fr); height: calc(100vh - 51px); }
.tree-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tree-tools { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fff; }
.hint { font-size: 12px; }
#tree { overflow: auto; flex: 1; padding: 8px 6px 60px; outline: none; }
#tree ul { list-style: none; margin: 0; padding: 0 0 0 20px; }
#tree ul.root { padding-left: 0; }
#tree li { position: relative; }
#tree ul ul::before { content: ""; position: absolute; left: 13px; top: 0; bottom: 6px; border-left: 1px dashed #d6dae0; }
#tree ul ul { position: relative; }

.row { display: flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 7px; cursor: pointer; user-select: none; border: 1px solid transparent; margin: 1px 0; }
.row:hover { background: #fff; border-color: var(--line); }
.row.sel { background: var(--sel); border-color: #bfdbfe; }
.row.dragging { opacity: .4; }
.row.drop-inside { background: var(--accent-soft); border-color: var(--accent); }
.row.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.row.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.tog { width: 14px; text-align: center; color: var(--muted); flex: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid #cbd5e1; flex: none; }
.ttl { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slug { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.badge { font-size: 11px; background: #eef0f3; border-radius: 10px; padding: 0 7px; color: var(--muted); }
.cc { font-size: 11px; background: #fff7e6; color: #9a5b00; border-radius: 10px; padding: 0 7px; flex: none; }
.cc.done { background: #eef0f3; color: var(--muted); }

/* detail */
.detail-pane { overflow: auto; padding: 18px 24px 60px; background: var(--panel); display: flex; flex-direction: column; gap: 12px; }
.empty { color: var(--muted); margin-top: 40px; text-align: center; }
.crumbs { font-size: 12px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.f-title { font-size: 22px !important; font-weight: 650 !important; border-color: transparent !important; padding: 4px 6px !important; margin-left: -6px; }
.f-title:hover { border-color: var(--line) !important; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 1.3fr; gap: 10px; }
.cnt.over { color: var(--danger); }
.meta { font-size: 12px; }
.actions { display: flex; gap: 8px; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-top: 8px; }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
#tabBody { display: grid; gap: 10px; }

.comments { display: grid; gap: 8px; }
.cm { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fcfcfd; }
.cm.resolved { opacity: .55; }
.cm-h { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.cm-b { white-space: pre-wrap; margin-top: 4px; word-break: break-word; }
.res { display: inline-flex; flex-direction: row; gap: 4px; align-items: center; font-weight: 400; color: var(--muted); }

.hist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.hist li { border-bottom: 1px solid #f0f1f3; padding: 6px 0; font-size: 13px; }
.hist-h { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.diff { margin: 4px 0 0 10px; display: grid; gap: 2px; font-size: 12px; }
.diff del { color: #b91c1c; background: #fef2f2; text-decoration: line-through; }
.diff ins { color: #166534; background: #f0fdf4; text-decoration: none; }

/* modaal */
.modal { position: fixed; inset: 0; background: rgba(17,24,39,.35); display: grid; place-items: center; z-index: 20; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 14px; width: min(720px, 94vw); max-height: 88vh; overflow: auto; padding: 20px 24px; position: relative; }
.modal-x { position: absolute; right: 12px; top: 8px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.modal h2 { margin: 0 0 8px; }
.form { display: grid; gap: 10px; max-width: 420px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.users { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.users th, .users td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 13px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 16px; border-radius: 9px; z-index: 50; font-size: 13px; }
.toast.bad { background: var(--danger); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .tree-pane { max-height: 50vh; }
  #search { width: 140px; }
  .hint { display: none; }
}

/* redaktor */
.rte { display: grid; gap: 4px; }
.lbl { font-size: 12px; font-weight: 600; color: #374151; }
.rte-bar { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; border: 1px solid var(--line); border-radius: 8px 8px 0 0; padding: 4px; background: #f9fafb; position: sticky; top: -18px; z-index: 2; }
.rte-bar button { border: 0; background: none; border-radius: 5px; padding: 3px 8px; cursor: pointer; font-size: 13px; min-width: 28px; }
.rte-bar button:hover { background: #e5e7eb; }
.rte-bar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
.rte-body { border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; padding: 10px 14px; min-height: 260px; background: #fff; outline: none; line-height: 1.55; overflow-wrap: anywhere; margin-top: -4px; }
.rte-body:focus { border-color: var(--accent); box-shadow: 0 0 0 2px #bbf7d0; }
.rte-body:empty::before { content: attr(data-ph); color: #9ca3af; }
.rte-body h2 { font-size: 18px; margin: 14px 0 6px; }
.rte-body h3 { font-size: 15px; margin: 12px 0 4px; }
.rte-body p { margin: 0 0 8px; }
.rte-body ul, .rte-body ol { margin: 0 0 8px; padding-left: 22px; }
.rte-body blockquote { margin: 0 0 8px; padding: 4px 12px; border-left: 3px solid var(--line); color: #4b5563; }
.rte-body a { color: #2563eb; }
.rte-body > :first-child { margin-top: 0; }
