:root {
    color-scheme: dark;
    --bg: #080b12;
    --surface: #0f141f;
    --surface-2: #151b28;
    --surface-3: #1b2332;
    --line: rgba(255, 255, 255, 0.075);
    --line-strong: rgba(255, 255, 255, 0.13);
    --text: #f5f7fb;
    --muted: #8d97aa;
    --muted-2: #667085;
    --accent: #7c5cff;
    --accent-2: #2dd4bf;
    --danger: #ff6577;
    --warning: #fbbf24;
    --success: #35d399;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.login-page {
    min-height: 100vh;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 35%, rgba(124, 92, 255, .12), transparent 32%),
        linear-gradient(145deg, #080b12, #0a1019 60%, #091116);
}
.login-page::before {
    content: ""; position: fixed; inset: 0; opacity: .09; pointer-events: none;
    background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
    background-size: 56px 56px;
    mask-image: radial-gradient(circle at center, black, transparent 72%);
}
.login-shell { min-height: 100vh; width: 100%; padding: 24px; display: grid; place-items: center; position: relative; }
.glass-panel { background: rgba(17, 22, 34, .76); border: 1px solid var(--line-strong); box-shadow: var(--shadow); backdrop-filter: blur(22px); }
.login-card { width: min(100%, 360px); text-align: center; }
.login-card .brand-mark { margin: 0 auto 20px; }
.login-card h1 { margin: 0 0 8px; font-size: 27px; letter-spacing: -.025em; }
.login-card > p { margin: 0 0 25px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.login-privacy { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 17px; color: var(--muted-2); font-size: 9px; line-height: 1.5; }
.login-privacy i { color: #59657a; font-size: 8px; }
.discord-button { display: flex; align-items: center; justify-content: center; gap: 12px; text-decoration: none; color: white; font-weight: 750; padding: 14px 18px; border-radius: 12px; background: linear-gradient(120deg, #5865f2, #765cf6); box-shadow: 0 14px 30px rgba(88, 101, 242, .24); transition: .2s ease; }
.discord-button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.discord-icon { font-size: 24px; }
.button-icon { margin-right: 5px; }
.alert { border-radius: 10px; padding: 12px 14px; margin: 0 0 18px; font-size: 13px; line-height: 1.5; }
.alert--danger { color: #ffc0c8; background: rgba(255,101,119,.1); border: 1px solid rgba(255,101,119,.25); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: #0b0f17; border-right: 1px solid var(--line); padding: 24px 16px 18px; display: flex; flex-direction: column; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; padding: 0 8px 26px; }
.brand > span:last-child { display: flex; flex-direction: column; }
.brand strong { font-size: 15px; }
.brand small { color: var(--muted-2); font-size: 9px; letter-spacing: .16em; margin-top: 2px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; background: linear-gradient(135deg, var(--accent), #4d7cff); font-weight: 900; box-shadow: 0 8px 22px rgba(124,92,255,.3); }
.brand-mark--large { width: 52px; height: 52px; border-radius: 15px; font-size: 22px; }
.sidebar-label { color: #505a6e; font-size: 10px; font-weight: 800; letter-spacing: .14em; padding: 0 10px 10px; }
.guild-list { display: flex; flex-direction: column; gap: 5px; overflow-y: auto; }
.guild-button { border: 1px solid transparent; color: var(--muted); background: transparent; padding: 9px 10px; border-radius: 11px; display: flex; align-items: center; gap: 10px; cursor: pointer; text-align: left; transition: .18s; }
.guild-button:hover { color: var(--text); background: rgba(255,255,255,.035); }
.guild-button.active { color: white; background: rgba(124,92,255,.12); border-color: rgba(124,92,255,.2); }
.mini-avatar, .guild-avatar { object-fit: cover; background: linear-gradient(135deg, #293246, #171d29); display: grid; place-items: center; font-weight: 800; }
.mini-avatar { width: 33px; height: 33px; border-radius: 10px; flex: none; }
.guild-button span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid var(--line); padding: 16px 5px 0; display: flex; align-items: center; gap: 8px; }
.user-card { min-width: 0; flex: 1; display: flex; gap: 9px; align-items: center; }
.user-card img { width: 32px; height: 32px; border-radius: 50%; }
.user-card div { min-width: 0; }
.user-card strong, .user-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card strong { font-size: 12px; }
.user-card small { color: var(--muted); font-size: 10px; margin-top: 2px; text-transform: uppercase; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-button:hover { color: var(--danger); border-color: rgba(255,101,119,.3); }

.main-panel { min-width: 0; }
.topbar { height: 88px; border-bottom: 1px solid var(--line); padding: 0 34px; display: flex; align-items: center; justify-content: space-between; gap: 20px; background: rgba(8,11,18,.82); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 4; }
.guild-heading { display: flex; align-items: center; gap: 13px; min-width: 0; }
.guild-avatar { width: 43px; height: 43px; border-radius: 13px; flex: none; }
.guild-heading h1 { font-size: 17px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guild-heading p { color: var(--muted); font-size: 11px; margin: 4px 0 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-button-group { display: flex; align-items: center; gap: 5px; padding: 4px; background: rgba(255,255,255,.025); border: 1px solid var(--line); border-radius: 13px; }
.topbar-button-group button { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; }
.topbar-button-group .secondary-button { background: transparent; border-color: transparent; box-shadow: none; }
.topbar-button-group .secondary-button:hover { background: var(--surface-2); border-color: var(--line); }
.connection-badge { color: var(--success); background: rgba(53,211,153,.065); border: 1px solid rgba(53,211,153,.15); border-radius: 999px; font-size: 9px; font-weight: 850; letter-spacing: .1em; padding: 8px 11px; white-space: nowrap; }
.connection-badge i { font-size: 6px; margin-right: 5px; filter: drop-shadow(0 0 5px var(--success)); }
.secondary-button, .primary-button, .danger-button { border-radius: 9px; padding: 9px 13px; cursor: pointer; font-weight: 700; font-size: 12px; transition: .18s; }
.secondary-button { color: #bec6d5; background: var(--surface-2); border: 1px solid var(--line); }
.secondary-button:hover { border-color: var(--line-strong); color: white; }
.primary-button { color: white; border: 1px solid rgba(124,92,255,.45); background: linear-gradient(120deg, #704ff5, #5b6ef6); box-shadow: 0 9px 24px rgba(92,77,235,.2); }
.primary-button:hover { transform: translateY(-1px); filter: brightness(1.08); }
.primary-button:disabled, .secondary-button:disabled { opacity: .55; cursor: wait; transform: none; filter: none; }
.danger-button { color: #ff9aa7; border: 1px solid rgba(255,101,119,.25); background: rgba(255,101,119,.07); }
.tabs { height: 54px; display: flex; gap: 3px; padding: 0 34px; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; }
.tabs button { position: relative; border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 650; padding: 0 15px; white-space: nowrap; cursor: pointer; }
.tabs button i { margin-right: 6px; font-size: 11px; }
.tabs button:hover { color: white; }
.tabs button.active { color: white; }
.tabs button.active::after { content: ""; position: absolute; left: 13px; right: 13px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 3px 3px 0 0; box-shadow: 0 0 14px var(--accent); }
.content-area { padding: 30px 34px 60px; max-width: 1500px; margin: auto; }
.loading-state, .empty-state { min-height: 420px; display: grid; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.07); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head h2 { font-size: 22px; margin: 0 0 6px; letter-spacing: -.02em; }
.page-head p { color: var(--muted); margin: 0; font-size: 13px; }
.grid { display: grid; gap: 16px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: 0 8px 34px rgba(0,0,0,.13); }
.stat-card { min-height: 118px; display: flex; flex-direction: column; justify-content: space-between; }
.stat-card small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.stat-card small i { color: #9d90ff; margin-right: 5px; }
.stat-card strong { font-size: 26px; }
.stat-card span { color: var(--muted-2); font-size: 11px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.card-title h3 { font-size: 14px; margin: 0; }
.card-title p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.health-list { display: flex; flex-direction: column; gap: 9px; }
.health-row { border: 1px solid var(--line); background: var(--surface-2); padding: 11px 12px; border-radius: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; }
.health-row > span:first-child { color: #c6ccda; }
.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: 9px; font-weight: 800; letter-spacing: .05em; }
.pill.success { color: #70efbd; background: rgba(53,211,153,.1); }
.pill.danger { color: #ff9caa; background: rgba(255,101,119,.1); }
.pill.warning { color: #ffdb73; background: rgba(251,191,36,.1); }
.pill.neutral { color: #b5bfd0; background: rgba(181,191,208,.08); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field label, .field-label { color: #aab3c3; font-size: 11px; font-weight: 650; }
.field small { color: var(--muted-2); line-height: 1.45; }
.input, .select, .textarea { width: 100%; color: var(--text); background: #0b1019; border: 1px solid var(--line-strong); border-radius: 9px; outline: 0; padding: 10px 11px; transition: .16s; }
.textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { border-color: rgba(124,92,255,.65); box-shadow: 0 0 0 3px rgba(124,92,255,.1); }
.input:disabled, .select:disabled, .textarea:disabled { opacity: .55; cursor: not-allowed; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-section { margin-top: 16px; }
.form-section:first-child { margin-top: 0; }
.form-section > h3 { margin: 0 0 4px; font-size: 14px; }
.form-section > p { color: var(--muted); font-size: 11px; margin: 0 0 13px; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.toggle-row { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.toggle-copy strong { display: block; font-size: 13px; }
.toggle-copy small { display: block; color: var(--muted); margin-top: 4px; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #2a3140; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #7e8798; transition: .2s; }
.switch input:checked + span { background: rgba(124,92,255,.75); }
.switch input:checked + span::before { transform: translateX(18px); background: white; }
.check-list { max-height: 270px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #0b1019; }
.choice-picker { min-width: 0; }
.choice-search { display: grid; grid-template-columns: minmax(120px, 1fr) auto auto auto; gap: 6px; align-items: center; margin-bottom: 7px; }
.choice-search .input { padding: 8px 10px; font-size: 11px; }
.choice-search > span { color: var(--muted); font-size: 9px; white-space: nowrap; padding: 0 3px; }
.choice-search button { color: #a99cff; background: transparent; border: 1px solid var(--line); border-radius: 7px; padding: 7px 8px; font-size: 9px; font-weight: 750; cursor: pointer; }
.choice-search button:hover { color: white; border-color: rgba(124,92,255,.4); background: rgba(124,92,255,.08); }
.grouped-check-list { max-height: 340px; }
.picker-group + .picker-group { border-top: 1px solid var(--line); }
.picker-category { position: sticky; top: 0; z-index: 1; min-height: 34px; display: flex; align-items: center; gap: 7px; padding: 7px 10px; color: #d3d8e3; background: #121824; border-bottom: 1px solid var(--line); font-size: 10px; font-weight: 800; }
.picker-category label { display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer; }
.picker-category input { accent-color: var(--accent); }
.picker-category small { margin-left: auto; color: var(--muted-2); font-size: 8px; font-weight: 650; }
.picker-category--label { cursor: default; color: var(--muted); }
.category-collapse { width: 22px; height: 22px; flex: none; display: grid; place-items: center; color: #9ea8ba; background: transparent; border: 1px solid transparent; border-radius: 6px; cursor: pointer; transition: transform .16s, background .16s; }
.category-collapse:hover { color: white; background: rgba(255,255,255,.055); border-color: var(--line); }
.picker-group.collapsed .category-collapse { transform: rotate(-90deg); }
.picker-group.collapsed .picker-children { display: none; }
.picker-children .check-item { padding-left: 16px; }
.channel-branch { color: #455065; margin-right: 5px; }
.check-item { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-bottom: 1px solid rgba(255,255,255,.04); color: #bac2d0; font-size: 11px; cursor: pointer; }
.check-item:last-child { border-bottom: 0; }
.check-item:hover { background: rgba(255,255,255,.025); }
.check-item input { accent-color: var(--accent); }
.check-item .indent { padding-left: 14px; }
.role-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.channel-tree { display: flex; flex-direction: column; gap: 14px; }
.category-block { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.category-head { color: #8e98aa; background: rgba(255,255,255,.018); padding: 10px 13px; font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; display: flex; justify-content: space-between; }
.channel-row { display: grid; grid-template-columns: minmax(160px, 1fr) repeat(5, 80px); align-items: center; gap: 8px; padding: 10px 13px; border-top: 1px solid var(--line); font-size: 11px; }
.channel-name { min-width: 0; display: flex; align-items: center; gap: 8px; }
.channel-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-type-icon { color: var(--muted-2); width: 15px; text-align: center; }
.permission-cell { text-align: center; color: var(--muted); }
.permission-cell.yes { color: var(--success); }
.permission-cell.no { color: var(--danger); }
.permission-header { color: var(--muted-2); font-size: 9px; }
.role-list { display: flex; flex-direction: column; gap: 7px; }
.role-row { display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; color: #c1c8d5; font-size: 11px; }
.role-row .pill { margin-left: auto; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 11px; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th { color: var(--muted-2); font-weight: 700; text-align: left; background: rgba(255,255,255,.018); }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
td { color: #bac2d1; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: #9fa9ba; font-size: 10px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(2, 4, 9, .78); backdrop-filter: blur(8px); cursor: default; }
.modal-card { position: relative; width: min(620px, 100%); max-height: min(720px, calc(100vh - 40px)); display: flex; flex-direction: column; overflow: hidden; background: #101621; border: 1px solid var(--line-strong); border-radius: 18px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0 0 6px; font-size: 18px; }
.modal-head h2 i { color: #7289da; margin-right: 7px; }
.modal-head p { margin: 0; color: var(--muted); font-size: 11px; }
.install-guild-list { min-height: 180px; padding: 12px; overflow-y: auto; }
.install-loading { min-height: 190px; }
.install-guild-row { display: flex; align-items: center; gap: 12px; padding: 11px; border: 1px solid transparent; border-radius: 12px; }
.install-guild-row + .install-guild-row { margin-top: 4px; }
.install-guild-row:hover { border-color: var(--line); background: rgba(255,255,255,.025); }
.install-guild-copy { min-width: 0; flex: 1; }
.install-guild-copy strong, .install-guild-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.install-guild-copy strong { font-size: 12px; }
.install-guild-copy small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.install-guild-row .primary-button, .install-guild-row .secondary-button { flex: none; }
.install-note { padding: 14px; color: var(--muted); text-align: center; font-size: 11px; line-height: 1.6; }
.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 30; display: flex; flex-direction: column; gap: 9px; }
.toast { min-width: 260px; max-width: 390px; color: #dce1eb; background: #171e2b; border: 1px solid var(--line-strong); box-shadow: var(--shadow); border-radius: 11px; padding: 12px 14px; font-size: 12px; animation: toast-in .22s ease; }
.toast.success { border-left: 3px solid var(--success); }
.toast.danger { border-left: 3px solid var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.mobile-brand { display: none; }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .channel-row { grid-template-columns: minmax(150px, 1fr) repeat(5, 58px); }
}
@media (max-width: 780px) {
    .login-shell { padding: 20px; }
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; width: 100%; height: auto; padding: 14px; border-right: 0; border-bottom: 1px solid var(--line); }
    .brand, .sidebar-label { display: none; }
    .guild-list { flex-direction: row; overflow-x: auto; }
    .guild-button { min-width: 180px; }
    .sidebar-bottom { position: absolute; right: 14px; top: 10px; border: 0; margin: 0; padding: 0; }
    .user-card { display: none; }
    .topbar { top: 62px; height: 76px; padding: 0 17px; }
    .mobile-brand { display: block; }
    .guild-avatar { display: none; }
    .connection-badge { display: none; }
    .topbar-actions { gap: 6px; }
    .topbar-button-group { padding: 0; gap: 5px; background: transparent; border: 0; }
    .topbar-button-group button { width: 36px; min-height: 36px; padding: 0; }
    .topbar-button-group .button-label { display: none; }
    .topbar-button-group .button-icon { margin-right: 0; }
    .tabs { padding: 0 12px; }
    .content-area { padding: 22px 16px 50px; }
    .two-column, .form-grid, .form-grid.two { grid-template-columns: 1fr; }
    .choice-search { grid-template-columns: 1fr auto auto; }
    .choice-search > span { grid-column: 1 / -1; grid-row: 2; }
    .channel-row { grid-template-columns: minmax(145px, 1fr) repeat(2, 52px); }
    .channel-row > :nth-child(4), .channel-row > :nth-child(5), .channel-row > :nth-child(6) { display: none; }
    .modal { padding: 10px; }
    .modal-card { max-height: calc(100vh - 20px); }
    .install-guild-row { align-items: flex-start; flex-wrap: wrap; }
    .install-guild-row .primary-button, .install-guild-row .secondary-button { width: 100%; }
}
