:root {
  --bg: #0b1020;
  --panel: #141b2e;
  --panel-2: #1b2440;
  --line: #263254;
  --text: #e8ecf6;
  --muted: #9aa6c4;
  --primary: #6d8bff;
  --primary-2: #4f6ef0;
  --accent: #35d3a6;
  --danger: #ff6b6b;
  --warn: #f7b955;
  --chip: rgba(109,139,255,0.15);
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
tr { transition: background 0.15s ease; }
.btn { transition: all 0.15s ease; }
.tab { transition: all 0.15s ease; }
.metric { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.metric:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #17203a 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--line);
  background: rgba(20,27,46,0.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.9rem; }
.logo {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 800; letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--primary), var(--accent)); color: #08122b;
}
.brand h1 { font-size: 1.1rem; margin: 0; }
.brand p { margin: 2px 0 0; font-size: 0.78rem; color: var(--muted); }
.stat-strip { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.4rem 0.7rem; font-size: 0.78rem; color: var(--muted);
}
.stat b { color: var(--text); font-size: 0.95rem; }

.tabs { display: flex; gap: 0.3rem; padding: 0.8rem 1.5rem 0; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 0.55rem 0.95rem; border-radius: 10px 10px 0 0; cursor: pointer;
  font-size: 0.85rem; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--panel); border-color: var(--line); border-bottom-color: var(--panel); }

main { padding: 1.2rem 1.5rem 3rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1rem 1.1rem; }
.panel + .panel { margin-top: 1rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem; gap: 1rem; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-head .sub { font-size: 0.78rem; color: var(--muted); }

.toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.search { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 0.45rem 0.7rem; font-size: 0.85rem; min-width: 200px; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.4px; position: sticky; top: 0; background: var(--panel); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tr:hover td { background: rgba(109,139,255,0.05); }

.chip { display: inline-block; background: var(--chip); color: var(--primary); border-radius: 999px; padding: 2px 8px; font-size: 0.72rem; margin: 1px 2px; font-weight: 600; }
.chip.grp-MKK { background: rgba(139,92,246,0.15); color: #b79bff; }
.chip.grp-MKB { background: rgba(53,211,166,0.15); color: var(--accent); }
.chip.grp-MKWK { background: rgba(247,185,85,0.15); color: var(--warn); }
.chip.grp-MKWKT { background: rgba(96,165,250,0.15); color: #7fb4ff; }

.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 9px; padding: 0.45rem 0.8rem; font-size: 0.82rem; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border: none; color: #08122b; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255,107,107,0.4); }
.btn.sm { padding: 0.3rem 0.55rem; font-size: 0.75rem; }
.row-actions { display: flex; gap: 0.35rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0.9rem; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 0.9rem; }
.card h3 { margin: 0 0 0.3rem; font-size: 0.95rem; }
.card .code { font-size: 0.72rem; color: var(--accent); font-weight: 700; }
.card p { font-size: 0.82rem; color: var(--muted); line-height: 1.45; }
.card .tags { margin-top: 0.5rem; }
.card-actions { margin-top: 0.7rem; display: flex; gap: 0.4rem; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 0.7rem; }
.metric { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem; text-align: center; }
.metric .n { font-size: 1.6rem; font-weight: 800; }
.metric .l { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(4,8,20,0.72); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { width: min(720px, 100%); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 1rem; }
.modal-body { padding: 1rem 1.1rem; display: grid; gap: 0.75rem; }
.modal-foot { padding: 0.9rem 1.1rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 0.5rem; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; }
.field { display: grid; gap: 0.3rem; }
.field label { font-size: 0.76rem; color: var(--muted); font-weight: 600; }
.field input, .field textarea, .field select { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 0.5rem 0.65rem; font-size: 0.85rem; font-family: inherit; }
.field textarea { min-height: 76px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 600px) { .field-row { grid-template-columns: 1fr; } }
.hint { font-size: 0.78rem; color: var(--muted); }

.toast { position: fixed; bottom: 1.2rem; right: 1.2rem; background: var(--panel); border: 1px solid var(--accent); color: var(--text); border-radius: 10px; padding: 0.7rem 1rem; font-size: 0.85rem; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
.toast.err { border-color: var(--danger); }

.rps-detail { font-size: 0.85rem; }
.rps-detail h4 { margin: 1rem 0 0.4rem; font-size: 0.85rem; color: var(--primary); }
.muted { color: var(--muted); }
.pill-cpl { background: var(--chip); color: var(--primary); border-radius: 6px; padding: 1px 6px; font-size: 0.72rem; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }

/* ── COMMENTS OBE STYLE ───────────────────────────────────── */
.comment-section { background: var(--panel); border-left: 3px solid var(--primary); padding: 0.5rem 0.8rem; margin: 0.3rem 0; border-radius: 0 8px 8px 0; }
.comment-list { display: grid; gap: 0.35rem; margin-bottom: 0.5rem; }
.comment-item { background: var(--panel-2); border: 1px solid var(--line); padding: 0.4rem 0.6rem; border-radius: 6px; font-size: 0.78rem; }
.comment-item .author { font-weight: 700; color: var(--accent); margin-right: 0.5rem; }
.comment-item .time { font-size: 0.65rem; color: var(--muted); float: right; }
.comment-form { display: flex; gap: 0.5rem; margin-top: 0.4rem; }
.comment-form input { flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 0.35rem 0.5rem; font-size: 0.8rem; }
.comment-form input:focus { border-color: var(--primary); outline: none; }
.comment-indicator { display: inline-block; cursor: pointer; color: var(--accent); font-size: 0.75rem; margin-left: 0.5rem; font-weight: 500; }
.comment-indicator:hover { text-decoration: underline; }

/* ── STICKY MATRIX COLUMNS ───────────────────────────────────── */
.matrix-table th:first-child,
.matrix-table td:first-child,
.matrix-table th:nth-child(2),
.matrix-table td:nth-child(2) {
  position: sticky;
  left: 0;
  background: var(--panel);
  z-index: 2;
}
.matrix-table th:nth-child(2),
.matrix-table td:nth-child(2) {
  left: 70px;
}
.matrix-table th:nth-child(3),
.matrix-table td:nth-child(3) {
  position: sticky;
  left: 168px;
  background: var(--panel);
  z-index: 2;
}
.matrix-table thead th {
  z-index: 3;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f0f2f8;
  --line: #d8dce6;
  --text: #1a1d2e;
  --muted: #5a6080;
  --primary: #4f6ef0;
  --primary-2: #3b5ad0;
  --accent: #1ea97c;
  --danger: #e04040;
  --warn: #c98a20;
  --chip: rgba(79,110,240,0.12);
}
[data-theme="light"] .topbar { background: rgba(255,255,255,0.85); }
[data-theme="light"] th { background: var(--panel); }
[data-theme="light"] .modal-backdrop { background: rgba(0,0,20,0.5); }
