:root {
    --bg: #f6f7f9; --card: #fff; --text: #17202e; --muted: #667085; --line: #e4e7ec;
    --accent: #2f6fde; --accent-soft: #e8f0fd; --danger: #c8372d; --danger-soft: #fdecea;
    --ok: #1a7f4b; --warn: #9a6400; --warn-soft: #fff6e0; --side: #111827; --side-fg: #aab2c0;
    --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f131a; --card: #171c25; --text: #e6e9ef; --muted: #98a2b3; --line: #2a313d;
        --accent: #6b9cff; --accent-soft: #1d2a44; --danger: #ff6b5e; --danger-soft: #3a1f1d;
        --ok: #4ccf8a; --warn: #f0b847; --warn-soft: #33290f; --side: #0a0d12;
        --shadow: none; color-scheme: dark;
    }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: 1rem; margin: 1.4rem 0 .6rem; }
.form h3:first-child, .preview h3 { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ok { color: var(--ok); } .bad { color: var(--danger); } .danger { color: var(--danger); }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side { width: 220px; flex: none; background: var(--side); color: var(--side-fg); padding: 1.25rem .75rem; display: flex; flex-direction: column; }
.brand { color: #fff; font-weight: 600; font-size: 1.1rem; padding: 0 .6rem 1.25rem; display: flex; gap: .5rem; align-items: center; }
.logo { background: var(--accent); color: #fff; border-radius: 7px; width: 28px; height: 28px; display: grid; place-items: center; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--side-fg); padding: .5rem .7rem; border-radius: 7px; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.side-foot { margin-top: auto; font-size: .8rem; padding: .6rem; opacity: .7; }
.main { flex: 1; padding: 1.75rem 2rem 4rem; max-width: 1300px; min-width: 0; }
@media (max-width: 760px) {
    .shell { flex-direction: column; }
    .side { width: auto; flex-direction: row; align-items: center; padding: .6rem 1rem; overflow-x: auto; }
    .brand { padding: 0 1rem 0 0; } .side nav { flex-direction: row; } .side-foot { display: none; }
    .main { padding: 1.25rem 1rem 3rem; }
}

.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.head p { margin: 0; max-width: 60ch; }
.back { font-size: .9rem; display: inline-block; margin-bottom: .3rem; }
.title-input { font-size: 1.5rem; font-weight: 600; border: 1px solid transparent; background: transparent; padding: .1rem .3rem; margin-left: -.35rem; width: min(600px, 100%); color: var(--text); border-radius: 6px; }
.title-input:hover, .title-input:focus { border-color: var(--line); background: var(--card); outline: none; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1rem; display: block; color: inherit; }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.spacer { flex: 1; }
.empty { text-align: center; padding: 3rem 1rem; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h3 { margin-top: 0; }

/* forms */
label, .field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
label > span:first-child, .field > span:first-child { font-weight: 500; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; margin: 0; }
label.check > span { font-weight: 400; }
input, select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: .5rem .65rem; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.narrow { width: 6rem; }
.inline { display: flex; gap: .5rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 1.25rem; }
.grid2 label.check { margin-top: 1.6rem; }
.hint { font-size: .85rem; color: var(--muted); margin: .2rem 0 .6rem; }
.hint.warn { color: var(--warn); background: var(--warn-soft); padding: .45rem .65rem; border-radius: 7px; }
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .35rem .75rem; max-height: 220px; overflow: auto; padding: .5rem; border: 1px solid var(--line); border-radius: 7px; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .2rem; }
.chip { font: inherit; font-size: .8rem; border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 99px; padding: .15rem .6rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: .8rem; }
.seg button { font: inherit; border: 0; background: transparent; color: var(--text); padding: .45rem 1rem; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }

.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 7px; padding: .5rem .95rem; cursor: pointer; display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.ghost.danger { color: var(--danger); border-color: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.actions { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.sticky-save { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; }

/* info tooltip */
.info { position: relative; display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; border: 1px solid var(--muted); color: var(--muted); font: italic 600 11px/1 Georgia, serif; cursor: help; vertical-align: 2px; margin-left: .25rem; }
.info .tip { display: none; position: absolute; z-index: 20; left: 50%; top: 150%; transform: translateX(-50%); width: min(300px, 80vw); background: var(--text); color: var(--bg); font: 400 13px/1.45 "Segoe UI", system-ui, sans-serif; padding: .6rem .75rem; border-radius: 7px; box-shadow: 0 6px 20px rgba(0,0,0,.2); text-align: left; }
.info:hover .tip, .info:focus .tip { display: block; }
.info:focus { outline: 2px solid var(--accent); }

/* rules list */
.rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 1rem; }
.rule { margin: 0; transition: border-color .15s; }
.rule:hover { border-color: var(--accent); }
.rule p { margin: .5rem 0; }
.count { font-weight: 600; color: var(--text); }
.count.danger { color: var(--danger); }
.pill { font-size: .75rem; padding: .1rem .55rem; border-radius: 99px; background: var(--line); color: var(--muted); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* editor */
.editor { display: grid; grid-template-columns: minmax(320px, 440px) 1fr; gap: 1rem; align-items: start; }
.preview { position: sticky; top: 1rem; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } .preview { position: static; } }
.sentence { background: var(--accent-soft); border-radius: 7px; padding: .55rem .75rem; margin: .5rem 0 .9rem; }
.stat { font-size: 1.05rem; margin-bottom: .6rem; }
.stat strong { font-size: 1.6rem; }
.table-wrap { max-height: 62vh; overflow: auto; border: 1px solid var(--line); border-radius: 7px; }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; table-layout: auto; }
.table th { text-align: left; font-weight: 500; color: var(--muted); padding: .45rem .6rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.table td { padding: .4rem .6rem; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lvl-error td:last-child { color: var(--danger); } .lvl-warn td:last-child { color: var(--warn); }

/* progress */
.busy { background: var(--card); border: 1px solid var(--accent); border-radius: var(--radius); padding: .65rem 1rem; margin-bottom: 1.25rem; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.busy-text { flex: 1; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; min-width: 0; }
.bar { flex-basis: 100%; height: 5px; background: var(--line); border-radius: 9px; overflow: hidden; }
.bar div { height: 100%; background: var(--accent); transition: width .3s; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: .65rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: var(--card); border-radius: 12px; padding: 1.4rem; max-width: 520px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h3 { margin-top: 0; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; background: var(--warn-soft); color: var(--text); padding: .7rem 1.25rem; z-index: 100; }

h1:focus { outline: none; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login form { width: min(380px, 100%); padding: 1.75rem; }
.brand-dark { font-weight: 600; font-size: 1.2rem; display: flex; gap: .5rem; align-items: center; margin-bottom: 1.25rem; }
.btn.wide { width: 100%; justify-content: center; margin-top: .25rem; }
.who { margin-bottom: .4rem; }
.who strong { color: #fff; }
.side-btn { color: var(--side-fg); border-color: rgba(255,255,255,.15); }
.side-foot .info { border-color: var(--side-fg); color: var(--side-fg); }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }
