:root {
  --orange: #e65100; --orange-dark: #bf360c; --blue: #1565c0; --red: #c62828; --green: #2e7d32;
  --bg: #f6f3f1; --card: #fff; --line: #e3dcd7; --text: #231f1d; --muted: #6d625c;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin: .4rem 0; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: .45rem .8rem; color: var(--text); }
button:hover:not(:disabled) { border-color: var(--orange); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--orange); border-color: var(--orange); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--orange-dark); }
button.danger { color: var(--red); border-color: #e7b9b9; }
button.ghost { background: transparent; border-color: transparent; color: #fff; }
button.small { padding: .2rem .5rem; font-size: .85rem; }
input, textarea, select { font: inherit; width: 100%; padding: .5rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
textarea { min-height: 4.5rem; resize: vertical; }
label { display: block; font-weight: 600; margin: .6rem 0 .2rem; font-size: .9rem; }
label input, label textarea { font-weight: normal; margin-top: .2rem; }

.login { min-height: 100%; display: grid; place-items: center; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; }
.login-card { width: min(380px, 100%); }
.login-card h1 { margin: 0; color: var(--orange); }

.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .8rem; background: #231f1d; color: #fff; padding: .5rem 1rem; }
.topbar strong { color: #ffb78a; font-size: 1.1rem; }
.topbar .muted { color: #bdb2ab; }
.spacer { flex: 1; }
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 420px; max-width: 46vw; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--bg); min-height: 0; }
.mapwrap { flex: 1; min-width: 0; position: relative; }
.map { position: absolute; inset: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); background: #fff; }
.tabs button { flex: 1; border: 0; border-radius: 0; border-bottom: 3px solid transparent; padding: .7rem .3rem; background: #fff; }
.tabs button.active { border-bottom-color: var(--orange); color: var(--orange); font-weight: 700; }
.panel { overflow-y: auto; padding: .8rem; flex: 1; min-height: 0; }
@media (max-width: 800px) {
  .layout { flex-direction: column-reverse; }
  .sidebar { width: 100%; max-width: none; height: 55%; border-right: 0; border-top: 1px solid var(--line); }
  .mapwrap { height: 45%; flex: none; }
}

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.stack > * + * { margin-top: .6rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
h3 { font-size: .95rem; margin: .8rem 0 .3rem; }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .25rem .65rem; font-size: .85rem; cursor: pointer; user-select: none; }
.chip.on { background: #ffe3d1; border-color: var(--orange); color: var(--orange-dark); font-weight: 600; }
.badge { display: inline-block; border-radius: 6px; padding: .05rem .4rem; font-size: .78rem; background: #e8eef5; color: #234; }
.badge.sim { background: #ffd9b0; color: #6b3500; font-weight: 600; }

.seg { display: flex; gap: .5rem; align-items: flex-start; padding: .55rem .5rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: .45rem; cursor: pointer; }
.seg.sel { border-color: var(--orange); box-shadow: 0 0 0 2px #ffd2b8; }
.seg input[type=checkbox] { width: auto; margin-top: .25rem; }
.seg .name { font-weight: 600; }
.seg .meta { font-size: .82rem; color: var(--muted); }
.seg .badges { margin-top: .25rem; display: flex; flex-wrap: wrap; gap: .25rem; }

.summary { font-size: 1.6rem; font-weight: 700; }
.warn { background: #fff3cd; border: 1px solid #e0b800; border-radius: 8px; padding: .5rem .7rem; font-size: .88rem; }
.item { display: flex; align-items: center; gap: .4rem; padding: .35rem .4rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: .35rem; }
.item .num { width: 1.7rem; height: 1.7rem; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.item .txt { flex: 1; min-width: 0; }
.item .txt div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: .78rem; color: var(--muted); }
.item button { padding: .15rem .4rem; }

.toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); background: #231f1d; color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 2000; max-width: 90vw; }
.toast.err { background: var(--red); }
.pin { width: 28px; height: 28px; border-radius: 50%; color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.vertex { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--red); box-shadow: 0 0 2px rgba(0,0,0,.6); }
.vertex.end { border-color: var(--green); }
.token-box { word-break: break-all; background: #f1ece8; border-radius: 8px; padding: .5rem; font-family: ui-monospace, monospace; font-size: .85rem; }
.popup button { margin: .15rem 0; display: block; width: 100%; }

/* Kacheln */
.tray { position: absolute; left: 8px; right: 8px; bottom: 26px; z-index: 900; display: flex; align-items: stretch; gap: .45rem; overflow-x: auto; padding: .5rem; background: rgba(246, 243, 241, .95); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 2px 10px rgba(0, 0, 0, .25); max-height: 55%; }
.tray-empty { padding: .6rem; align-self: center; }
.tile { flex: none; width: 168px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .4rem; display: flex; flex-direction: column; gap: .2rem; position: relative; cursor: grab; }
.tile.sel { border-color: var(--orange); box-shadow: 0 0 0 2px #ffd2b8; }
.tile.dragging { opacity: .5; }
.tile.dragover, .conn.dragover, .tray-empty.dragover { outline: 2px dashed var(--orange); outline-offset: 1px; }
.tile svg { width: 100%; height: 64px; background: #f1ece8; border-radius: 8px; display: block; }
.tile .tname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .tmeta { font-size: .78rem; color: var(--muted); }
.tile .tnum { position: absolute; top: .25rem; left: .25rem; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--orange); color: #fff; font-weight: 700; font-size: .8rem; display: grid; place-items: center; box-shadow: 0 1px 3px rgba(0, 0, 0, .4); }
.tile.wp { width: 118px; align-items: center; text-align: center; justify-content: center; }
.tile.wp .tname, .tile.wp .tmeta { max-width: 100%; }
.tile.addzone { width: 100px; border-style: dashed; color: var(--muted); align-items: center; justify-content: center; text-align: center; cursor: default; font-size: .85rem; }
.tactions { display: flex; gap: .2rem; flex-wrap: wrap; margin-top: auto; }
.tilegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.tilegrid .tile { width: auto; }
.conn { flex: none; width: 205px; display: flex; flex-direction: column; justify-content: center; gap: .25rem; padding: .2rem .3rem; font-size: .8rem; border-radius: 10px; }
.conn select { padding: .3rem .4rem; font-size: .85rem; }
.carrow { text-align: center; color: var(--orange); font-weight: 700; font-size: 1.1rem; line-height: 1; }
.cinfo { display: flex; flex-direction: column; gap: .15rem; }
.cmain { font-weight: 700; }
.cstat { color: var(--muted); font-size: .75rem; }
.cnote { font-size: .72rem; color: #7a5a00; background: #fff8dc; border-radius: 6px; padding: .1rem .3rem; }
.cerr { color: var(--red); font-size: .78rem; }
.badge.curve.r0 { background: #e8eef5; }
.badge.curve.r1 { background: #e3f1d8; color: #2c5a12; }
.badge.curve.r2 { background: #ffe1c2; color: #7a3500; font-weight: 600; }
.badge.curve.r3 { background: #ffc9c9; color: #7a0c0c; font-weight: 700; }
.badge.warnb { background: #fff3cd; color: #6b5200; }
.badge.q-real { background: #dff3df; color: #1d5d1d; }
.badge.q-approx { background: #fff3cd; color: #6b5200; }
.badge.q-limited { background: #ffd9d9; color: #7a0c0c; }
.okbox { background: #e3f4e3; border: 1px solid #8ec58e; border-radius: 8px; padding: .5rem .7rem; font-size: .88rem; }
.item.capab { align-items: flex-start; }
.item .sub.wrapsub { white-space: normal; }
.item.capab .txt div:first-child { white-space: normal; }
