:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --ink: #18201d;
    --muted: #6f7c76;
    --line: #dde4e0;
    --primary: #137a5b;
    --primary-dark: #0f6048;
    --primary-soft: #e4f4ed;
    --danger: #b63c43;
    --danger-soft: #fff0f0;
    --warning: #a36c08;
    --warning-soft: #fff6db;
    --shadow: 0 12px 35px rgba(25, 42, 35, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
code { border-radius: 7px; background: #eff2f0; padding: 2px 6px; color: #355047; font-size: .9em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(21px, 3vw, 28px); line-height: 1.2; }
h2 { margin-bottom: 5px; font-size: 21px; }
h3 { margin-bottom: 4px; font-size: 16px; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); }
.eyebrow { margin-bottom: 4px; color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: .14em; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; display: flex; width: 260px; flex-direction: column; padding: 22px 16px; background: #14251f; color: #dbe8e2; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 9px 24px; }
.brand strong, .brand small { display: block; }
.brand small { color: #8fb0a3; font-size: 11px; }
.brand-mark { display: grid; width: 40px; height: 40px; flex: 0 0 auto; place-items: center; border-radius: 13px; background: linear-gradient(145deg, #2cb386, #0e7254); color: #fff; font-size: 20px; font-weight: 900; box-shadow: 0 8px 20px rgba(16, 157, 111, .28); }
.sidebar nav { display: grid; gap: 5px; }
.nav-link { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 11px; color: #b9cdc5; font-weight: 650; transition: .16s ease; }
.nav-link:hover, .nav-link.active { background: rgba(255, 255, 255, .09); color: #fff; }
.nav-link.active { box-shadow: inset 3px 0 #39c697; }
.nav-icon { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 7px; background: rgba(255,255,255,.07); font-size: 10px; }
.sidebar-bottom { display: grid; gap: 3px; margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.09); }

.main { min-height: 100vh; margin-left: 260px; }
.topbar { display: flex; height: 86px; align-items: center; justify-content: space-between; padding: 0 32px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.86); backdrop-filter: blur(12px); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar-actions form { margin: 0; }
.automation-toggle { display: inline-flex; min-height: 40px; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 13px; background: #fff; color: #4b5d55; font-size: 12px; font-weight: 850; }
.automation-toggle.is-automatic { border-color: #a6d8c4; background: var(--primary-soft); color: var(--primary-dark); }
.automation-toggle.is-manual { border-color: #e6cf9b; background: var(--warning-soft); color: var(--warning); }
.worker-toggle { display: inline-flex; min-height: 40px; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 13px; background: #fff; color: #4b5d55; font-size: 12px; font-weight: 900; }
.worker-toggle.is-on { border-color: #9ed9c5; background: #e8f8f1; color: #087a57; }
.worker-toggle.is-off { border-color: #e3a8a8; background: #fff0f0; color: #b42318; }
.automation-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px rgba(255,255,255,.55); }
.content { padding: 28px 32px 60px; }
.user-chip { display: flex; align-items: center; gap: 9px; color: #405049; font-weight: 650; }
.user-chip span, .avatar { display: grid; width: 35px; height: 35px; place-items: center; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 850; text-transform: uppercase; }
.menu-button { display: none; }

.page-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; margin-bottom: 24px; }
.page-actions p { margin-bottom: 0; }
.button-row { display: flex; align-items: center; gap: 9px; }
.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 11px; padding: 9px 15px; font-weight: 750; transition: .16s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--primary); color: #fff; box-shadow: 0 8px 18px rgba(19, 122, 91, .18); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { border-color: var(--line); background: #fff; color: #355047; }
.button-ghost { color: var(--muted); }
.button-danger { background: var(--danger); color: #fff; }
.icon-button { border: 0; background: transparent; font-size: 22px; }

.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-grid.compact { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stat-grid.curation-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card { display: flex; min-height: 128px; flex-direction: column; justify-content: center; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 18px; box-shadow: 0 4px 16px rgba(25,42,35,.03); }
.stat-card:hover { border-color: #bdcdc6; }
.stat-card span { color: var(--muted); font-weight: 700; }
.stat-card strong { margin: 3px 0; font-size: 31px; line-height: 1.15; }
.stat-card .small-strong { font-size: 13px; overflow-wrap: anywhere; }
.stat-card small { color: #87938e; }
.danger-soft { border-color: #f1cbcd; background: var(--danger-soft); }

.panel { margin-bottom: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 20px; box-shadow: 0 5px 20px rgba(25,42,35,.035); }
.panel.flush { padding: 0; overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 17px; }
.panel-header h3, .panel-header p { margin-bottom: 0; }
.panel-header p { color: var(--muted); font-size: 12px; }
.panel-header > a { color: var(--primary); font-weight: 750; }
.two-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.three-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.empty-state { display: grid; min-height: 105px; place-items: center; color: var(--muted); text-align: center; }

.source-list { display: grid; gap: 4px; }
.source-row { display: flex; min-height: 56px; align-items: center; gap: 11px; border-bottom: 1px solid #eef2f0; padding: 7px 2px; }
.source-row:last-child { border-bottom: 0; }
.source-row > div { display: grid; flex: 1; }
.source-row small { color: var(--muted); }
.status-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; background: #a8b2ae; box-shadow: 0 0 0 4px #edf0ef; }
.status-dot.ok { background: #20a574; box-shadow: 0 0 0 4px #e2f5ed; }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.sync-summary dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sync-summary dl div { border-radius: 12px; background: #f7f9f8; padding: 12px; }
.sync-summary dt { color: var(--muted); font-size: 11px; }
.sync-summary dd { margin: 0; font-size: 21px; font-weight: 850; }

.badge { display: inline-flex; width: fit-content; align-items: center; border-radius: 999px; background: #edf1ef; padding: 4px 9px; color: #53615b; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge-success { background: var(--primary-soft); color: var(--primary-dark); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.metadata-issue-badge { margin: 2px 4px 2px 0; white-space: normal; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid #edf1ef; padding: 12px 13px; text-align: left; vertical-align: middle; }
th { background: #f8faf9; color: #66746e; font-size: 11px; letter-spacing: .025em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfb; }
td small { display: block; }
.legacy-row { background: #fffafa; }
.checkbox-cell { width: 42px; text-align: center; }
.lock { color: #aab3af; }
.id-text { max-width: 200px; overflow: hidden; color: #9aa49f; text-overflow: ellipsis; white-space: nowrap; }
.truncate { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.user-card { display: flex; align-items: center; gap: 14px; border: 1px solid var(--line); border-radius: 16px; background: #fff; padding: 17px; }
.user-card:hover { border-color: #a7c9bc; box-shadow: var(--shadow); }
.user-card .avatar { width: 45px; height: 45px; font-size: 17px; }
.user-card-main { display: grid; flex: 1; }
.user-card-main strong { font-size: 16px; }
.user-card-main small, .confidence span, .confidence small { color: var(--muted); font-size: 11px; }
.confidence { display: grid; text-align: right; }
.confidence strong { color: var(--primary); font-size: 18px; }
.back-link { display: inline-block; margin-bottom: 7px; color: var(--primary); font-weight: 750; }
.ranking { margin: 0; padding: 0; list-style: none; }
.ranking li { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid #edf1ef; padding: 8px 0; }
.ranking li:last-child { border-bottom: 0; }
.ranking strong { color: var(--primary); }
.ranking li > span small { display: block; margin-top: 2px; color: var(--muted); }

.filter-bar { display: flex; align-items: end; gap: 10px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; padding: 13px; }
label { display: grid; gap: 6px; color: #4d5b55; font-size: 12px; font-weight: 700; }
input, select { width: 100%; min-height: 40px; border: 1px solid #cfd8d4; border-radius: 10px; background: #fff; padding: 9px 11px; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(19,122,91,.1); }
input:disabled, select:disabled { cursor: not-allowed; background: #f2f4f3; color: #8a9590; }
input[type="checkbox"] { width: 17px; min-height: auto; accent-color: var(--primary); }
.bulk-bar { display: flex; min-height: 55px; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); background: #f8faf9; padding: 10px 14px; }
.check-label { display: flex; align-items: center; gap: 8px; }
.danger-zone { display: grid; grid-template-columns: 1fr minmax(220px, 320px) auto; align-items: end; gap: 18px; margin-top: 20px; border: 1px solid #efc4c7; border-radius: var(--radius); background: var(--danger-soft); padding: 20px; }
.danger-zone h3, .danger-zone p { margin-bottom: 3px; }
.danger-zone p { color: #7e5558; }

.source-card { min-height: 160px; }
.source-title { display: flex; align-items: center; gap: 10px; }
.source-title h3 { margin: 0; text-transform: capitalize; }
.source-version { display: block; margin: 20px 0 4px; font-size: 19px; }
.source-card small { color: var(--muted); }
.config-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.config-grid div { display: grid; background: #fff; padding: 12px; }
.config-grid span { color: var(--muted); font-size: 11px; }
.config-grid strong { overflow-wrap: anywhere; }
.method { display: inline-flex; min-width: 54px; justify-content: center; border-radius: 7px; padding: 4px 7px; background: #edf1ef; font-size: 10px; font-weight: 900; }
.method-get { background: #e6f3ff; color: #12659b; }
.method-post { background: #e5f6ee; color: #147550; }
.method-delete { background: var(--danger-soft); color: var(--danger); }

.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; }
.template-card { display: flex; min-height: 185px; gap: 15px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 20px; }
.template-icon { display: grid; width: 43px; height: 43px; flex: 0 0 auto; place-items: center; border-radius: 13px; background: var(--primary-soft); color: var(--primary); font-size: 20px; }
.template-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.template-title h3 { margin: 0; }
.template-card p { color: var(--muted); }
.template-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.template-meta span { border-radius: 7px; background: #f1f4f2; padding: 4px 7px; color: #64716c; font-size: 10px; font-weight: 700; }
.roadmap { margin-top: 20px; }
.roadmap li { margin-bottom: 7px; }

.alert { margin-bottom: 18px; border-radius: 12px; padding: 12px 14px; font-weight: 650; }
.alert-success { background: var(--primary-soft); color: var(--primary-dark); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.button-block { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.template-card-stack { display: grid; min-height: 0; align-content: start; }
.compact-stack { gap: 10px; margin-top: 5px; }
.form-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.preview-header { padding: 20px 20px 0; }
.mix-builder .filter-bar { margin-bottom: 14px; }
.publish-panel { border-color: #b8d8cb; box-shadow: 0 10px 28px rgba(19,122,91,.08); }
.publish-panel hr { margin: 20px 0; border: 0; border-top: 1px solid var(--line); }
.publish-panel .filter-bar { margin-top: 15px; }

.auth-body { display: grid; min-height: 100vh; place-items: center; padding: 20px; background: radial-gradient(circle at top left, #dceee7, transparent 45%), #f4f7f5; }
.auth-card { width: min(100%, 430px); border: 1px solid var(--line); border-radius: 24px; background: #fff; padding: 32px; box-shadow: var(--shadow); }
.auth-card .brand-mark { margin-bottom: 20px; }
.auth-card h1 { margin-bottom: 7px; }
.stack { display: grid; gap: 15px; margin-top: 22px; }
.overlay { display: none; }

@media (max-width: 1100px) {
    .stat-grid, .stat-grid.compact, .stat-grid.curation-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .template-grid, .three-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .topbar { height: 76px; padding: 0 18px; }
    .topbar-actions { gap: 7px; }
    .automation-toggle, .worker-toggle { max-width: 118px; min-height: 36px; padding: 6px 9px; font-size: 10px; line-height: 1.15; }
    .content { padding: 20px 16px 50px; }
    .menu-button { display: block; }
    .user-chip { font-size: 0; }
    .page-actions { align-items: stretch; flex-direction: column; }
    .page-actions .button-row, .page-actions form, .page-actions .button { width: 100%; }
    .two-columns, .three-columns, .template-grid, .user-grid { grid-template-columns: 1fr; }
    .overlay.open { position: fixed; inset: 0; z-index: 20; display: block; background: rgba(9,22,17,.46); }
    .danger-zone { grid-template-columns: 1fr; align-items: stretch; }
}

@media (max-width: 560px) {
    .stat-grid, .stat-grid.compact, .stat-grid.curation-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-card { min-height: 105px; padding: 14px; }
    .stat-card strong { font-size: 25px; }
    .filter-bar { align-items: stretch; flex-direction: column; }
    .button-row { align-items: stretch; flex-direction: column; }
    .config-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 24px; }
    .form-pair { grid-template-columns: 1fr; }
}
.template-match-table table{min-width:1180px}.template-match-table td small{display:block;margin-top:.3rem}.danger-text{color:#a33}.source-tabs details{border-top:1px solid var(--border);padding:.75rem 0}.source-tabs details:first-child{border-top:0}.source-tabs summary{cursor:pointer}.source-code{max-height:34rem;overflow:auto;padding:1rem;border-radius:.65rem;background:#14201d;color:#dcece7;white-space:pre-wrap;word-break:break-word;font-size:.8rem;line-height:1.5}.detail-list>div{display:grid;grid-template-columns:9rem 1fr;gap:1rem;padding:.55rem 0;border-bottom:1px solid var(--border)}.detail-list dt{font-weight:700}.detail-list dd{margin:0;overflow-wrap:anywhere}
