:root {
    --bg-primary: #1e1f22;
    --bg-secondary: #2b2d31;
    --bg-tertiary: #313338;
    --bg-card: #2b2d31;
    --bg-card-hover: #35373c;
    --bg-input: #1e1f22;

    --text-primary: #f2f3f5;
    --text-secondary: #b5bac1;
    --text-muted: #949ba4;

    --accent: #5865f2;
    --accent-hover: #4752c4;
    --discord-green: #57f287;
    --discord-red: #ed4245;
    --discord-yellow: #fee75c;

    --border: #3f4147;
    --radius: 8px;
    --radius-sm: 4px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* Navbar */
.navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.nav-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link {
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.nav-user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.nav-logout {
    color: var(--text-muted);
    background: none;
    border: none;
    font: inherit;
    cursor: pointer;
}

/* Container */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Page header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.page-desc {
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Breadcrumb */
.breadcrumb {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.breadcrumb a {
    color: var(--text-muted);
}
.breadcrumb a:hover {
    color: var(--text-primary);
}

.breadcrumb-sep {
    margin: 0 0.35rem;
    opacity: 0.5;
}

/* Guild grid */
.guild-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.guild-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: background 0.15s, border-color 0.15s;
    color: var(--text-primary);
}
.guild-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    text-decoration: none;
}

.guild-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
}

.guild-icon-placeholder {
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.guild-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.guild-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.guild-members {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Cog grid */
.cog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.cog-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: background 0.15s, border-color 0.15s;
    color: var(--text-primary);
}
.cog-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    text-decoration: none;
}

.cog-name {
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 0.35rem;
}

.cog-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Settings form */
.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.field-group {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.field-group.field-error {
    border-color: var(--discord-red);
}

.field-label {
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.field-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.field-input {
    margin-top: 0.5rem;
}

.field-error-msg {
    color: var(--discord-red);
    font-size: 0.8rem;
    margin-top: 0.35rem;
}

.field-hint {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.25rem;
    display: block;
}

/* Setting locks */
.field-locked {
    border-color: var(--discord-yellow);
    border-style: dashed;
}

.badge-locked {
    background: var(--discord-yellow);
    color: #1e1f22;
}

.lock-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    margin-bottom: 0.25rem;
}

.lock-toggle input:checked + .lock-icon {
    color: var(--discord-yellow);
    font-weight: 600;
}

.field-input-locked {
    opacity: 0.5;
    border: none;
    padding: 0;
    margin: 0;
    min-inline-size: 0;
}

/* Inputs */
.input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    width: 100%;
    max-width: 400px;
    transition: border-color 0.15s;
}
.input:focus {
    outline: none;
    border-color: var(--accent);
}

.textarea {
    min-height: 80px;
    resize: vertical;
    font-family: inherit;
}

.textarea.keyed-dict {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 0.85rem;
    white-space: pre;
    overflow-x: auto;
}

.select {
    cursor: pointer;
}

select[multiple].input {
    min-height: 120px;
}

/* Toggle */
.toggle {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    position: relative;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    width: 44px;
    height: 24px;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    transition: background 0.2s;
}

.toggle-slider::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
}

.toggle input:focus-visible + .toggle-slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.toggle input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}
.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-discord {
    background: var(--accent);
    color: white;
    font-size: 1rem;
    padding: 0.75rem 1.5rem;
}
.btn-discord:hover {
    background: var(--accent-hover);
    text-decoration: none;
}

.form-actions {
    padding-top: 0.5rem;
}

/* Badge */
.badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-owner {
    background: var(--discord-yellow);
    color: #1e1f22;
}

/* Toast */
.toast {
    position: fixed;
    top: 72px;
    right: 1.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 200;
    transition: opacity 0.3s;
}

.toast-success {
    background: var(--discord-green);
    color: #1e1f22;
}

.toast-error {
    background: var(--discord-red);
    color: white;
}

.toast-fade {
    opacity: 0;
}

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

/* Login page */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    max-width: 400px;
    width: 100%;
}

.login-card h1 {
    margin-bottom: 0.5rem;
}

.login-desc {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* --- Utility classes (replaces all inline style= attributes) --- */

/* Display */
.d-none { display: none; }
.d-inline { display: inline; }
.d-flex { display: flex; }
.d-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 0; }
.flex-noshrink { flex-shrink: 0; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: end; }
.gap-025 { gap: 0.25rem; }
.gap-035 { gap: 0.35rem; }
.gap-05 { gap: 0.5rem; }
.gap-075 { gap: 0.75rem; }
.gap-1 { gap: 1rem; }
.ml-auto { margin-left: auto; }
.ml-05 { margin-left: 0.5rem; }
.mr-05 { margin-right: 0.5rem; }

/* Spacing */
.mb-025 { margin-bottom: 0.25rem; }
.mb-035 { margin-bottom: 0.35rem; }
.mb-05 { margin-bottom: 0.5rem; }
.mb-1 { margin-bottom: 1rem; }
.mb-15 { margin-bottom: 1.5rem; }
.mb-2 { margin-bottom: 2rem; }
.mb-25 { margin-bottom: 2.5rem; }
.mt-025 { margin-top: 0.25rem; }
.mt-015 { margin-top: 0.15rem; }
.mt-05 { margin-top: 0.5rem; }
.mt-075 { margin-top: 0.75rem; }
.mt-1 { margin-top: 1rem; }
.p-05 { padding: 0.5rem; }
.py-025 { padding: 0.25rem 0; }
.py-04 { padding: 0.4rem 0; }
.pl-1 { padding-left: 1rem; }

/* Width constraints */
.w-full { width: 100%; }
.mw-90 { max-width: 90px; }
.mw-100 { max-width: 100px; }
.mw-120 { max-width: 120px; }
.mw-130 { max-width: 130px; }
.mw-140 { max-width: 140px; }
.mw-150 { max-width: 150px; }
.mw-180 { max-width: 180px; }
.mw-200 { max-width: 200px; }
.mw-220 { max-width: 220px; }
.mw-250 { max-width: 250px; }
.mw-300 { max-width: 300px; }
.mw-350 { max-width: 350px; }
.mw-400 { max-width: 400px; }
.min-w-55 { min-width: 55px; }
.min-w-60 { min-width: 60px; }
.min-w-200 { min-width: 200px; }
.min-w-250 { min-width: 250px; }

/* Typography */
.text-xs { font-size: 0.7rem; }
.text-sm { font-size: 0.75rem; }
.text-0-8 { font-size: 0.8rem; }
.text-0-85 { font-size: 0.85rem; }
.text-0-9 { font-size: 0.9rem; }
.text-1 { font-size: 1rem; }
.text-lg { font-size: 1.1rem; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mono { font-family: monospace; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-danger { color: var(--discord-red); }
.text-nowrap { white-space: nowrap; }
.text-break { word-break: break-all; }
.text-left { text-align: left; }
.opacity-04 { opacity: 0.4; }
.overflow-x { overflow-x: auto; }

/* Borders */
.border-bottom { border-bottom: 1px solid var(--border); }
.border-accent-l { border-left: 3px solid var(--accent); }
.border-subtle-l { border-left: 2px solid var(--bg-tertiary); }

/* --- Component classes --- */

/* List item row (streamer, feed, trigger, etc.) */
.list-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Edit panel (shown/hidden under list items) */
.edit-panel {
    display: none;
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    margin-top: -0.5rem;
}

/* Small action buttons */
.btn-sm {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
}

.btn-xs {
    font-size: 0.75rem;
    padding: 0.3rem 0.65rem;
}

.btn-xxs {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}

.btn-danger {
    background: var(--discord-red);
    color: white;
}

.btn-danger-lg {
    background: var(--discord-red);
    color: white;
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
}

.btn-danger-xxs {
    background: var(--discord-red);
    color: white;
    font-size: 0.7rem;
    padding: 0.2rem 0.45rem;
}

/* Permission badges */
.perm-badge-allow {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    background: var(--discord-green);
    color: #000;
    font-weight: 600;
}

.perm-badge-deny {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    background: var(--discord-red);
    color: #fff;
    font-weight: 600;
}

.perm-badge-allow-sm {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: var(--discord-green);
    color: #000;
    font-weight: 600;
}

.perm-badge-deny-sm {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: var(--discord-red);
    color: #fff;
    font-weight: 600;
}

.perm-badge-scope {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    background: #5865f2;
    color: #fff;
    font-weight: 600;
}

.perm-badge-scope-sm {
    font-size: 0.65rem;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    background: #5865f2;
    color: #fff;
    font-weight: 600;
}

/* Permission buttons (active states) */
.perm-btn-active-allow {
    background: var(--discord-green);
    color: #000;
    font-weight: 600;
}

.perm-btn-active-deny {
    background: var(--discord-red);
    color: #fff;
    font-weight: 600;
}

.perm-btn-active-none {
    outline: 2px solid var(--accent);
}

/* Permission section toggle */
.perm-toggle {
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.perm-toggle-inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
}

.perm-arrow {
    font-size: 0.7rem;
    transition: transform 0.15s;
    display: inline-block;
}

.perm-arrow-sm {
    font-size: 0.6rem;
    transition: transform 0.15s;
    display: inline-block;
}

.perm-cmd-toggle {
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 40px;
    display: flex;
    align-items: center;
    padding: 0.4rem 0;
}

.perm-cog-content {
    display: none;
    padding-left: 1rem;
    border-left: 3px solid var(--accent);
}

.perm-cmd-content {
    display: none;
    padding-left: 1rem;
    border-left: 2px solid var(--bg-tertiary);
}

.perm-rule-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
    flex-wrap: wrap;
}

.perm-rule-row-sm {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.3rem 0;
    flex-wrap: wrap;
}

/* Lookup result card */
.lookup-card {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Avatar styles */
.avatar-lg {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.avatar-sm {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

.avatar-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

/* Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table-sm {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.data-table th, .data-table-sm th {
    text-align: left;
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.data-table td, .data-table-sm td {
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
}

.data-table td.text-truncate, .data-table-sm td.text-truncate {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Code badge */
.code-badge {
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
}

/* Height fit */
.h-fit { height: fit-content; }

/* Checkbox label */
.check-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.check-label-secondary {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
}

/* Warning text */
.warning-text {
    color: #ed4245;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* Input width override for specific widths */
.input-w-200 { width: 200px; font-size: 0.85rem; }

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }

    .guild-grid, .cog-grid {
        grid-template-columns: 1fr;
    }

    .navbar {
        padding: 0 1rem;
    }

    .nav-links {
        gap: 0.5rem;
    }

    .input {
        max-width: 100%;
    }
}
