/* Shared components on the tokens: header bar, logo and wordmark, user menu, buttons, full-page screens,
   modal shell and toasts. App stylesheets load after this one and may refine any of them. */

/* ---------- header bar: brand left, actions right ---------- */
.header {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 56px;
    padding-top: env(safe-area-inset-top, 0);
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: 0;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 50;
}
.header h1,
.header .brand {
    margin: 0;
    font-size: inherit;
    font-weight: normal;
    line-height: 1;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.logo-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
}
.krul-logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}
/* Logo parts by class, for markup without fill/stroke attributes. */
.krul-logo .crown { fill: var(--iris-500); }
.krul-logo .jewel { fill: var(--regal-500); }
.krul-logo .curl { fill: none; stroke: var(--blonde-400); stroke-width: 4; stroke-linecap: round; }
.wordmark-stack {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1;
    gap: 2px;
}
.wordmark {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--fg-1);
    line-height: 1;
}
.wordmark-dot { color: var(--iris-500); }
.wordmark-eyebrow {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--fg-3);
    line-height: 1;
}

/* ---------- user menu: avatar button + dropdown (menu.js toggles .open) ---------- */
.user-menu {
    position: relative;
    z-index: 200;
}
.user-menu-btn {
    background: var(--iris-500);
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    padding: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--dur-fast) var(--ease-out);
}
.user-menu-btn:hover { border-color: var(--fg-3); }
.user-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}
.user-avatar.loaded { display: block; }
.user-initial {
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.01em;
}
.user-avatar.loaded + .user-initial { display: none; }
.user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    min-width: 220px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.user-dropdown.open { display: block; }
.user-info { padding: 12px 16px; }
.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--fg-1);
}
.user-email,
.user-location {
    font-size: 11px;
    color: var(--fg-3);
    margin-top: 2px;
}
.dropdown-divider {
    height: 1px;
    background: var(--border-subtle);
}
.dropdown-version {
    padding: 8px 16px;
    font-size: 11px;
    color: var(--fg-3);
    font-variant-numeric: tabular-nums;
}
.dropdown-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--fg-2);
    font-family: inherit;
    font-size: 12px;
    text-align: left;
    text-decoration: none;
    transition: background 0.15s;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.logout { color: var(--danger); }
.dropdown-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    margin-right: 8px;
}
.theme-label {
    color: var(--fg-3);
    font-size: 10px;
    margin-left: auto;
    text-transform: uppercase;
}

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-sunken);
    color: var(--fg-1);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.2;
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--bg-hover); border-color: var(--fg-3); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-ghost { background: transparent; }
.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--fg-on-brand);
    font-weight: 500;
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block { display: flex; width: 100%; padding: 10px 32px; font-size: 1em; }

/* ---------- full-page screens (sign-in, access denied, unreachable), above every dialog ---------- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    color: var(--fg-1);
}
.screen-card {
    text-align: center;
    max-width: 400px;
    padding: 40px 20px;
}
.screen-card h2 {
    font-size: 1.5em;
    margin: 0 0 16px;
    color: var(--fg-1);
}
.screen-card p {
    margin: 0 0 12px;
    color: var(--fg-2);
    line-height: 1.5;
}
.screen-card code {
    background: var(--bg-raised);
    border: 1px solid var(--border-subtle);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}
.screen-card .btn-block { margin-top: 16px; }
.screen-divider {
    display: flex;
    align-items: center;
    margin: 16px 0;
    color: var(--fg-3);
    font-size: 0.85em;
}
.screen-divider::before,
.screen-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-subtle);
}
.screen-divider span { padding: 0 12px; }
.screen-divider + .btn-block { margin-top: 0; }

/* ---------- modal shell ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in oklch, var(--bg) 70%, transparent);
}
.modal-content {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 20px;
}
.modal-content h3 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
}
.modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
}
.modal-spacer { flex: 1; }

/* ---------- toasts (toast.js), stacked under the header ---------- */
.toasts {
    position: fixed;
    top: calc(56px + env(safe-area-inset-top, 0px) + 8px);
    right: max(12px, env(safe-area-inset-right));
    z-index: 9000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 340px;
    max-width: calc(100vw - 24px);
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-left: 3px solid var(--iris-500);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 10px 8px 10px 14px;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(-8px);
    /* Own layer: some mobile GPU paths (Mali-G52 WebViews) smear animated content otherwise. */
    will-change: transform, opacity;
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}
.toast--in { opacity: 1; transform: none; }
.toast--warn { border-left-color: var(--warning-500); }
.toast--danger { border-left-color: var(--danger-500); }
.toast__body { flex: 1; min-width: 0; }
.toast__body--action { cursor: pointer; }
.toast__body--action:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-sm);
}
.toast__close {
    flex: none;
    background: none;
    border: none;
    color: var(--fg-3);
    font-size: 18px;
    line-height: 1;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
}
.toast__close:hover { color: var(--fg-1); background: var(--bg-sunken); }
@media (max-width: 767px) {
    .toasts {
        left: max(8px, env(safe-area-inset-left));
        right: max(8px, env(safe-area-inset-right));
        width: auto;
        max-width: none;
    }
}
@media (prefers-reduced-motion: reduce) {
    .toast { transition: none; transform: none; }
}
