/* Textzähler: ergänzt app.css (Farben, Gruppen, Schalter) um Editor und Inspektor. */

:root {
  --editor-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono-font: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --editor-size: 16px;
  --editor-line: 24px;
  --editor-pad-y: 14px;
  --editor-pad-x: 16px;
  --gutter-bg: #fafafc;
  --current-line: rgba(0, 122, 255, 0.06);
  --bar-track: rgba(120, 120, 128, 0.16);
}
@media (prefers-color-scheme: dark) {
  :root { --gutter-bg: #19191b; --current-line: rgba(10, 132, 255, 0.12); --bar-track: rgba(120, 120, 128, 0.32); }
}

body { overflow-x: hidden; }

.tz { max-width: 1320px; margin: 0 auto; padding: 28px 28px 64px; }
.tz-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.tz-head .app-mark { width: 40px; height: 40px; border-radius: 10px; background: #ff9500; display: grid; place-items: center; flex: none; }
.tz-head .app-mark::after { display: none; }
.tz-head .app-mark svg { width: 22px; height: 22px; color: #fff; }
.tz-title { font-family: var(--font-display); font-size: 28px; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.tz-sub { margin: 2px 0 0; color: var(--label-2); font-size: 14px; }

.tz-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
.tz-left { min-width: 0; }

/* ---------- Kennzahlen ---------- */

.stats {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  background: var(--bg-2); border-radius: var(--r-l); box-shadow: var(--shadow-1);
  margin-bottom: 14px; overflow: hidden;
}
.stat { padding: 12px 14px 11px; position: relative; min-width: 0; }
.stat + .stat::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; border-left: 0.5px solid var(--separator); }
.stat-value { font-family: var(--font-display); font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-label { font-size: 12px; color: var(--label-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Werkzeugleiste ---------- */

.toolbar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar .sep { width: 0.5px; height: 20px; background: var(--separator); margin: 0 6px; }
.toolbar .spacer { flex: 1; }
.toolbar .btn { min-height: 32px; padding: 0 10px; font-size: 14px; background: transparent; }
.toolbar .btn:hover { background: var(--fill-3); }
.toolbar .btn svg { width: 18px; height: 18px; }
.toolbar .btn.icon { width: 34px; padding: 0; }
.toolbar .btn[aria-pressed="true"] { background: var(--accent-soft); }
.toolbar .btn[aria-expanded="true"] { background: var(--fill); }
@media (pointer: coarse) { .toolbar .btn { min-height: 44px; } .toolbar .btn.icon { width: 44px; } }

/* ---------- Suchen und Ersetzen ---------- */

.findbar {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 10px 12px; margin-bottom: 10px; background: var(--bg-2); border-radius: var(--r-m); box-shadow: var(--shadow-1);
}
.findbar .field-wrap { position: relative; }
.findbar .field-wrap .field { padding-right: 70px; }
.findbar .count { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--label-2); font-variant-numeric: tabular-nums; pointer-events: none; }
.findbar .count.bad { color: var(--red); }
.findbar .controls { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.findbar .opt { min-width: 34px; font-family: var(--mono-font); font-size: 13px; font-weight: 600; }
.findbar .opt[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ---------- Editor ---------- */

.editor-box {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr);
  height: clamp(360px, 62vh, 920px); background: var(--bg-2); border-radius: var(--r-l); box-shadow: var(--shadow-1);
  overflow: hidden;
}
.editor-box.no-gutter { grid-template-columns: 0 minmax(0, 1fr); }
.editor-box.no-gutter .gutter { display: none; }
.editor-box.dragging { box-shadow: inset 0 0 0 2px var(--accent), var(--shadow-1); }
.editor-box .drop-hint {
  position: absolute; inset: 0; display: none; place-items: center; background: var(--accent-soft); color: var(--accent);
  font-weight: 600; font-size: 17px; pointer-events: none; z-index: 3;
}
.editor-box.dragging .drop-hint { display: grid; }

.gutter {
  position: relative; overflow: hidden; background: var(--gutter-bg); border-right: 0.5px solid var(--separator);
  font-family: var(--mono-font); font-size: 11.5px; color: var(--label-3); font-variant-numeric: tabular-nums;
  width: calc((var(--gn, 2) + var(--gl, 0)) * 1ch + var(--gl-gap, 0px) + 22px);
  user-select: none; -webkit-user-select: none;
}
.gutter-item { position: absolute; left: 0; right: 0; height: var(--editor-line); line-height: var(--editor-line); display: flex; justify-content: flex-end; gap: 10px; padding: 0 10px 0 6px; }
.gutter-item .n { min-width: calc(var(--gn, 2) * 1ch); text-align: right; }
.gutter-item .l { min-width: calc(var(--gl, 0) * 1ch); text-align: right; color: var(--label-3); opacity: 0.8; }
.gutter-item.cur .n { color: var(--label); font-weight: 600; }
.gutter-item.over .l, .gutter-item.over .n { color: var(--red); opacity: 1; }
.gutter-item.cur::before { content: ""; position: absolute; inset: 0; background: var(--current-line); }

.editor {
  display: block; width: 100%; height: 100%; margin: 0; border: 0; resize: none; outline: none;
  padding: var(--editor-pad-y) var(--editor-pad-x);
  font-family: var(--editor-font); font-size: var(--editor-size); line-height: var(--editor-line);
  color: var(--label); background: transparent; tab-size: 4; -moz-tab-size: 4;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
  overflow: auto; caret-color: var(--accent);
}
.editor.nowrap { white-space: pre; overflow-wrap: normal; }
.editor::placeholder { color: var(--label-3); }
.editor:focus-visible { outline: none; }
.editor-box:focus-within { box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.35), var(--shadow-1); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent), var(--shadow-1); }
.editor.mono { font-family: var(--mono-font); font-size: 14.5px; }

.mirror {
  position: absolute; left: 0; top: 0; visibility: hidden; pointer-events: none; z-index: -1;
  font-family: var(--editor-font); font-size: var(--editor-size); line-height: var(--editor-line);
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; tab-size: 4; -moz-tab-size: 4;
}
.mirror.mono { font-family: var(--mono-font); font-size: 14.5px; }
.mirror > div { min-height: var(--editor-line); }

.statusbar { display: flex; align-items: center; gap: 12px; padding: 8px 4px 0; font-size: 12.5px; color: var(--label-2); font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.statusbar .sel { color: var(--accent); }
.statusbar .spacer { flex: 1; }
.statusbar label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.statusbar .switch { transform: scale(0.72); transform-origin: right center; margin: -6px -8px -6px -4px; }

/* ---------- Inspektor ---------- */

.inspector { position: sticky; top: 16px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; padding: 2px 2px 16px; margin: -2px; }
.inspector-tabs { display: grid; grid-template-columns: repeat(6, 1fr); background: var(--fill-3); border-radius: 9px; padding: 2px; gap: 2px; margin-bottom: 6px; }
.inspector-tabs button { border: 0; background: transparent; border-radius: 7px; min-height: 32px; display: grid; place-items: center; color: var(--label-2); }
.inspector-tabs button svg { width: 18px; height: 18px; }
.inspector-tabs button[aria-selected="true"] { background: var(--bg-2); color: var(--accent); box-shadow: 0 3px 8px rgba(0,0,0,0.12), 0 3px 1px rgba(0,0,0,0.04); }
@media (prefers-color-scheme: dark) { .inspector-tabs button[aria-selected="true"] { background: #636366; color: #fff; } }
@media (pointer: coarse) { .inspector-tabs button { min-height: 40px; } }
.inspector-title { font-size: 17px; font-weight: 600; margin: 12px 4px 2px; }
.inspector .section { margin-top: 18px; }
.inspector .section-title { margin-left: 16px; }

.row-value { font-variant-numeric: tabular-nums; text-align: right; }
.row-value.strong { color: var(--label); font-weight: 600; }
.row .row-label small { margin-top: 1px; }
.row.compact { min-height: 38px; }

.bar { height: 6px; border-radius: 3px; background: var(--bar-track); overflow: hidden; width: 100%; }
.bar > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.2s var(--ease); }
.bar.warn > span { background: var(--orange); }
.bar.over > span { background: var(--red); }

.limit { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 10px 16px 11px; position: relative; }
.limit + .limit::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--separator); }
.limit .name { font-size: 15px; min-width: 0; }
.limit .name small { display: block; font-size: 12px; color: var(--label-2); }
.limit .val { font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.limit .val b { color: var(--label); font-weight: 600; }
.limit .val .bad { color: var(--red); font-weight: 600; }
.limit .bar { grid-column: 1 / -1; margin-top: 6px; }
.limit .del { position: absolute; right: 8px; top: 8px; }

.list-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%;
  min-height: 38px; padding: 6px 16px; border: 0; background: transparent; text-align: left; position: relative; font-size: 14px;
}
button.list-row:hover { background: var(--fill-3); }
.list-row + .list-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--separator); }
.list-row .k { color: var(--label-2); font-variant-numeric: tabular-nums; font-size: 12px; min-width: 2.5em; }
.list-row .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .t.wrap { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.list-row .t.empty { color: var(--label-3); font-style: italic; }
.list-row .v { color: var(--label-2); font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; text-align: right; }
.list-row .meter { grid-column: 2 / -1; height: 3px; border-radius: 2px; background: var(--bar-track); overflow: hidden; margin-top: -2px; }
.list-row .meter > span { display: block; height: 100%; background: var(--accent); opacity: 0.6; }

.line-head { display: grid; grid-template-columns: 3.2em 3.2em 3em minmax(0, 1fr); gap: 8px; padding: 6px 16px; font-size: 12px; color: var(--label-2); }
.line-row { grid-template-columns: 3.2em 3.2em 3em minmax(0, 1fr); font-size: 13px; }
.line-row .k, .line-row .v { text-align: right; }
.line-row .t { font-family: var(--mono-font); font-size: 12px; }

.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; padding: 10px; }
.char-cell { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; padding: 6px 9px; border-radius: 8px; background: var(--fill-3); font-size: 13px; font-variant-numeric: tabular-nums; min-width: 0; }
.char-cell .c { font-family: var(--mono-font); font-size: 15px; font-weight: 600; white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.char-cell .c.named { font-family: var(--font); font-size: 11px; font-weight: 500; color: var(--label-2); }
.char-cell .n { color: var(--label-2); font-size: 12px; }

.empty-note { padding: 14px 16px; font-size: 13px; color: var(--label-2); }
.empty-note.ok { display: flex; gap: 8px; align-items: center; }
.empty-note.ok svg { width: 16px; height: 16px; color: var(--green); flex: none; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px 12px; }
.score-big { font-family: var(--font-display); font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--fill-3); color: var(--label-2); margin-left: 6px; vertical-align: 2px; }

.add-limit { display: grid; grid-template-columns: minmax(0, 1fr) 84px; gap: 8px; padding: 10px 16px 12px; }
.add-limit .field { min-width: 0; }
.add-limit select.field { width: 100%; }
.add-limit .btn { grid-column: 1 / -1; }

/* ---------- Popover ---------- */

.popover {
  position: fixed; z-index: 60; min-width: 240px; max-width: min(720px, calc(100vw - 24px)); max-height: min(70vh, 640px); overflow: auto;
  background: var(--sheet); border-radius: 14px; box-shadow: var(--shadow-2), 0 0 0 0.5px var(--separator);
  padding: 6px; animation: pop-in 0.16s var(--ease);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .popover { background: color-mix(in srgb, var(--sheet) 88%, transparent); -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%); }
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
.popover .note { font-size: 12px; color: var(--label-2); padding: 6px 10px 8px; }
.menu-groups { display: grid; grid-template-columns: repeat(3, minmax(200px, 1fr)); gap: 4px 6px; }
.menu-group { padding: 2px 0 6px; }
.menu-group h3 { font-size: 11.5px; font-weight: 600; color: var(--label-2); margin: 6px 10px 3px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 30px; padding: 4px 10px;
  border: 0; background: transparent; border-radius: 7px; text-align: left; font-size: 14px; color: var(--label);
}
.menu-item svg { width: 17px; height: 17px; color: var(--accent); flex: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--accent); color: #fff; outline: none; }
.menu-item:hover svg, .menu-item:focus-visible svg { color: #fff; }
@media (pointer: coarse) { .menu-item { min-height: 44px; } }

.toast { display: flex; align-items: center; gap: 12px; }
.toast .toast-action { pointer-events: auto; border: 0; background: rgba(255,255,255,0.16); color: #fff; font-weight: 600; font-size: 14px; border-radius: 14px; padding: 4px 12px; cursor: pointer; }
.toasts { pointer-events: none; }
.toasts .toast.has-action { pointer-events: auto; }

/* ---------- Kleinere Bildschirme ---------- */

@media (max-width: 1100px) {
  .tz-layout { grid-template-columns: minmax(0, 1fr) 340px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat:nth-child(4)::before { display: none; }
  .stat:nth-child(n+4) { border-top: 0.5px solid var(--separator); }
}
@media (max-width: 900px) {
  .tz-layout { grid-template-columns: minmax(0, 1fr); }
  .inspector { position: static; max-height: none; overflow: visible; }
  .menu-groups { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
}
@media (max-width: 760px) {
  .tz { padding: 16px 16px 48px; padding-top: max(16px, env(safe-area-inset-top)); }
  .tz-title { font-size: 26px; }
  .tz-sub { font-size: 13px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 20px; }
  .toolbar { gap: 0; flex-wrap: nowrap; }
  .toolbar .btn .lbl { display: none; }
  .toolbar .btn, .toolbar .btn.icon { width: 44px; min-height: 44px; padding: 0; flex: none; }
  .toolbar .sep, .toolbar .spacer { display: none; }
  .toolbar .btn.mono-toggle { display: none; }
  .stat-label { white-space: normal; line-height: 1.2; }
  .editor-box { height: 52vh; height: 52dvh; min-height: 300px; }
  .findbar { grid-template-columns: 1fr; }
  .popover.sheet { left: 8px !important; right: 8px; top: auto !important; bottom: max(8px, env(safe-area-inset-bottom)); max-height: 72vh; min-width: 0; max-width: none; }
  .menu-groups { grid-template-columns: 1fr; }
  .statusbar .hide-mobile { display: none; }
}
