:root {
    --bg: #0f1115;
    --panel: #161922;
    --panel2: #1d2230;
    --border: #2a3142;
    --text: #e7e9ee;
    --muted: #8a93a6;
    --accent: #4f8cff;
    --accent-h: #6aa1ff;
    --ok: #2ecc71;
    --warn: #f0a35e;
    --err: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); text-decoration: underline; }
code { background: var(--panel2); padding: 0 .35em; border-radius: 3px; }
small { color: var(--muted); }
.muted { color: var(--muted); }

.topbar {
    display: flex; align-items: center; gap: 1.5rem;
    padding: .75rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topbar .brand a { color: var(--text); font-weight: 600; font-size: 1.05rem; }
.topbar .nav { display: flex; gap: 1rem; flex: 1; }
.topbar .user { color: var(--muted); display: flex; gap: .75rem; align-items: center; }
.topbar .nav a { color: var(--text); padding: .25rem .5rem; border-radius: 4px; }
.topbar .nav a:hover { background: var(--panel2); text-decoration: none; }

.container { max-width: 1400px; margin: 1.25rem auto; padding: 0 1.25rem; }

.flash { padding: .6rem .9rem; border-radius: 4px; margin-bottom: 1rem; }
.flash.ok  { background: #14361f; color: #b2efc3; border: 1px solid #235c36; }
.flash.err { background: #3a1414; color: #ffc3c3; border: 1px solid #6a2323; }

h1 { margin: .25rem 0 1rem; font-size: 1.45rem; }
h2 { margin: 1.5rem 0 .75rem; font-size: 1.15rem; border-bottom: 1px solid var(--border); padding-bottom: .35rem; }
h3 { margin: 1rem 0 .5rem; font-size: 1rem; color: var(--muted); }

.btn {
    background: var(--panel2); color: var(--text); border: 1px solid var(--border);
    padding: .45rem .9rem; border-radius: 4px; cursor: pointer; font: inherit;
}
.btn:hover { background: #242a3a; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-h); }
.btn.danger  { background: #5a2222; border-color: #7a3030; color: #ffd7d7; }
.btn.danger:hover { background: #6e2828; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.link:hover { color: var(--accent-h); text-decoration: underline; }
.link.danger { color: var(--err); }

input, select, textarea {
    background: var(--panel2); color: var(--text); border: 1px solid var(--border);
    padding: .45rem .6rem; border-radius: 4px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
label { display: block; margin-bottom: .65rem; }
label > input, label > select, label > textarea { margin-top: .25rem; }

.searchbar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.searchbar input[type=search] { flex: 1; }
.searchbar select { width: auto; }

table.data { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
table.data th, table.data td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.data th { background: var(--panel2); font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: rgba(255,255,255,.02); }
table.data .empty { color: var(--muted); text-align: center; padding: 2rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.card {
    display: block; background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
    padding: 1rem; color: var(--text);
}
.card:hover { background: var(--panel2); text-decoration: none; }
.card .num { font-size: 1.6rem; font-weight: 600; }
.card .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.card.warn .num { color: var(--warn); }

.pager { margin-top: 1rem; display: flex; gap: .25rem; }
.pager a { padding: .35rem .65rem; border: 1px solid var(--border); border-radius: 3px; }
.pager a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.auth-box { max-width: 380px; margin: 4rem auto; background: var(--panel); padding: 2rem; border-radius: 6px; border: 1px solid var(--border); }
.error-box { max-width: 600px; margin: 4rem auto; text-align: center; }

.split { display: grid; grid-template-columns: 1fr 380px; gap: 1rem; min-height: 80vh; }
.split .viewer { background: #fff; border-radius: 6px; overflow: hidden; }
.split .viewer iframe { width: 100%; height: 100%; min-height: 80vh; border: 0; }
.split .side { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; overflow: auto; }

.filename { font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; word-break: break-all; }
.meta { color: var(--muted); margin-bottom: .75rem; font-size: 13px; }

.maplist { list-style: none; padding: 0; margin: 0; }
.maplist li { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.maplist li:last-child { border-bottom: 0; }
.m-piece { font-weight: 500; }
.m-sub { color: var(--muted); font-size: 13px; margin: .15rem 0 .35rem; }

.badge { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; background: var(--panel2); border: 1px solid var(--border); margin-left: .25em; }
.badge.ok { background: #14361f; color: #b2efc3; border-color: #235c36; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1rem; }
.grid .full { grid-column: 1 / -1; }

.newform { margin: 1rem 0; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 0 1rem; }
.newform > summary { cursor: pointer; padding: .75rem 0; font-weight: 500; }
.newform[open] { padding-bottom: 1rem; }

.ac-results { background: var(--panel2); border: 1px solid var(--border); border-radius: 4px; max-height: 240px; overflow: auto; margin-top: 2px; display: none; }
.ac-results.open { display: block; }
.ac-results .item { padding: .4rem .6rem; cursor: pointer; }
.ac-results .item:hover, .ac-results .item.sel { background: var(--accent); color: #fff; }
.ac-results .item small { color: var(--muted); display: block; }
.ac-results .item:hover small, .ac-results .item.sel small { color: rgba(255,255,255,.85); }

.map-form label.check { display: flex; align-items: center; gap: .5rem; }
.map-form label.check input { width: auto; margin-top: 0; }

/* AI suggestion panel */
.ai-panel { margin: .5rem 0 1rem; }
.ai-btn { background: linear-gradient(180deg, #2a3a6a, #233057); border-color: #38528a; }
.ai-btn:hover { background: linear-gradient(180deg, #38528a, #2a3a6a); }
.ai-btn:disabled { opacity: .6; cursor: progress; }
.ai-results { margin-top: .5rem; display: flex; flex-direction: column; gap: .5rem; }
.ai-status { padding: .5rem .75rem; background: var(--panel2); border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
.ai-status.err { background: #3a1414; color: #ffc3c3; border-color: #6a2323; }
.ai-card { background: var(--panel2); border: 1px solid var(--border); border-radius: 5px; padding: .55rem .7rem; }
.ai-card-h { display: flex; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .25rem; }
.ai-card-h .conf { font-variant-numeric: tabular-nums; }
.ai-card-b { font-size: 13.5px; line-height: 1.4; }
.ai-card .ok   { color: #b2efc3; }
.ai-card .warn { color: var(--warn); }
.ai-card .small { font-size: 12px; }
.ai-card details { margin-top: .25rem; font-size: 12px; }
.ai-card details summary { cursor: pointer; color: var(--muted); }
.ai-card button.link { margin-top: .35rem; font-size: 12.5px; }

@media (max-width: 1000px) {
    .split { grid-template-columns: 1fr; }
    .grid { grid-template-columns: 1fr; }
}
