@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/inter-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/inter-latin-700-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("../fonts/inter-latin-800-normal.woff2") format("woff2");
}

:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev2: #1c2330;
  --panel: #11161f;
  --border: #2a3441;
  --border-soft: #222b36;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --muted: #6b7785;
  --accent: #3b82f6;
  --accent-hover: #2f6fe0;
  --accent-soft: rgba(59, 130, 246, 0.15);
  /* Soft grey gradient for icon tiles that have no defined color of their own */
  --icon-tile: linear-gradient(145deg, #5a6675 0%, #48515f 55%, #3a4250 100%);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --ok: #22c55e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--bg-elev), var(--panel));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}
.brand-text { display: flex; flex-direction: column; justify-content: center; gap: 1px; }
.brand-text h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: .2px; line-height: 1.15; }
.brand-text .path {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.1;
  color: var(--muted);
  max-width: 360px;
  display: inline-block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: bottom;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: #fca5a5; border-color: rgba(239,68,68,.3); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  display: grid; place-items: center;
  transition: all .12s ease;
}
.icon-btn:hover { background: var(--bg-elev2); color: var(--text); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 290px 1fr;
  height: calc(100vh - 59px);
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-section { padding: 14px 14px 10px; border-bottom: 1px solid var(--border-soft); }
.sidebar-section.grow { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); font-weight: 700; margin-bottom: 8px;
}
.hint { margin: 0 0 10px; font-size: 12px; color: var(--muted); }

.palette { display: flex; flex-direction: column; gap: 8px; }
.palette-block {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: grab;
  transition: all .12s ease;
}
.palette-block:hover { border-color: var(--accent); background: var(--bg-elev2); transform: translateY(-1px); }
.palette-block:active { cursor: grabbing; }
.palette-block .pb-icon { font-size: 18px; }
.palette-block strong { display: block; font-size: 13px; }
.palette-block small { color: var(--muted); font-size: 11px; }

.filter {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  margin-bottom: 10px;
}
.filter:focus { outline: none; border-color: var(--accent); }

.section-nav { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.section-nav li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
}
.section-nav li:hover { background: var(--bg-elev); color: var(--text); }
.section-nav li .nav-handle { cursor: grab; color: var(--muted); font-size: 13px; }
.section-nav li .nav-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-nav li .nav-count { color: var(--muted); font-size: 11px; }
.section-nav li.dim { display: none; }

.sidebar-foot {
  padding: 10px 14px; border-top: 1px solid var(--border-soft); font-size: 11px;
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-btn { width: 100%; }
.app-credit { font-size: 10px; color: var(--muted); line-height: 1.4; }
.app-credit a { color: var(--text-dim); text-decoration: none; }
.app-credit a:hover { color: var(--accent); text-decoration: underline; }
.linklike {
  background: none; border: none; padding: 0; cursor: pointer;
  font: inherit; color: var(--text-dim); text-decoration: none;
}
.linklike:hover { color: var(--accent); text-decoration: underline; }

/* Changelog modal content */
.changelog { font-size: 13px; line-height: 1.6; color: var(--text); }
.changelog h1 { font-size: 18px; margin: 0 0 12px; }
.changelog h2 {
  font-size: 15px; margin: 20px 0 8px; padding-bottom: 5px;
  border-bottom: 1px solid var(--border-soft); color: var(--text);
}
.changelog h3 { font-size: 13px; margin: 14px 0 6px; color: var(--accent); text-transform: uppercase; letter-spacing: .4px; }
.changelog ul { margin: 6px 0; padding-left: 20px; }
.changelog li { margin: 3px 0; color: var(--text-dim); }
.changelog p { margin: 6px 0; color: var(--text-dim); }
.changelog a { color: var(--accent); text-decoration: none; }
.changelog a:hover { text-decoration: underline; }
.changelog code {
  font-family: var(--mono); font-size: 12px;
  background: var(--bg); border: 1px solid var(--border-soft);
  padding: 1px 5px; border-radius: 4px; color: var(--text);
}

/* ---------- Canvas ---------- */
.canvas { overflow-y: auto; padding: 22px; }
.groups {
  column-gap: 18px;
  column-width: 360px;
}
.group {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 18px;
  break-inside: avoid;
  overflow: hidden;
  display: inline-block;
  width: 100%;
}
.group.drag-ghost { opacity: .4; }
.group-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--bg-elev2);
  border-bottom: 1px solid var(--border);
}
.group-drag { cursor: grab; }
.drag-handle { color: var(--muted); cursor: grab; user-select: none; font-size: 14px; }
.drag-handle:active { cursor: grabbing; }
.group-name {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 6px;
}
.group-name:hover { border-color: var(--border); }
.group-name:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.count-pill {
  font-size: 11px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 999px;
  white-space: nowrap; flex-shrink: 0;
}
.group-actions { display: flex; gap: 2px; }

.service-list { padding: 8px; min-height: 14px; display: flex; flex-direction: column; gap: 6px; }
.service-list.drag-over { background: var(--accent-soft); border-radius: 8px; }

.service-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  transition: border-color .12s ease, transform .05s ease;
}
.service-card:hover { border-color: var(--border); }
.service-card.sortable-ghost { opacity: .35; }
.service-card.sortable-chosen { border-color: var(--accent); }
.svc-icon, .icon-preview-btn { position: relative; }
.svc-icon {
  width: 30px; height: 30px; flex: 0 0 30px;
  display: grid; place-items: center;
  background: var(--icon-tile);
  border-radius: 7px; overflow: hidden;
}
.svc-icon img { width: 24px; height: 24px; object-fit: contain; }
.svc-icon img[src=""], .svc-icon img:not([src]) { display: none; }
.icon-fallback { color: var(--muted); font-weight: 700; font-size: 13px; }
.svc-main { flex: 1; min-width: 0; }
.svc-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-sub {
  font-size: 11px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.svc-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s ease; }
.service-card:hover .svc-actions { opacity: 1; }

.empty-state { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-state p { font-size: 16px; margin-bottom: 16px; }

/* ---------- Drawer ---------- */
.drawer-overlay, .modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 50;
  display: flex;
}
.drawer-overlay { justify-content: flex-end; }
.drawer {
  width: 440px; max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head, .modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.drawer-head h2, .modal-head h2 { margin: 0; font-size: 15px; }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.drawer-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 18px; border-top: 1px solid var(--border);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.field input[type="text"], .field input[type="password"], .advanced textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
}
.field input:focus, .advanced textarea:focus { outline: none; border-color: var(--accent); }

.icon-field { display: flex; align-items: center; gap: 8px; }
.icon-field input { flex: 1; }
.icon-preview-btn {
  width: 42px; height: 42px; flex: 0 0 42px;
  display: grid; place-items: center;
  background: var(--icon-tile);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.icon-preview-btn:hover { border-color: var(--accent); }
.icon-preview-btn img { width: 28px; height: 28px; object-fit: contain; }
.icon-preview-btn img[src=""], .icon-preview-btn img:not([src]) { display: none; }

.icon-color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.color-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
.color-toggle input { width: 15px; height: 15px; accent-color: var(--accent); }
.icon-color-row input[type="color"] {
  width: 38px; height: 30px; padding: 0;
  border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer;
}
.icon-color-row input[type="color"]:disabled { opacity: .4; cursor: not-allowed; }
.color-val { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.color-hint { font-size: 12px; color: var(--muted); }
.icon-color-field.unsupported .color-toggle { opacity: .5; }

.advanced { border-top: 1px solid var(--border-soft); padding-top: 12px; }
.advanced summary { cursor: pointer; font-size: 12px; color: var(--text-dim); font-weight: 600; }
.advanced textarea { font-family: var(--mono); font-size: 12px; margin-top: 8px; resize: vertical; }
.adv-error { color: #fca5a5; font-size: 12px; margin-top: 6px; min-height: 14px; }

/* ---------- Modal ---------- */
.modal {
  margin: auto;
  width: 720px; max-width: 94vw; max-height: 88vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: pop .16s ease;
}
@keyframes pop { from { transform: scale(.97); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-body { padding: 18px; overflow: auto; }
.modal-body pre {
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px; margin: 0;
  white-space: pre; overflow: auto;
}

/* ---------- Icon chooser ---------- */
.icon-modal { width: 760px; height: 80vh; }
.icon-tabs { display: flex; gap: 4px; padding: 10px 16px 0; border-bottom: 1px solid var(--border); }
.icon-tabs .tab {
  background: transparent; border: none; color: var(--text-dim);
  padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.icon-tabs .tab:hover { color: var(--text); }
.icon-tabs .tab.active { color: var(--text); border-bottom-color: var(--accent); }
.icon-controls { display: flex; align-items: center; gap: 12px; padding: 14px 16px 8px; }
.icon-controls .filter { margin: 0; flex: 1; }
.mdi-color { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.mdi-color input[type="color"] { width: 32px; height: 30px; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; }
.ext-link { color: var(--accent); font-size: 12px; text-decoration: none; white-space: nowrap; }
.ext-link:hover { text-decoration: underline; }
.upload-controls { display: flex; align-items: center; gap: 8px; }
.icon-results.dropzone {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
  background: var(--accent-soft);
}
.icon-cell .cell-del {
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; line-height: 16px;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--bg); color: #fca5a5;
  font-size: 11px; text-align: center; cursor: pointer;
  opacity: 0; transition: opacity .12s ease; padding: 0;
}
.icon-cell:hover .cell-del { opacity: 1; }
.icon-cell .cell-del:hover { background: var(--danger-soft); border-color: var(--danger); }

.icon-results {
  flex: 1; overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 8px;
  padding: 12px 16px;
  align-content: start;
}
.icon-cell {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--icon-tile);
  transition: all .12s ease;
  min-height: 78px;
}
.icon-cell:hover { border-color: var(--accent); background: var(--bg-elev2); transform: translateY(-1px); }
.icon-cell img { width: 30px; height: 30px; object-fit: contain; }
.icon-cell { position: relative; }
.icon-cell .cell-label {
  font-size: 10px; color: var(--muted); text-align: center;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-cell .cell-badge {
  position: absolute; top: 4px; right: 4px;
  font-size: 8px; font-weight: 700; letter-spacing: .3px;
  padding: 1px 4px; border-radius: 4px;
  background: var(--bg); color: var(--text-dim); border: 1px solid var(--border);
}
.cell-badge.b-dash { color: #93c5fd; border-color: #2b4a6b; }
.cell-badge.b-mdi { color: #a5d8ff; border-color: #2b5278; }
.cell-badge.b-fa { color: #fcd34d; border-color: #6b5a1e; }
.cell-badge.b-si { color: #d8b4fe; border-color: #4a2b6b; }
.cell-badge.b-svg { color: #86efac; border-color: #1e5a3a; }
.icon-status { padding: 8px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border-soft); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 90; display: flex; flex-direction: column; gap: 10px; }
.toast {
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--bg-elev2); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 13px; min-width: 200px;
  animation: toastIn .2s ease;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.backup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.backup-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); font-size: 13px;
}
.backup-list .bk-name { font-family: var(--mono); flex: 1; }
.backup-list .bk-meta { color: var(--muted); font-size: 11px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ---------- Login ---------- */
.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(59, 130, 246, 0.16), transparent 70%),
    var(--bg);
}
.login-wrap { width: 100%; max-width: 380px; }
.login-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 30px 28px 22px;
  background: linear-gradient(180deg, var(--bg-elev), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
}
.login-mark { width: 44px; height: 44px; border-radius: 10px; align-self: center; }
.login-card h1 { margin: 0; font-size: 19px; text-align: center; }
.login-sub { margin: -8px 0 4px; font-size: 13px; color: var(--muted); text-align: center; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.flash {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--bg-elev2);
}
.flash--error { background: var(--danger-soft); border-color: rgba(239, 68, 68, 0.35); color: #fca5a5; }
.flash--success { background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .35); color: #86efac; }
.form-error { margin: 0; font-size: 13px; color: #fca5a5; }
.login-remember { font-size: 13px; color: var(--text-dim); }
.login-submit { width: 100%; padding: 10px 14px; font-size: 14px; }
.login-credit { margin-top: 4px; text-align: center; }
.logout-form { margin: 0; display: flex; }
.btn-block { width: 100%; }

/* Turnstile widget — centred, and never wider than the card. */
.cf-turnstile { display: flex; justify-content: center; min-height: 65px; }
.cf-turnstile iframe { max-width: 100%; }

/* ---------- First-run wizard ---------- */
.wizard { gap: 12px; }
.wiz-dots { display: flex; justify-content: center; gap: 6px; margin: 2px 0 6px; }
.wiz-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border); transition: background .2s ease; }
.wiz-dot.is-active { background: var(--accent); }
.wiz-step { display: none; flex-direction: column; gap: 14px; }
.wiz-step.is-active { display: flex; }
.wiz-title { margin: 0; font-size: 16px; }
.wiz-text { margin: -6px 0 0; font-size: 13px; line-height: 1.55; color: var(--text-dim); }
.wiz-text code, .wiz-list code { font-family: var(--mono); font-size: 12px; }
.wiz-list { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.9; color: var(--text-dim); }
.wiz-path {
  margin: -4px 0 0; padding: 9px 11px;
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.wiz-path code { font-family: var(--mono); font-size: 11px; word-break: break-all; color: var(--text-dim); }
.wiz-nav { display: flex; gap: 10px; margin-top: 2px; }
.wiz-nav .btn { flex: 1; }
.wizard .hint { margin: 0; }
