:root {
    --bg: #1e1e1e;
    --bg-panel: #252526;
    --bg-elevated: #2d2d30;
    --bg-hover: #2a2d2e;
    --bg-active: #094771;
    --border: #3c3c3c;
    --text: #cccccc;
    --text-dim: #858585;
    --accent: #0e639c;
    --accent-hover: #1177bb;
    --danger: #c75050;
    --success: #4ec9b0;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', Tahoma, sans-serif;
    font-size: 13px;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    height: 44px;
    padding: 0 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 16px;
}

.brand {
    font-weight: 600;
    font-size: 14px;
}

.brand-sub {
    color: var(--text-dim);
    font-weight: 400;
    margin-left: 4px;
}

.current {
    flex: 1;
    text-align: center;
    color: var(--text-dim);
}

.current-name {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
}

.dirty-dot {
    color: var(--success);
    margin-left: 6px;
    font-size: 18px;
    line-height: 0;
    vertical-align: middle;
}

.actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-nav {
    display: flex;
    gap: 2px;
    margin-left: 8px;
}

.tab-btn {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid transparent;
    padding: 6px 14px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: background 0.1s, color 0.1s;
}

.tab-btn:hover { background: var(--bg-hover); color: var(--text); }
.tab-btn.is-active {
    background: var(--bg-active);
    color: white;
}

.tab-panel { display: flex; flex: 1; min-height: 0; }
.tab-panel[hidden] { display: none; }

.me-badge {
    color: var(--text-dim);
    font-size: 12px;
    padding: 0 6px;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.15); }

.meta-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 12px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    font-size: 12px;
}
.meta-bar select, .meta-bar input[type="text"] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 4px 6px;
    border-radius: 3px;
    font: inherit;
}
.meta-bar label { display: flex; gap: 6px; align-items: center; }
.shared-with input { width: 200px; }

.room-pane { padding: 16px 20px; flex-direction: column; overflow-y: auto; }
.room-editor { display: flex; flex-direction: column; gap: 18px; max-width: 720px; }
.empty-state { color: var(--text-dim); padding: 40px 0; text-align: center; }

.room-fieldset {
    border: 1px solid var(--border);
    background: var(--bg-panel);
    border-radius: 4px;
    padding: 14px 16px;
}
.room-fieldset legend { padding: 0 8px; font-weight: 600; }
.room-fieldset .hint { color: var(--text-dim); font-size: 12px; margin: 0 0 8px; }

.field-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.field-row label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-dim); }
.field-row input, .field-row select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 5px 8px;
    border-radius: 3px;
    font: inherit;
    min-width: 90px;
}

.script-list.mini li { padding: 4px 8px; font-size: 12px; }

.room-title { margin: 0 0 4px; font-size: 18px; font-weight: 600; }

.room-danger { margin-top: 12px; padding-top: 14px; border-top: 1px dashed var(--border); }

.detach-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0 6px;
    border-radius: 3px;
    cursor: pointer;
    margin-left: auto;
}
.detach-btn:hover { color: var(--danger); border-color: var(--danger); }

.btn {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: background 0.1s;
}

.btn:hover:not(:disabled) {
    background: var(--bg-hover);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    font-weight: 500;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-small {
    padding: 3px 10px;
    font-size: 12px;
}

.btn-icon {
    background: transparent;
    color: var(--text);
    border: 1px solid transparent;
    width: 36px;
    height: 32px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.btn-icon:hover {
    background: var(--bg-hover);
}

.mobile-only { display: none; }

.drawer-overlay {
    position: fixed;
    inset: 44px 0 0 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.drawer-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.layout {
    flex: 1;
    display: flex;
    min-height: 0;
}

.sidebar {
    width: 240px;
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-left {
    border-right: 1px solid var(--border);
}

.sidebar-right {
    border-left: 1px solid var(--border);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    height: 36px;
    flex-shrink: 0;
}

.script-list,
.function-list {
    list-style: none;
    margin: 0;
    padding: 4px 0;
    overflow-y: auto;
    flex: 1;
}

.script-list li {
    padding: 6px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    user-select: none;
}

.script-list li:hover {
    background: var(--bg-hover);
}

.script-list li.active {
    background: var(--bg-active);
    color: white;
}

.script-list li::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23519aba'><path d='M9 1H3a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V6L9 1zm0 1.5L12.5 6H9V2.5z'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
}

.function-list li {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}

.function-list li:hover {
    background: var(--bg-hover);
}

.function-list li.fn-section {
    padding: 8px 14px 4px;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.6px;
    color: var(--text-dim);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    cursor: default;
    user-select: none;
}

.function-list li.fn-section:hover {
    background: var(--bg-elevated);
}

.function-list .fn-sig {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    color: #dcdcaa;
}

.function-list .fn-desc {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 3px;
    line-height: 1.4;
}

.editor-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.editor {
    flex: 1;
    min-height: 0;
}

.editor-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
    font-size: 14px;
}

.ai-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.ai-input {
    flex: 1;
    padding: 7px 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: inherit;
    font-size: 13px;
    outline: none;
}

.ai-input:focus {
    border-color: var(--accent);
}

.ai-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-bar.is-loading .ai-input,
.ai-bar.is-loading .btn {
    opacity: 0.6;
    pointer-events: none;
}

.status {
    height: 22px;
    padding: 0 14px;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    font-size: 11px;
    flex-shrink: 0;
    transition: background 0.2s;
}

.status.is-error {
    background: var(--danger);
}

.status.is-success {
    background: #007a3d;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 20px;
    min-width: 360px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.modal h3 {
    margin: 0 0 14px 0;
    font-size: 14px;
    font-weight: 500;
}

.modal input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    outline: none;
}

.modal input:focus {
    border-color: var(--accent);
}

.modal-hint {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 6px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

@media (max-width: 800px) {
    .mobile-only { display: inline-flex; }

    .topbar {
        padding: 0 8px;
        gap: 8px;
    }

    .brand-sub { display: none; }

    .current {
        min-width: 0;
        overflow: hidden;
    }

    .current-name {
        font-size: 12px;
        display: inline-block;
        max-width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: bottom;
    }

    #btnSave {
        padding: 6px 10px;
    }

    .sidebar {
        position: fixed;
        top: 44px;
        bottom: 0;
        width: min(80vw, 320px);
        z-index: 60;
        transition: transform 0.2s ease;
        border: none;
    }

    .sidebar-left {
        left: 0;
        transform: translateX(-100%);
        border-right: 1px solid var(--border);
    }

    .sidebar-right {
        right: 0;
        transform: translateX(100%);
        border-left: 1px solid var(--border);
    }

    .sidebar-left.open,
    .sidebar-right.open {
        transform: translateX(0);
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.6);
    }

    .modal {
        width: 90vw;
        min-width: 0;
        max-width: 400px;
    }

    .modal input {
        font-size: 16px;
    }

    .ai-bar {
        padding: 6px 8px;
        gap: 6px;
    }

    .ai-input {
        font-size: 16px;
    }
}

/* ── Loja tab ── */
.shop-pane {
    padding: 20px 24px;
    overflow-y: auto;
}

.shop-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.shop-card {
    background: var(--bg-elevated);
}

.shop-card:hover {
    border-color: var(--accent) !important;
}

/* ── Room creation dialog ── */
dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

/* ── Admin tab ── */
.admin-pane {
    padding: 16px 20px;
    gap: 14px;
    overflow-y: auto;
}

.admin-section-item {
    cursor: pointer;
    padding: 8px 14px;
    font-size: 13px;
    user-select: none;
    list-style: none;
}

.admin-section-item::before { display: none; }

.admin-section-item:hover { background: var(--bg-hover); }

.admin-section-item.is-active {
    background: var(--bg-active);
    color: white;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: 14px;
}

.admin-table th {
    text-align: left;
    padding: 5px 10px;
    background: var(--bg-elevated);
    color: var(--text-dim);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.admin-table td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.admin-table tr:hover td { background: var(--bg-hover); }

.admin-editor {
    margin-top: 6px;
    max-width: 720px;
}
