* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: #f0f2f5;
    margin: 0;
    color: #1f2933;
}

/* ------------------------------------------------------------------ */
/* Auth pages (login) — centered card layout                           */
/* ------------------------------------------------------------------ */

body.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
}

.logo {
    display: block;
    margin: 0 auto 1.5rem;
}

h1 { margin-top: 0; font-size: 1.4rem; }

label {
    display: block;
    margin: 0.75rem 0 0.25rem;
    font-weight: 600;
    font-size: 0.9rem;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

.btn {
    display: inline-block;
    margin-top: 1.25rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 4px;
    background: #2563eb;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

.btn:hover { background: #1d4ed8; }

.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }

.error {
    background: #fee2e2;
    color: #b91c1c;
    border-radius: 4px;
    padding: 0.6rem;
    font-size: 0.9rem;
}

/* ------------------------------------------------------------------ */
/* Site shell — branding, menu, footer                                 */
/* ------------------------------------------------------------------ */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 1.25rem;
    color: #1e293b;
    background: #fff;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #1e293b;
    text-decoration: none;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.brand-name { font-weight: 600; font-size: 1.05rem; }

.nav-block {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.nav-link {
    color: #444;
    text-decoration: none;
    padding: 0.45rem 0.85rem;
    border-radius: 6px;
    font-size: 0.95rem;
}

.nav-link:hover { background: rgba(0, 0, 0, 0.08); }

.nav-link.active { color: #fff; background: #2563eb; }

.account-menu { position: relative; margin-left: 0.75rem; }
.account-trigger {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.35rem 0.65rem 0.35rem 0.35rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    color: #334155;
    font-size: 0.9rem;
    font-weight: 600;
    list-style: none;
    cursor: pointer;
    user-select: none;
    transition: background 150ms, border-color 150ms, box-shadow 150ms;
}
.account-trigger::-webkit-details-marker { display: none; }
.account-trigger:hover { background: #f1f5f9; border-color: #cbd5e1; }
.account-menu[open] .account-trigger { background: #eff6ff; border-color: #93c5fd; box-shadow: 0 0 0 3px #dbeafe; }
.account-avatar {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    background: #dbeafe;
    color: #2563eb;
    flex-shrink: 0;
}
.account-menu svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.account-avatar svg { width: 20px; height: 20px; }
.account-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chevron { width: 18px; height: 18px; color: #64748b; transition: transform 150ms; }
.account-menu[open] .account-chevron { transform: rotate(180deg); }
.account-options {
    position: absolute;
    right: 0;
    top: calc(100% + 0.65rem);
    width: 240px;
    max-width: calc(100vw - 2.5rem);
    padding: 0.4rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 12px 32px -8px rgba(15, 23, 42, 0.22), 0 3px 8px rgba(15, 23, 42, 0.06);
    z-index: 1000;
    animation: account-menu-appear 130ms ease-out;
}
.account-menu-heading { padding: 0.65rem 0.75rem 0.5rem; color: #64748b; font-size: 0.75rem; font-weight: 600; }
.account-options .account-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 44px;
    padding: 0.65rem 0.75rem;
    color: #334155;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: 7px;
    transition: background 120ms, color 120ms;
}
.account-option svg { width: 19px; height: 19px; flex-shrink: 0; color: #64748b; }
.account-options .account-option:hover, .account-options .account-option:focus-visible { background: #eff6ff; color: #1d4ed8; }
.account-option:hover svg, .account-option:focus-visible svg { color: inherit; }
.account-menu-divider { height: 1px; margin: 0.35rem 0.5rem; background: #e2e8f0; }
.account-options .account-option-logout { color: #b91c1c; }
.account-option-logout svg { color: #dc2626; }
.account-options .account-option-logout:hover, .account-options .account-option-logout:focus-visible { background: #fef2f2; color: #b91c1c; }
@keyframes account-menu-appear {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    .account-options { animation: none; }
    .account-trigger, .account-chevron, .account-option { transition: none; }
}
.password-dialog {
    width: min(440px, calc(100% - 2rem));
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: 1.5rem;
    border: none;
    border-radius: 8px;
    color: #1f2933;
    background: #fff;
}
.password-dialog::backdrop { background: rgba(15, 23, 42, 0.5); }
.password-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.success { background: #dcfce7; color: #166534; padding: 0.6rem; border-radius: 4px; }
.btn:disabled { opacity: 0.6; cursor: wait; }
:focus-visible { outline: 2px solid #2563eb; outline-offset: 3px; }
@media (max-width: 640px) {
    .site-header { flex-wrap: wrap; }
    .nav-block { width: 100%; align-items: stretch; }
    .site-nav { flex-wrap: wrap; justify-content: flex-end; }
}

.page-content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

.page-card {
    max-width: 560px;
}

.site-footer {
    border-top: 1px solid #e2e8f0;
    color: #64748b;
    font-size: 0.85rem;
    padding: 1rem 1.25rem;
    text-align: center;
}

/* ------------------------------------------------------------------ */
/* Dashboard page                                                      */
/* ------------------------------------------------------------------ */

/* The dashboard renders full-width; no page padding or max-width. */
body.dashboard-page .page-content {
    max-width: none;
    padding: 0;
}

/* Fallback card shown when the submodule is not installed yet. */
.dashboard-missing {
    margin-top: 2rem;
}

/* Text pages (about/privacy) use the full screen width. */
body.wide-page .page-content {
    max-width: none;
}

.page-card.page-wide {
    max-width: none;
}

.dashboard-missing pre {
    background: #f1f5f9;
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
}

/* ------------------------------------------------------------------ */
/* Dashboard embed (cl_dashboard submodule, included without iframe)   */
/* Styles scoped to #dashboard_embed so they never touch the shell.    */
/* Mimics the standalone dashboard's <body> style.                     */
/* ------------------------------------------------------------------ */

#dashboard_embed {
    background: #eee;
    text-align: center;
    min-height: calc(100vh - 4rem);
}

/* ------------------------------------------------------------------ */
/* Dashboard page scaling                                              */
/*                                                                     */
/* The dashboard is a fixed-proportion layout (pixel heights). To keep */
/* it on one screen with no page scrollbars, the page is a viewport-   */
/* tall flex column and the dashboard is scaled to fit the remaining   */
/* height by public/js/dashboard-scale.js (which scales the fonts too).*/
/* ------------------------------------------------------------------ */

body.dashboard-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

body.dashboard-page .site-header { flex: 0 0 auto; }

body.dashboard-page .site-footer { flex: 0 0 auto; }

body.dashboard-page .page-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0; /* reset margin:0 auto, which would otherwise defeat the flex stretch */
}

body.dashboard-page #dashboard_embed {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* The element that dashboard-scale.js scales. transform-origin is set in JS. */
body.dashboard-page #dashboard_embed #site_container {
    width: 100%;
    transform-origin: top center;
}
