/* === Base === */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root { --bg: #0f172a; --card: #1e293b; --border: #334155; --text: #e2e8f0; --muted: #94a3b8; --accent: #3b82f6; --safe-bottom: env(safe-area-inset-bottom, 0px); }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; overflow: hidden; }

/* === Auth pages (login/register) === */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; overflow: auto; padding: 24px; }
.auth-container { text-align: center; max-width: 360px; width: 100%; }
.auth-logo { width: 80px; height: 80px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 2.5rem; font-weight: 700; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; }
.auth-container h1 { font-size: 1.5rem; margin-bottom: 8px; }
.auth-subtitle { color: var(--muted); margin-bottom: 32px; font-size: 0.9rem; }
.auth-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 16px; font-size: 1.1rem; font-weight: 600; border: none; border-radius: 14px; background: var(--accent); color: #fff; cursor: pointer; transition: background 0.2s; }
.auth-btn:hover { background: #2563eb; }
.auth-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-btn-icon { font-size: 1.3rem; }
.auth-hint { color: var(--muted); font-size: 0.8rem; margin-top: 16px; }
.auth-error { background: #991b1b; color: #fca5a5; padding: 12px; border-radius: 10px; margin-bottom: 16px; font-size: 0.85rem; }
.auth-input { width: 100%; padding: 14px 16px; font-size: 1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text); margin-bottom: 12px; outline: none; }
.auth-input:focus { border-color: var(--accent); }
.auth-form { margin-bottom: 8px; }

/* === App shell === */
.app-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* Header */
#app-header { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); background: var(--card); border-bottom: 1px solid var(--border); flex-shrink: 0; }
#app-header h1 { font-size: 1.1rem; color: var(--accent); flex: 1; }
.header-logo { width: 28px; height: 28px; border-radius: 6px; object-fit: contain; flex-shrink: 0; }
.header-user { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85rem; cursor: pointer; padding: 5px 10px; border-radius: 20px; border: 1px solid var(--border); transition: all 0.2s; flex-shrink: 0; }
.header-user:hover { background: var(--border); border-color: var(--accent); color: var(--text); }
.user-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 0.75rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.user-chevron { font-size: 0.6rem; color: var(--muted); margin-left: 1px; }

/* Content */
#app-content { flex: 1; overflow: hidden; position: relative; }
.panel { display: none; width: 100%; height: 100%; overflow-y: auto; }
.panel.active { display: block; }
.panel-iframe { width: 100%; height: 100%; border: none; }

/* Bottom tabs — 3 onglets fixes */
#bottom-tabs { display: flex; background: var(--card); border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom); flex-shrink: 0; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 4px; border: none; background: none; color: var(--muted); cursor: pointer; font-size: 0.72rem; transition: color 0.2s; -webkit-tap-highlight-color: transparent; text-decoration: none; }
.tab.active { color: var(--accent); }
.tab-icon { font-size: 1.5rem; line-height: 1; }
.tab-label { font-weight: 600; }

/* === Home panel === */
.home-welcome { padding: 24px 16px 16px; }
.home-welcome h2 { font-size: 1.4rem; font-weight: 600; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 16px 24px; }
.home-card { display: block; background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 24px 16px; text-align: center; cursor: pointer; transition: all 0.2s; text-decoration: none; color: inherit; }
.home-card:active { transform: scale(0.97); }
.home-card-icon { font-size: 2rem; margin-bottom: 8px; }
.home-card-label { font-size: 0.9rem; font-weight: 600; color: var(--muted); }

/* === Settings panel === */
.settings-page { padding: 24px 16px; }
.settings-page h2 { font-size: 1.3rem; margin-bottom: 20px; }
.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 10px; }
.settings-item { display: flex; justify-content: space-between; padding: 12px 14px; background: var(--card); border-radius: 10px; margin-bottom: 4px; font-size: 0.9rem; }
.settings-item span { color: var(--muted); }
.settings-btn { width: 100%; padding: 14px; font-size: 0.95rem; font-weight: 600; border: none; border-radius: 12px; background: var(--accent); color: #fff; cursor: pointer; }
.settings-btn.danger { background: #dc2626; }
.settings-link { display: block; padding: 12px 14px; background: var(--card); border-radius: 10px; margin-bottom: 4px; color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.settings-link:hover { background: var(--border); }
.settings-hint { font-size: 0.75rem; color: var(--muted); margin-top: 8px; }

/* Invite */
.invite-url { display: flex; gap: 8px; margin-top: 10px; }
.invite-url input { flex: 1; padding: 10px; font-size: 0.8rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.invite-url button { padding: 10px 16px; border: none; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; font-size: 0.8rem; }
.invite-hint { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }

/* === Responsive desktop === */
@media (min-width: 768px) {
    /* Dark background behind the centered app shell */
    body { background: #070d1a; }

    /* App shell: centered card with sidebar layout via CSS Grid */
    .app-page {
        display: grid;
        grid-template-areas:
            "header header"
            "nav    content";
        grid-template-columns: 190px 1fr;
        grid-template-rows: auto 1fr;
        max-width: 1000px;
        width: calc(100vw - 40px);
        margin: 20px auto;
        height: calc(100vh - 40px);
        height: calc(100dvh - 40px);
        border-radius: 16px;
        overflow: hidden;
        box-shadow: 0 8px 60px rgba(0,0,0,0.6);
        border: 1px solid var(--border);
    }

    /* Header spans full width */
    #app-header {
        grid-area: header;
    }
    #app-header h1 { font-size: 1.25rem; }

    /* Sidebar nav */
    #app-content {
        grid-area: content;
        overflow: hidden;
    }
    #bottom-tabs {
        grid-area: nav;
        flex-direction: column;
        border-top: none;
        border-right: 1px solid var(--border);
        padding: 16px 8px 16px;
        justify-content: flex-start;
        gap: 2px;
        overflow-y: auto;
    }
    .tab {
        flex-direction: row;
        justify-content: flex-start;
        gap: 10px;
        padding: 10px 14px;
        font-size: 0.88rem;
        border-radius: 10px;
        flex: none;
        width: 100%;
    }
    .tab-icon { font-size: 1.1rem; }
    .tab-label { font-weight: 500; font-size: 0.88rem; }
    .tab.active { background: rgba(59,130,246,0.15); color: var(--accent); }
    .tab:hover:not(.active) { background: var(--border); color: var(--text); }

    /* Home panel */
    .home-grid {
        grid-template-columns: repeat(4, 1fr);
        max-width: none;
        padding: 0 28px 28px;
        gap: 16px;
    }
    .home-welcome { padding: 32px 28px 20px; }
    .home-welcome h2 { font-size: 1.7rem; }
    .home-card { padding: 30px 16px; }
    .home-card-icon { font-size: 2.4rem; }
    .home-card-label { font-size: 1rem; }

    /* Settings panel: buttons not full-width */
    .settings-page { padding: 28px 32px; max-width: none; }
    .settings-page h2 { font-size: 1.5rem; }
    .settings-btn {
        width: auto;
        display: inline-block;
        min-width: 180px;
        padding: 10px 22px;
        font-size: 0.9rem;
    }
    .settings-btn.danger { margin-top: 0; }
    .settings-item { max-width: 480px; }
    .settings-link { max-width: 360px; }
}
