:root {
  --bg: #0b1120;
  --bg-2: #0f172a;
  --panel: #172033;
  --panel-2: #1e293b;
  --line: #2b3852;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --brand: #6366f1;
  --brand-2: #818cf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Assistant", system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 100% -5%, #1b2440, transparent),
    radial-gradient(700px 500px at -5% 0%, #14243a, transparent),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}
h1 { font-size: 1.55rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 16px; color: var(--brand-2); }
h3 { font-size: .95rem; margin: 0; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.hidden { display: none !important; }
.inline { display: inline; }
.err { color: #fecaca; background: #43181c; padding: 9px 13px; border-radius: 9px; margin: 6px 0; }
.ok-msg { color: #bbf7d0; background: #10331f; padding: 9px 13px; border-radius: 9px; margin: 6px 0; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 20px; }

/* ---- Topbar ---- */
.topbar { border-bottom: 1px solid var(--line); background: rgba(11,17,32,.7); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 62px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); font-weight: 800; font-size: 1.15rem; }
.brand:hover { text-decoration: none; }
.brand svg { color: var(--brand-2); }
.topbar nav { display: flex; align-items: center; gap: 12px; }

.crumb { margin: 22px 0 10px; }
.sys-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.toolbar { margin: 22px 0 18px; }
.search input { max-width: 340px; }

/* ---- Cards grid ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-bottom: 28px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px; transition: border-color .15s, transform .15s, box-shadow .15s; }
.card:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sys-name { font-weight: 700; font-size: 1.06rem; color: var(--text); }
.tag { display: inline-block; margin-top: 8px; font-size: .72rem; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); padding: 2px 9px; border-radius: 999px; }
.url { margin-top: 6px; direction: ltr; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; gap: 14px; margin: 12px 0 4px; font-size: .78rem; color: var(--muted); }
.card-meta svg { vertical-align: -2px; }
.empty-state { text-align: center; padding: 40px; grid-column: 1/-1; }

/* ---- Badges ---- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge.ext { background: #2e2a6b; color: #c7d2fe; }
.badge.int { background: #12463a; color: #a7f3d0; }
.badge.edit { background: #3a2f10; color: #fcd888; }
.badge.view { background: #24303f; color: #9fb3cc; }
.badge.lock { background: #3a2417; color: #fcbf9a; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.active { background: var(--ok); box-shadow: 0 0 8px #22c55e88; }
.dot.paused { background: var(--warn); }

/* ---- Links ---- */
.link-row { display: flex; align-items: center; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.link { background: var(--bg-2); border: 1px solid var(--line); color: var(--brand-2); padding: 6px 10px; border-radius: 8px; font-size: .76rem; direction: ltr; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; flex: 1; }
.actions { display: flex; gap: 8px; margin-top: 4px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Buttons ---- */
button, .btn { font-family: inherit; font-size: .9rem; cursor: pointer; border: none; border-radius: 9px; padding: 9px 16px; background: var(--brand); color: #fff; transition: background .15s, opacity .15s, transform .05s; }
button:hover, .btn:hover { background: var(--brand-2); text-decoration: none; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost, button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.ghost:hover, button.ghost:hover { border-color: var(--brand); background: var(--panel-2); }
.mini { padding: 5px 11px; font-size: .77rem; }
.copied { background: var(--ok) !important; color: #04240f !important; }
.btn.danger, button.danger { background: var(--danger); }
.btn.danger:hover { background: #f87171; }
.danger-ghost { background: transparent; border: 1px solid var(--danger); color: #fca5a5; }
.danger-ghost:hover { background: #43181c; }

/* ---- Panels & forms ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.panel-head h2 { margin: 0; }
.danger-zone { border-color: #5b2626; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
.form-grid label.wide, .form-grid > button { grid-column: 1 / -1; }
input, select, textarea { font-family: inherit; font-size: .95rem; background: var(--bg-2); border: 1px solid var(--line); color: var(--text); padding: 10px 12px; border-radius: 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px #6366f133; }
textarea { resize: vertical; direction: ltr; text-align: left; font-family: ui-monospace, monospace; }
.inline-form { display: flex; gap: 10px; align-items: center; }
.code-input { letter-spacing: .4em; text-align: center; font-size: 1.2rem; max-width: 180px; }

/* ---- Tables ---- */
.tbl { width: 100%; border-collapse: collapse; font-size: .86rem; }
.tbl th { text-align: right; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: .78rem; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.off { opacity: .5; }
.link-add, .todo-add { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.link-add input { flex: 1; min-width: 180px; }
.link-add select { max-width: 160px; }

/* ---- Todos ---- */
.todos-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pill { font-size: .74rem; background: var(--panel-2); border: 1px solid var(--line); padding: 2px 10px; border-radius: 999px; color: var(--muted); }
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.todo-list li.empty { color: var(--muted); border: none; }
.todo-list li.done .todo-text { text-decoration: line-through; color: var(--muted); }
.todo-text { flex: 1; }
.check { width: 22px; height: 22px; min-width: 22px; padding: 0; border-radius: 6px; background: var(--bg-2); border: 1px solid var(--line); color: var(--ok); font-size: .8rem; display: inline-flex; align-items: center; justify-content: center; }
.check.on { color: var(--ok); }
.x { background: transparent; color: var(--muted); padding: 2px 6px; }
.x:hover { color: var(--danger); background: transparent; }
.todo-add input { flex: 1; }

/* ---- Auth ---- */
.auth { max-width: 400px; margin: 8vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 34px; text-align: center; box-shadow: var(--shadow); }
.auth .logo { width: 54px; height: 54px; margin: 0 auto 12px; display: grid; place-items: center; background: #6366f122; border: 1px solid var(--brand); border-radius: 14px; color: var(--brand-2); }
.auth form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.auth .code-input { max-width: none; }
.secret-box { display: flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; margin: 8px 0; }
.secret-box code { direction: ltr; word-break: break-all; flex: 1; }

/* ---- Isolated workspace ---- */
body.isolated { background: radial-gradient(900px 500px at 0% -5%, #0f3830, transparent), var(--bg); }
.iso-bar { border-bottom: 1px solid var(--line); background: rgba(11,17,32,.7); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.iso-bar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.iso-title { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.1rem; }
.iso-title svg { color: #34d399; }
.iso-main { padding-top: 22px; padding-bottom: 40px; }
.note-box { background: var(--panel-2); border-inline-start: 3px solid var(--brand); padding: 11px 15px; border-radius: 9px; margin-bottom: 16px; }
.frame-wrap { margin-top: 14px; }
.frame-wrap iframe { width: 100%; height: 62vh; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.ext-actions { margin-bottom: 8px; }
.readonly { background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 14px; white-space: pre-wrap; direction: ltr; text-align: left; }
.iso-foot { text-align: center; margin-top: 18px; }

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar nav .small { display: none; }
}
