/* Maahir Studio - Beginner-first visual overhaul.
 * Loaded AFTER styles.css. Keeps every existing class/selector working;
 * only changes the look & feel, adds onboarding + guided dashboard. */

:root {
    --brand: #6d5efc;
    --brand2: #22d3ee;
    --ink: #0b1021;
    --ink2: #111834;
    --card: #151d3b;
    --card2: #1b2549;
    --line2: rgba(255,255,255,.09);
    --txt: #e8ecff;
    --muted2: #9aa4cc;
    --grad: linear-gradient(120deg, #6d5efc, #22d3ee);
    --shadow2: 0 16px 40px rgba(0,0,0,.35);

    /* remap legacy tokens used by existing rules */
    --primary: #6d5efc;
    --primary-hover: #5a4ce8;
    --surface: #151d3b;
    --bg: #0b1021;
    --border: rgba(255,255,255,.09);
    --text: #e8ecff;
    --text-muted: #9aa4cc;
    --radius: 12px;
    --shadow: 0 8px 24px rgba(0,0,0,.28);
}

html { scroll-behavior: smooth; }
body { background: var(--ink); color: var(--txt); font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif; }
button, input, select, textarea { font-family: inherit; }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-small, .btn-icon, .add-btn {
    border-radius: 10px; font-weight: 600; cursor: pointer; transition: transform .18s, box-shadow .18s, background .18s;
    border: 1px solid transparent;
}
.btn-primary { background: var(--grad); color: #fff; padding: 11px 20px; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(109,94,252,.42); }
.btn-secondary { background: var(--card2); color: var(--txt); border-color: var(--line2); padding: 11px 18px; }
.btn-secondary:hover { background: #243060; }
.btn-icon { background: var(--card2); color: var(--txt); border: 1px solid var(--line2); width: 36px; height: 36px; padding: 0; border-radius: 9px; font-size: 1rem; }
.btn-icon:hover { background: var(--brand); color: #fff; }
.btn-small { background: var(--card2); color: var(--txt); border-color: var(--line2); padding: 7px 13px; font-size: .85rem; }
.btn-small:hover { background: var(--brand); color: #fff; }
input, select, textarea { background: var(--ink2); color: var(--txt); border: 1px solid var(--line2); border-radius: 9px; padding: 10px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(109,94,252,.18); }
a { color: var(--brand2); }

/* ---------- Auth / Login ---------- */
#auth-screen, #setup-screen {
    background: radial-gradient(circle at 20% 10%, rgba(109,94,252,.20), transparent 45%),
                radial-gradient(circle at 85% 80%, rgba(34,211,238,.14), transparent 45%), var(--ink);
    min-height: 100vh;
}
.auth-container {
    max-width: 440px; margin: 0 auto; padding: 42px 38px 30px;
    background: rgba(21,29,59,.92); border: 1px solid var(--line2); border-radius: 20px;
    box-shadow: var(--shadow2); backdrop-filter: blur(12px);
    position: relative; top: 8vh;
}
.auth-container h1 { font-size: 1.85rem; font-weight: 800; letter-spacing: -.02em; }
.auth-container .subtitle { margin-bottom: 26px; color: var(--muted2); }
.auth-container h2 { font-size: 1.15rem; margin: 8px 0 18px; }
.auth-form input { margin-bottom: 12px; padding: 13px 14px; }
.auth-form .btn-primary { width: 100%; padding: 13px; margin-top: 6px; font-size: 1rem; }
.switch-form { margin-top: 18px; font-size: .88rem; }
.switch-form a { color: var(--brand2); font-weight: 600; }
.legal-links { margin-top: 22px; }
.legal-link { color: var(--muted2); }
.error-message { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); }

/* Auth side welcome copy (injected) */
.auth-aside { max-width: 440px; margin: 0 auto 18px; text-align: center; color: var(--muted2); }
.auth-aside .aa-badge { display:inline-block; background: rgba(109,94,252,.18); color: #c4bcff; border:1px solid rgba(109,94,252,.35); padding:5px 13px; border-radius:999px; font-size:.75rem; font-weight:700; letter-spacing:.08em; }
.auth-aside h2 { color: var(--txt); font-size: 1.5rem; margin: 14px 0 8px; font-weight: 800; }
.auth-aside p { font-size: .92rem; line-height: 1.55; }

/* ---------- Headers ---------- */
.app-header, .editor-header {
    background: rgba(11,16,33,.92); backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line2); height: 66px; padding: 0 22px;
    display: flex; align-items: center; gap: 14px;
}
.app-header h1, .editor-header h2 { font-size: 1.2rem; font-weight: 800; letter-spacing: -.01em; }
.app-header .user-info { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.editor-header h2 { margin-right: auto; }
.editor-actions { display: flex; gap: 8px; margin-left: auto; }
.role-badge { background: rgba(109,94,252,.2); color: #c4bcff; border: 1px solid rgba(109,94,252,.35); border-radius: 999px; padding: 3px 11px; font-size: .75rem; }
.lang-select { font-size: .82rem; padding: 7px 9px; }

/* ---------- Dashboard ---------- */
.dashboard-content { display: grid; grid-template-columns: 280px 1fr; min-height: calc(100vh - 66px); }
.dashboard-sidebar { background: var(--ink2); border-right: 1px solid var(--line2); padding: 22px 16px; }
.dashboard-sidebar #new-project-btn { width: 100%; margin-bottom: 18px; padding: 13px; font-size: .95rem; }
.project-list { display: flex; flex-direction: column; gap: 7px; }
.project-item { background: var(--card); border: 1px solid var(--line2); border-radius: 10px; padding: 12px 14px; color: var(--txt); cursor: pointer; text-align: left; transition: .18s; font-size: .9rem; }
.project-item:hover { background: var(--card2); transform: translateX(3px); }
.project-item.active { background: rgba(109,94,252,.2); border-color: var(--brand); }

.dashboard-main { padding: 40px 46px 60px; background: radial-gradient(circle at 80% 0%, rgba(34,211,238,.07), transparent 40%); overflow-y: auto; }
.welcome { max-width: 900px; }
.welcome h2 { font-size: 2.1rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: 8px; }
.welcome > p { color: var(--muted2); font-size: 1.02rem; margin-bottom: 30px; }
.starter-templates h3 { font-size: 1.05rem; margin: 28px 0 14px; font-weight: 700; }
.template-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; }
.template-card { background: var(--card); border: 1px solid var(--line2); border-radius: 14px; padding: 22px 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; cursor: pointer; transition: .2s; color: var(--txt); }
.template-card:hover { transform: translateY(-5px); border-color: var(--brand); box-shadow: 0 14px 30px rgba(109,94,252,.18); }
.template-icon { font-size: 2.2rem; }
.template-name { font-size: .88rem; font-weight: 600; }

/* Beginner hero + quick actions (injected into dashboard) */
.beginner-hero {
    background: linear-gradient(120deg, rgba(109,94,252,.16), rgba(34,211,238,.09));
    border: 1px solid rgba(109,94,252,.3); border-radius: 16px; padding: 24px 26px; margin-bottom: 26px;
    display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
}
.bh-text { flex: 1; min-width: 260px; }
.bh-kicker { color: #c4bcff; font-size: .75rem; font-weight: 800; letter-spacing: .1em; }
.bh-text h3 { font-size: 1.45rem; margin: 6px 0; font-weight: 800; }
.bh-text p { color: var(--muted2); font-size: .9rem; }
.bh-btn { background: var(--grad); color: #fff; border: none; padding: 13px 22px; border-radius: 10px; font-weight: 700; cursor: pointer; transition: .2s; white-space: nowrap; }
.bh-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(109,94,252,.4); }

.path-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 12px; }
.path-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 10px; }
.path-card { background: var(--card); border: 1px solid var(--line2); border-radius: 14px; padding: 20px; cursor: pointer; transition: .2s; position: relative; overflow: hidden; }
.path-card:hover { transform: translateY(-4px); border-color: var(--brand2); }
.path-num { width: 30px; height: 30px; border-radius: 9px; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .9rem; margin-bottom: 12px; }
.path-card h4 { font-size: .98rem; margin-bottom: 5px; }
.path-card p { color: var(--muted2); font-size: .82rem; line-height: 1.5; }
.path-arrow { position: absolute; right: 16px; top: 18px; color: var(--muted2); font-size: 1.1rem; }

/* ---------- Editor ---------- */
.editor-content { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100vh - 66px); }
.editor-sidebar { background: var(--ink2); border-right: 1px solid var(--line2); padding: 18px 14px; overflow-y: auto; }
.editor-sidebar h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted2); margin: 8px 6px 12px; }
.file-tree, .version-history { margin-bottom: 22px; }
#file-list > div, #version-list > div { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: .85rem; }
#file-list > div:hover, #version-list > div:hover { background: var(--card2); }
.editor-main { background: var(--ink); min-width: 0; display: flex; flex-direction: column; }
.editor-tabs { display: flex; gap: 3px; padding: 10px 14px; border-bottom: 1px solid var(--line2); overflow-x: auto; background: var(--ink2); scrollbar-width: thin; }
.tab-btn { background: transparent; color: var(--muted2); border: none; padding: 9px 14px; border-radius: 9px; font-size: .83rem; white-space: nowrap; cursor: pointer; transition: .18s; }
.tab-btn:hover { background: var(--card2); color: var(--txt); }
.tab-btn.active { background: var(--brand); color: #fff; font-weight: 600; }
.tab-content { flex: 1; padding: 22px; overflow: auto; }
.tab-content h2, .tab-content h3 { margin-bottom: 12px; }
.file-header { background: var(--card); border: 1px solid var(--line2); border-radius: 10px 10px 0 0; padding: 10px 14px; display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted2); }
#code-editor { width: 100%; min-height: calc(100vh - 230px); background: var(--ink2); border: 1px solid var(--line2); border-top: none; border-radius: 0 0 10px 10px; color: #c8d0f0; font-family: 'SF Mono',Monaco,Menlo,Consolas,monospace; font-size: .88rem; line-height: 1.7; padding: 18px; resize: vertical; }

/* Chat */
.chat-messages { background: var(--card); border: 1px solid var(--line2); border-radius: 12px; padding: 18px; min-height: 320px; max-height: 52vh; overflow-y: auto; }
.chat-message { margin-bottom: 14px; line-height: 1.6; }
.chat-message .role { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--brand2); font-weight: 700; }
.chat-input { display: flex; gap: 10px; margin-top: 14px; align-items: stretch; }
.chat-input textarea { flex: 1; resize: none; min-height: 52px; }
.chat-input .btn-primary { align-self: stretch; }

/* Run / terminal / logs */
.runtime-logs, .terminal-output, .db-schema, pre { background: var(--ink2) !important; color: #a9e6c0 !important; border: 1px solid var(--line2); border-radius: 10px; padding: 14px; font-family: 'SF Mono',Monaco,Consolas,monospace; font-size: .82rem; }
.run-controls, .run-url-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.runtime-status { color: var(--brand2); font-size: .85rem; }
.terminal-output { min-height: 220px; max-height: 45vh; overflow-y: auto; }
.terminal-input-row { display: flex; gap: 10px; margin-top: 12px; }
.terminal-input-row input { flex: 1; }
.terminal-prompt { color: var(--brand2); font-weight: 700; padding-top: 10px; }

/* Generic content panels */
.tab-content > div { margin-bottom: 14px; }
.model-select { background: var(--card2); color: var(--txt); border: 1px solid var(--line2); border-radius: 9px; padding: 9px 11px; }
.arena-results, .council-final, .db-result, .email-status, .email-test-result { background: var(--card); border: 1px solid var(--line2); border-radius: 12px; padding: 16px; }

/* Admin */
.admin-content { padding: 30px; }
.admin-content h2 { margin-bottom: 18px; font-size: 1.5rem; font-weight: 800; }
.admin-tabs { display: flex; gap: 8px; margin-bottom: 22px; border-bottom: 1px solid var(--line2); }
.admin-tab-btn { background: transparent; border: none; color: var(--muted2); padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent; }
.admin-tab-btn.active { color: var(--txt); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------- Modals ---------- */
.legal-modal-card, .help-modal-card { background: var(--card); border: 1px solid var(--line2); box-shadow: var(--shadow2); }
.legal-modal-body, .help-modal-body { color: var(--txt); }
.legal-section p, .help-section p { color: var(--muted2); }
.help-nav-btn.active { background: var(--brand); }
.help-modal, .legal-modal { z-index: 500; }
.cookie-banner { background: var(--ink2); border-top: 1px solid var(--line2); }

/* ---------- Onboarding tour ---------- */
#onboarding-modal { position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center; background: rgba(5,8,20,.78); padding: 20px; backdrop-filter: blur(5px); }
#onboarding-modal[hidden] { display: none !important; }
.onb-card { background: var(--card); border: 1px solid rgba(109,94,252,.35); border-radius: 20px; width: 100%; max-width: 560px; box-shadow: 0 30px 80px rgba(0,0,0,.6); overflow: hidden; animation: onbIn .3s ease-out; }
@keyframes onbIn { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
.onb-bar { height: 4px; background: var(--card2); }
.onb-bar > div { height: 100%; background: var(--grad); transition: width .3s; }
.onb-body { padding: 32px 34px 26px; }
.onb-step { color: #c4bcff; font-size: .75rem; font-weight: 800; letter-spacing: .12em; }
.onb-title { font-size: 1.65rem; font-weight: 800; margin: 10px 0 10px; letter-spacing: -.02em; }
.onb-text { color: var(--muted2); font-size: .96rem; line-height: 1.65; }
.onb-visual { background: var(--ink2); border: 1px solid var(--line2); border-radius: 12px; padding: 18px; margin: 20px 0; font-size: .88rem; }
.onb-visual .ov-line { padding: 5px 0; color: #c8d0f0; }
.onb-visual .ov-line b { color: var(--brand2); }
.onb-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 24px; }
.onb-dots { display: flex; gap: 7px; }
.onb-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--card2); transition: .2s; }
.onb-dots span.on { background: var(--brand2); width: 22px; border-radius: 4px; }
.onb-next { background: var(--grad); color: #fff; border: none; padding: 12px 24px; border-radius: 10px; font-weight: 700; cursor: pointer; }
.onb-next:hover { transform: translateY(-2px); }
.onb-skip { background: none; border: none; color: var(--muted2); cursor: pointer; font-size: .85rem; }
.onb-skip:hover { color: var(--txt); }
.onb-close { position: absolute; top: 16px; right: 18px; background: none; border: none; color: var(--muted2); font-size: 1.4rem; cursor: pointer; }

/* Guided callout on first project open */
.guide-tip { position: fixed; z-index: 800; max-width: 320px; background: var(--card); border: 1px solid var(--brand); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow2); font-size: .88rem; }
.guide-tip h4 { font-size: .95rem; margin-bottom: 6px; }
.guide-tip p { color: var(--muted2); margin-bottom: 12px; }
.guide-tip button { background: var(--grad); color: #fff; border: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: .8rem; font-weight: 600; }

/* Responsive */
@media (max-width: 900px) {
    .dashboard-content, .editor-content { grid-template-columns: 1fr; }
    .dashboard-sidebar, .editor-sidebar { border-right: none; border-bottom: 1px solid var(--line2); }
    .dashboard-main { padding: 26px 20px; }
    .template-grid, .path-grid { grid-template-columns: repeat(2, 1fr); }
    .editor-actions { flex-wrap: wrap; }

    /* Editor header must grow with wrapped actions - a fixed 66px height
       pushed Save Version / Export ZIP above the viewport on phones. */
    #editor-screen.active { display: flex; flex-direction: column; }
    #editor-screen .editor-header {
        height: auto; min-height: 66px; flex: 0 0 auto;
        flex-wrap: wrap; gap: 8px; padding: 10px 14px;
    }
    #editor-screen .editor-header h2 { flex: 1 1 120px; margin-right: 0; }
    #editor-screen .editor-actions { flex: 1 1 100%; margin-left: 0; }
    #editor-screen .editor-actions button { flex: 1 1 auto; }
    #editor-screen .editor-content { flex: 1 1 auto; height: auto; min-height: 0; }
    #editor-screen .tabs { flex-wrap: wrap; }
}
@media (max-width: 560px) {
    .path-grid, .template-grid { grid-template-columns: 1fr; }
    .onb-body { padding: 26px 22px; }
    .app-header h1, .editor-header h2 { font-size: 1rem; }
    .user-info #user-name { display: none; }
}
