/*
 * Xinglet — app-specific styles layered on top of Axe + brand.css
 *
 * Author: David M. Anderson
 * Built with AI assistance (Claude, Anthropic)
 */

/* Right-align the user-menu items in the nav. */
nav ul li.nav-right {
    margin-left: auto;
    display: flex;
    gap: 1.25rem;
}

/* Brand mark + wordmark in the nav. */
nav .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

nav .brand-mark {
    height: 1.4rem;
    width: auto;
    display: block;
}

/* Footer spacing. */
footer {
    margin-top: 3rem;
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* --- Auth pages (login, register, confirm, forgot, reset) -------------- */

.auth-card {
    max-width: 26rem;
    margin: 3rem auto;
}

.auth-card h1 {
    margin-top: 0;
}

.auth-error {
    background: var(--color-error-bg);
    color: var(--color-error-text);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.auth-ok {
    background: var(--color-ok-bg);
    color: var(--color-ok-text);
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.25rem 0;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--color-border);
}

.ms-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.65rem 1rem;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 500;
}

.ms-button:hover {
    background: var(--color-bg);
}

.ms-logo {
    width: 1.1rem;
    height: 1.1rem;
}

.auth-footer {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    text-align: center;
}

.auth-page-legal {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.footer-credits {
    margin-top: 0.25rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-align: center;
}

.excelano-credit {
    display: inline-block;
    vertical-align: baseline;
}

.excelano-credit img {
    height: 1.4em;
    width: auto;
    vertical-align: baseline;
}

/* Swap Excelano logo based on theme. Default: purple-on-transparent for
   light pages. Swap to white-on-transparent when the page is in dark mode
   (either by explicit data-theme or by system preference). */
.excelano-credit .for-dark { display: none; }

[data-theme="dark"] .excelano-credit .for-light { display: none; }
[data-theme="dark"] .excelano-credit .for-dark  { display: inline-block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .excelano-credit .for-light { display: none; }
    :root:not([data-theme="light"]) .excelano-credit .for-dark  { display: inline-block; }
}

/* --- Theme toggle in the nav ------------------------------------------- */

.theme-toggle {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-nav-text);
    border-radius: 999px;
    width: 2rem;
    height: 2rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    font-size: 1rem;
}

.theme-toggle::before { content: "\263E"; }                   /* ☾ crescent (click for light) */
[data-theme="light"] .theme-toggle::before { content: "\2600"; } /* ☀ sun (click for dark) */

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) .theme-toggle::before { content: "\2600"; }
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* --- Home / xinglet list ----------------------------------------------- */

.new-xinglet {
    margin: 1.25rem 0;
}

.xinglet-list {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.xinglet-list th,
.xinglet-list td {
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
}

/* Name column takes all extra space; other columns shrink to content. */
.xinglet-list th:first-child,
.xinglet-list td:first-child {
    width: 100%;
}
.xinglet-list th:not(:first-child),
.xinglet-list td:not(:first-child) {
    white-space: nowrap;
    width: 1px;
}

/* Role dropdowns in the sharing list need enough room to show the widest
   option ("editor") plus the native arrow. */
.xinglet-list select { min-width: 6.5rem; }

.xinglet-list th {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.name-hint {
    display: inline-block;
    width: 1.1rem;
    height: 1.1rem;
    line-height: 1rem;
    text-align: center;
    border-radius: 50%;
    border: 1px solid var(--color-text-muted);
    color: var(--color-text-muted);
    font-size: 0.7rem;
    margin-left: 0.35rem;
    cursor: help;
    opacity: 0.45;
    vertical-align: middle;
    user-select: none;
}
.name-hint:hover { opacity: 1; }

.share-add {
    display: flex;
    gap: 0.75rem;
    align-items: end;
    flex-wrap: wrap;
    margin: 1rem 0 0.5rem;
}
.share-add label {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    gap: 0.25rem;
}
.share-add input[type="email"] { min-width: 18rem; }

.inline-form {
    display: inline;
    margin: 0;
}

.row-action {
    font-size: 0.85rem;
    margin-right: 0.6rem;
}

button.danger {
    background: transparent;
    color: #b33a3a;
    border: 1px solid var(--color-border);
    padding: 0.2rem 0.6rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: var(--radius);
}

button.danger:hover {
    background: var(--color-error-bg);
}

.muted {
    color: var(--color-text-muted);
}

/* --- Editor page ------------------------------------------------------- */

/* Shared toolbar structure used by edit.php, share.php, and xinglet/index.php.
   Back link on the left, meta/title in the middle (flex: 1), actions on the right.
   Children <a> and <button> in the actions area render as a subtle outlined
   button so navigation and state-change controls line up visually. */

.editor-toolbar,
.xinglet-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
}

.editor-toolbar .back,
.xinglet-toolbar .back {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}
.editor-toolbar .back:hover,
.xinglet-toolbar .back:hover { color: var(--color-accent); }

.editor-toolbar .editor-title,
.xinglet-toolbar .xinglet-meta {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.editor-toolbar .editor-actions,
.xinglet-toolbar .xinglet-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Uniform tool button look for every action, whether anchor or button. */
.editor-toolbar .editor-actions > a,
.editor-toolbar .editor-actions > button,
.xinglet-toolbar .xinglet-actions > a,
.xinglet-toolbar .xinglet-actions > button {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: var(--radius);
    text-decoration: none;
    cursor: pointer;
    line-height: 1.3;
}
.editor-toolbar .editor-actions > a:hover,
.editor-toolbar .editor-actions > button:hover,
.xinglet-toolbar .xinglet-actions > a:hover,
.xinglet-toolbar .xinglet-actions > button:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.save-status {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.save-status[data-kind="dirty"]   { color: var(--color-highlight); }
.save-status[data-kind="working"] { color: var(--color-text-muted); }
.save-status[data-kind="ok"]      { color: #2d8a4f; }
.save-status[data-kind="error"]   { color: #b33a3a; }

.editor-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    height: calc(100dvh - 12rem);
    min-height: 30rem;
}

.editor-pane,
.preview-pane {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--color-surface);
}

.editor-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.editor-pane .cm-editor {
    flex: 1;
    min-height: 0;
    height: 100%;
}
.editor-pane .cm-scroller { overflow: auto; }

/* CodeMirror chrome tracks the site theme. Syntax highlighting spans set
   their own colors so we only theme the frame. */
.editor-pane .cm-editor { background: var(--color-surface); }
.editor-pane .cm-content { color: var(--color-text); caret-color: var(--color-text); }
.editor-pane .cm-gutters {
    background: var(--color-surface);
    color: var(--color-text-muted);
    border-right: 1px solid var(--color-border);
}
.editor-pane .cm-activeLine {
    background: color-mix(in srgb, var(--color-text-muted) 10%, transparent);
}
.editor-pane .cm-activeLineGutter {
    background: color-mix(in srgb, var(--color-text-muted) 15%, transparent);
}
.editor-pane .cm-selectionBackground,
.editor-pane .cm-content ::selection {
    background: color-mix(in srgb, var(--color-accent) 25%, transparent) !important;
}
.editor-pane .cm-cursor { border-left-color: var(--color-text); }

.editor-layout.preview-hidden {
    grid-template-columns: 1fr;
}
.editor-layout.preview-hidden .preview-pane {
    display: none;
}

.preview-pane iframe {
    width: 100%;
    height: 100%;
    border: 0;
    background: #ffffff;
}

@media (max-width: 900px) {
    .editor-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    .editor-pane,
    .preview-pane {
        height: 50dvh;
    }
}

/* --- Public display (xinglet render) ----------------------------------- */

.xinglet-frame {
    padding: 0.75rem 1rem;
    height: calc(100dvh - 12rem);
    min-height: 30rem;
}

.xinglet-frame iframe {
    width: 100%;
    height: 100%;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: #ffffff;
}

/* --- Maximized shared view (chromeless) -------------------------------- */

body.xinglet-max {
    margin: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
}

.xinglet-max-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.35rem 0.75rem;
    background: var(--color-nav-bg);
    color: var(--color-nav-text);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
    height: 2.25rem;
}

.xinglet-max-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xinglet-max-actions {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.xinglet-max-actions button {
    width: 1.75rem;
    height: 1.5rem;
    padding: 0;
    background: transparent;
    color: var(--color-nav-text);
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
}

.xinglet-max-actions button:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* theme-toggle in the max bar — shrink to match sibling buttons */
.xinglet-max-actions .theme-toggle {
    width: 1.75rem;
    height: 1.5rem;
    border-radius: 3px;
    font-size: 0.85rem;
}

.xinglet-max-frame {
    flex: 1 1 auto;
    min-height: 0;
}

.xinglet-max-frame iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #ffffff;
}


/* ============================================
   LEGAL PAGE
   ============================================ */

.legal-toc {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    margin: 1.5rem 0;
}

.legal-toc ul {
    margin: 0;
    padding-left: 1.25rem;
}

.legal-toc li {
    margin: 0.15rem 0;
}

.legal h2 {
    margin-top: 2rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--color-border);
}

.legal h3 {
    margin-top: 1.5rem;
    font-size: 1.05rem;
}

.legal-address {
    font-style: normal;
    color: var(--color-text-muted);
}


/* ============================================
   CLIENT PORTAL LISTING
   ============================================ */

.portal-list {
    list-style: none;
    padding: 0;
    margin: 1.5rem 0;
}

.portal-list li {
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    background: var(--color-surface);
}

.portal-list a {
    text-decoration: none;
}

.portal-list a:hover strong {
    text-decoration: underline;
}

.portal-meta {
    display: block;
    margin-top: 0.2rem;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}
