:root {
  --bg: #090b10;
  --bg-soft: #0d1017;
  --panel: #11151d;
  --panel-2: #151a24;
  --panel-3: #1a202c;
  --border: rgba(255,255,255,.075);
  --border-strong: rgba(255,255,255,.12);
  --text: #f7f8fb;
  --muted: #9098a7;
  --muted-2: #697180;
  --accent: #78a9ff;
  --accent-strong: #4d8eff;
  --accent-soft: rgba(77,142,255,.14);
  --danger: #ff6b79;
  --danger-soft: rgba(255,107,121,.12);
  --success: #65d6a4;
  --shadow: 0 28px 70px rgba(0,0,0,.32);
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 78% -10%, rgba(59,112,220,.10), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}
button, input, textarea { font: inherit; }
button { color: inherit; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 24px 18px 18px;
  display: flex;
  flex-direction: column;
  background: rgba(10,13,19,.94);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px);
  z-index: 20;
}

.brand { display:flex; align-items:center; gap:12px; padding: 2px 8px 24px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  display:grid; place-items:center; overflow:hidden; flex-shrink:0;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(69,127,241,.10);
}
.brand-mark img { width:100%; height:100%; object-fit:cover; display:block; }
.brand-name { font-size: 15px; font-weight: 750; letter-spacing: .01em; }
.brand-subtitle { color: var(--muted-2); font-size: 12px; margin-top: 2px; }

.nav { display:flex; flex-direction:column; gap:6px; }
.nav-item {
  width:100%; border:0; border-radius: 11px; background:transparent;
  padding:10px 12px; display:flex; gap:11px; align-items:center;
  color: var(--muted); cursor:pointer; text-align:left;
  transition: .18s ease;
}
.nav-item:hover { background: rgba(255,255,255,.04); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #bdd3ff; }
.nav-icon { width: 19px; font-size: 16px; text-align:center; }
.sidebar-spacer { flex:1; }
.sync-card {
  margin: 0 4px 12px; padding: 12px;
  border:1px solid var(--border); border-radius: 12px;
  background: rgba(255,255,255,.025); display:flex; align-items:center; gap:10px;
}
.sync-card strong { display:block; font-size:12px; }
.sync-card span { color:var(--muted-2); font-size:10px; display:block; margin-top:2px; }
.sync-dot { width:8px; height:8px; border-radius:50%; background:var(--success); box-shadow:0 0 14px rgba(101,214,164,.55); }
.sync-dot.offline { background:#727989; box-shadow:none; }
.sync-dot.error { background:var(--danger); box-shadow:0 0 14px rgba(255,107,121,.42); }
.logout { color: #8c93a0; }

.main { margin-left: 248px; min-height: 100vh; padding: 0 42px 70px; }
.topbar {
  width:100%;
  max-width:1160px;
  min-height:0;
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  gap:24px;
  margin:0 auto 22px;
  padding:28px 4px 10px;
  position:relative;
  top:auto;
  z-index:10;
  border:0;
  background:transparent;
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
}
.topbar::after { display:none; }
.topbar h1 {
  margin:5px 0 0;
  font-size:30px;
  line-height:1.05;
  font-weight:780;
  letter-spacing:-.045em;
}
.topbar > div:first-child { min-width:0; }
.topbar .eyebrow { color:#7599dc; }
.top-actions {
  display:flex;
  align-items:center;
  gap:12px;
  margin-left:auto;
  padding-bottom:1px;
}
.save-state {
  font-size:11px;
  color:var(--muted-2);
  white-space:nowrap;
}
.topbar .primary {
  min-width:116px;
  padding:9px 14px;
  border:1px solid rgba(120,169,255,.28);
  border-radius:10px;
  background:linear-gradient(180deg, #8bb7ff, #669cff);
  color:#08111f;
  box-shadow:0 8px 24px rgba(64,118,220,.18);
}
.topbar .primary:hover:not(:disabled) {
  transform:translateY(-1px);
  background:linear-gradient(180deg, #a4c7ff, #78a9ff);
}
.topbar .primary:disabled {
  opacity:1;
  cursor:not-allowed;
  color:#666f7e;
  background:rgba(255,255,255,.045);
  border-color:rgba(255,255,255,.07);
  box-shadow:none;
}
.eyebrow { color: #7599dc; font-size: 10px; font-weight:800; letter-spacing:.16em; }

.primary, .secondary, .danger-button {
  border:1px solid transparent; border-radius: 10px; cursor:pointer;
  padding: 10px 15px; font-weight:700; font-size:12px; transition:.18s ease;
}
.primary { background: #e8efff; color:#101827; box-shadow: 0 8px 22px rgba(104,145,227,.12); }
.primary:hover:not(:disabled) { transform: translateY(-1px); background:#fff; }
.primary:disabled { opacity:.36; cursor:not-allowed; }
.secondary { background: rgba(255,255,255,.045); border-color:var(--border-strong); color:#d9deea; }
.secondary:hover { background:rgba(255,255,255,.075); }
.secondary.compact { padding:8px 11px; }
.danger-button { background:var(--danger-soft); border-color:rgba(255,107,121,.18); color:#ff9aa4; padding:8px 11px; }
.danger-button:hover { background:rgba(255,107,121,.18); }
.wide { width:100%; padding:12px 16px; }

.view { max-width: 1160px; margin: 0 auto; }
.hidden { display:none !important; }
.hero-card {
  padding: 26px 28px; border:1px solid rgba(100,149,244,.14); border-radius:var(--radius);
  background: linear-gradient(135deg, rgba(50,90,168,.13), rgba(17,21,29,.86) 62%);
  display:flex; align-items:flex-start; justify-content:flex-start; gap:24px; margin-bottom: 18px;
}
.hero-card h2, .section-heading h2, .settings-panel h2 { margin:5px 0 6px; font-size:22px; letter-spacing:-.03em; }
.hero-card p, .section-heading p, .panel-head p { margin:0; color:var(--muted); line-height:1.55; max-width:720px; }

.panel, .category-card, .loading-card {
  border:1px solid var(--border); border-radius:var(--radius); background:rgba(17,21,29,.86); box-shadow: var(--shadow);
}
.panel { padding:22px; }
.panel-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:20px; }
.panel-head h3 { margin:0 0 5px; font-size:15px; }

.structured-editor { display:flex; flex-direction:column; gap:10px; }
.context-block {
  width:100%; resize:vertical; min-height: 68px; padding:13px 14px;
  background:#0c1017; border:1px solid var(--border); color:#cbd1dc; border-radius:11px;
  line-height:1.55; outline:none; transition:.16s ease;
}
.context-block:focus, .rule-input:focus, .field input:focus, .field textarea:focus { border-color:rgba(100,151,255,.55); box-shadow:0 0 0 3px rgba(76,132,241,.10); }
.rule-group {
  border:1px solid var(--border); border-radius:14px; background:#0d1118; padding: 10px;
}
.rule-group-head { display:flex; justify-content:space-between; align-items:center; padding:2px 4px 10px; color:var(--muted-2); font-size:10px; font-weight:800; letter-spacing:.1em; }
.rule-row { display:grid; grid-template-columns: 34px 1fr auto; align-items:start; gap:9px; padding:7px; border-radius:10px; }
.rule-row + .rule-row { border-top:1px solid rgba(255,255,255,.035); }
.rule-number {
  width:30px; height:30px; border-radius:8px; display:grid; place-items:center;
  background:var(--accent-soft); color:#8eb7ff; font-weight:800; font-size:11px;
}
.rule-input {
  width:100%; resize:vertical; min-height:45px; padding:7px 9px; line-height:1.48;
  background:transparent; color:#e6e9ef; border:1px solid transparent; border-radius:8px; outline:none;
}
.row-actions { display:flex; gap:5px; padding-top:1px; }
.icon-button {
  width:30px; height:30px; display:grid; place-items:center; border-radius:8px;
  border:1px solid var(--border); background:#141923; color:#8f97a5; cursor:pointer;
}
.icon-button:hover { color:#fff; background:#1b2230; }
.icon-button.danger:hover { color:#ff8f9a; background:var(--danger-soft); border-color:rgba(255,107,121,.18); }
.empty-rules { padding:20px; text-align:center; color:var(--muted-2); font-size:12px; }

.section-heading { display:flex; justify-content:space-between; align-items:end; margin:34px 2px 14px; }
.category-list { display:flex; flex-direction:column; gap:15px; }
.category-card { padding:20px; }
.category-top { display:flex; align-items:center; justify-content:space-between; gap:20px; padding-bottom:16px; border-bottom:1px solid var(--border); }
.category-title-wrap { display:flex; align-items:center; gap:12px; }
.category-emoji-preview { width:38px; height:38px; border-radius:11px; display:grid; place-items:center; background:var(--panel-3); border:1px solid var(--border); font-size:17px; overflow:hidden; }
.category-title { margin:0; font-size:15px; }
.category-key { margin:3px 0 0; color:var(--muted-2); font-size:10px; font-family:ui-monospace, SFMono-Regular, Menlo, monospace; }
.category-actions { display:flex; gap:8px; }
.category-meta { display:grid; grid-template-columns: 1.2fr 1.7fr .55fr 1fr; gap:10px; margin:16px 0; }

.field { display:flex; flex-direction:column; gap:7px; }
.field > span { color:#929aa8; font-size:10px; font-weight:700; letter-spacing:.04em; }
.field input, .field textarea {
  width:100%; border:1px solid var(--border); border-radius:10px; background:#0d1118;
  color:#e5e8ee; padding:10px 11px; outline:none; resize:vertical; line-height:1.5;
}
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.span-2 { grid-column: span 2; }
.settings-panel { max-width: 920px; }

.loading-card { max-width:480px; margin:100px auto; padding:36px; display:grid; place-items:center; color:var(--muted); }
.spinner { width:28px; height:28px; border:3px solid rgba(255,255,255,.08); border-top-color:#84adf8; border-radius:50%; animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

.toast-host { position:fixed; top:18px; right:18px; z-index:1000; display:flex; flex-direction:column; gap:9px; }
.toast { min-width:260px; max-width:420px; padding:12px 14px; border-radius:11px; border:1px solid var(--border); background:#171c26; box-shadow:var(--shadow); animation:toastIn .2s ease; }
.toast.success { border-color:rgba(101,214,164,.22); }
.toast.error { border-color:rgba(255,107,121,.22); }
.toast strong { font-size:12px; display:block; margin-bottom:2px; }
.toast span { color:var(--muted); font-size:11px; }
@keyframes toastIn { from { transform:translateY(-8px); opacity:0; } }

/* Login */
.login-page { display:grid; place-items:center; overflow:hidden; background:#080a0f; }
.ambient { position:fixed; border-radius:50%; filter:blur(90px); opacity:.22; pointer-events:none; }
.ambient-one { width:500px; height:500px; background:#315fae; top:-260px; right:-130px; }
.ambient-two { width:420px; height:420px; background:#233e70; bottom:-250px; left:-170px; }
.login-shell { width:100%; padding:28px; position:relative; z-index:1; }
.login-card {
  width:min(430px, 100%); margin:0 auto; padding:30px;
  border:1px solid var(--border-strong); border-radius:22px; background:rgba(17,21,29,.84);
  box-shadow:0 35px 90px rgba(0,0,0,.48); backdrop-filter:blur(18px);
}
.brand-login { padding:0 0 34px; }
.login-copy h1 { margin:7px 0 7px; font-size:30px; letter-spacing:-.04em; }
.login-copy p { margin:0 0 24px; color:var(--muted); line-height:1.55; }
.login-form { display:flex; flex-direction:column; gap:14px; }
.login-form label { display:flex; flex-direction:column; gap:7px; color:#a1a8b4; font-size:11px; font-weight:700; }
.login-form input { width:100%; border:1px solid var(--border); border-radius:10px; background:#0b0f16; color:#fff; padding:12px; outline:none; }
.login-form input:focus { border-color:rgba(100,151,255,.55); box-shadow:0 0 0 3px rgba(76,132,241,.10); }
.login-footer { margin:20px 0 0; text-align:center; color:var(--muted-2); font-size:10px; }
.alert.error { margin-bottom:16px; padding:10px 12px; border-radius:9px; background:var(--danger-soft); border:1px solid rgba(255,107,121,.16); color:#ff9aa4; font-size:11px; }

@media (max-width: 980px) {
  .sidebar { width:78px; padding:20px 12px; }
  .brand > div:not(.brand-mark), .nav-item span:not(.nav-icon), .sync-card > div:not(.sync-dot) { display:none; }
  .brand { justify-content:center; padding-inline:0; }
  .nav-item { justify-content:center; padding-inline:0; }
  .sync-card { justify-content:center; padding:12px 0; }
  .main { margin-left:78px; padding-inline:22px; }
  .category-meta { grid-template-columns:1fr 1fr; }
}

@media (max-width: 720px) {
  .sidebar { position:static; width:100%; height:auto; flex-direction:row; align-items:center; padding:10px 14px; border-right:0; border-bottom:1px solid var(--border); }
  .brand { padding:0; margin-right:8px; }
  .brand-mark { width:34px; height:34px; }
  .nav { flex-direction:row; }
  .sidebar-spacer, .sync-card { display:none; }
  .sidebar form { margin-left:auto; }
  .main { margin-left:0; padding:0 14px 50px; }
  .topbar { min-height:76px; padding:12px 0; margin-bottom:22px; }
  .topbar .save-state { display:none; }
  .hero-card, .section-heading, .category-top { align-items:flex-start; flex-direction:column; }
  .category-meta, .form-grid { grid-template-columns:1fr; }
  .span-2 { grid-column:span 1; }
  .rule-row { grid-template-columns:30px 1fr; }
  .row-actions { grid-column:2; }
}

/* Account / sub-user management */
.nav-link { text-decoration:none; }
.account-card {
  margin: 0 4px 10px; padding: 10px 11px; display:flex; align-items:center; gap:9px;
  border:1px solid var(--border); border-radius:12px; background:rgba(255,255,255,.02);
}
.account-avatar, .user-avatar {
  display:grid; place-items:center; flex-shrink:0; font-weight:800; color:#bdd3ff;
  background:var(--accent-soft); border:1px solid rgba(100,149,244,.15);
}
.account-avatar { width:29px; height:29px; border-radius:9px; font-size:11px; }
.account-card strong { display:block; font-size:11px; max-width:135px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.account-card span { display:block; margin-top:2px; color:var(--muted-2); font-size:9px; }
.read-only-badge { padding:7px 10px; border:1px solid var(--border); border-radius:9px; background:rgba(255,255,255,.03); color:var(--muted); font-size:11px; font-weight:700; }
.viewer-mode .secondary, .viewer-mode .danger-button, .viewer-mode .row-actions { display:none !important; }
.viewer-mode input, .viewer-mode textarea { cursor:default; }

.users-view { padding-bottom:40px; }
.users-hero { margin-bottom:18px; }
.create-user-panel { margin-bottom:30px; }
.user-create-form { display:grid; grid-template-columns:1fr 1.25fr 1.15fr auto; gap:12px; align-items:end; }
.field select {
  width:100%; min-height:40px; border:1px solid var(--border); border-radius:10px; background:#0d1118;
  color:#e5e8ee; padding:10px 11px; outline:none;
}
.field select:focus { border-color:rgba(100,151,255,.55); box-shadow:0 0 0 3px rgba(76,132,241,.10); }
.field em { font-style:normal; color:var(--muted-2); font-weight:500; }
.create-user-button { min-height:40px; white-space:nowrap; }
.users-heading { margin-top:28px; }
.user-list { display:flex; flex-direction:column; gap:12px; }
.user-card { position:relative; padding:18px 20px; border:1px solid var(--border); border-radius:var(--radius); background:rgba(17,21,29,.86); box-shadow:var(--shadow); }
.user-card-head { display:flex; align-items:center; justify-content:space-between; gap:14px; margin-bottom:16px; }
.user-identity { display:flex; align-items:center; gap:11px; }
.user-avatar { width:38px; height:38px; border-radius:11px; font-size:13px; }
.user-identity h3 { margin:0; font-size:14px; }
.user-identity p { margin:3px 0 0; color:var(--muted-2); font-size:10px; }
.role-badge { padding:6px 9px; border-radius:999px; font-size:9px; font-weight:800; text-transform:uppercase; letter-spacing:.08em; border:1px solid var(--border); }
.role-badge.editor { color:#9fc0ff; background:rgba(77,142,255,.10); border-color:rgba(77,142,255,.16); }
.role-badge.viewer { color:#aab1be; background:rgba(255,255,255,.035); }
.user-edit-form { display:grid; grid-template-columns:.8fr 1.6fr auto; gap:11px; align-items:end; padding-right:125px; }
.delete-user-form { position:absolute; right:20px; bottom:18px; }
.empty-users { display:flex; flex-direction:column; gap:5px; color:var(--muted); }
.empty-users strong { color:var(--text); font-size:13px; }
.empty-users span { font-size:11px; }
.link-button { display:block; text-align:center; text-decoration:none; }
.result-card { text-align:left; }

@media (max-width: 1100px) {
  .user-create-form { grid-template-columns:1fr 1fr; }
  .create-user-button { width:max-content; }
  .user-edit-form { grid-template-columns:1fr 1fr; padding-right:0; padding-bottom:52px; }
  .delete-user-form { left:20px; right:auto; bottom:18px; }
}
@media (max-width: 980px) {
  .account-card > div:not(.account-avatar) { display:none; }
  .account-card { justify-content:center; padding:10px 0; }
}
@media (max-width: 720px) {
  .account-card { display:none; }
  .user-create-form, .user-edit-form { grid-template-columns:1fr; }
  .user-edit-form { padding-bottom:52px; }
}
