/* ============================================================
   FreyFil Identity — app chrome on top of FreyFil UI.
   Only --ff-* semantic tokens may be used here, with one exception:
   the .brand-panel block (and the logo-mirroring app-tile icon) uses
   fixed brand imagery (--auth-*) that is identical in light and dark.
   ============================================================ */

:root {
    /* From the FreyFil logo: ultramarine #0D05A8 + red #FE0002 */
    --auth-brand-1: #1A10D0;
    --auth-brand-2: #0D05A8;
    --auth-brand-3: #050240;
    --auth-brand-mid: #2F24E0;
    --auth-accent: #FE0002;
    --auth-accent-soft: #FF6B63;
}

/* ------------------------------------------------------------
   Shell: brand panel (left) + content (right)
   ------------------------------------------------------------ */

.auth-shell {
    min-height: 100dvh;
    display: grid;
    grid-template-columns: minmax(430px, 44%) 1fr;
}

/* --- Brand panel (fixed brand imagery; does not respond to dark mode) --- */

.brand-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 48px;
    padding: clamp(36px, 4.5vw, 60px);
    color: #E9E8FA;
    background:
        radial-gradient(720px 420px at 85% -10%, rgba(254, 0, 2, .10), transparent 60%),
        linear-gradient(158deg, var(--auth-brand-1) 0%, var(--auth-brand-2) 45%, var(--auth-brand-3) 100%);
    overflow: hidden;
}

/* Blueprint grid texture */
.brand-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
    background-size: 38px 38px;
    mask-image: linear-gradient(180deg, rgba(0,0,0,.9), rgba(0,0,0,.35));
    -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,.9), rgba(0,0,0,.35));
    pointer-events: none;
}

.brand-panel > * { position: relative; }

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
    color: inherit;
    width: fit-content;
}

.brand-lockup:hover { color: inherit; }

.logo-mark { width: 44px; height: 44px; flex: none; display: block; }
.logo-mark.sm { width: 34px; height: 34px; }

.brand-wordmark {
    font-size: var(--ff-text-lg);
    letter-spacing: -.01em;
    color: #fff;
    white-space: nowrap;
}

.brand-wordmark strong { font-weight: 700; }
.brand-wordmark span { font-weight: 300; opacity: .85; }

.brand-copy { max-width: 30rem; }

.brand-eyebrow {
    display: block;
    font-size: var(--ff-text-xs);
    font-weight: 600;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: #A5A0F0;
    margin-bottom: 14px;
}

.brand-headline {
    margin: 0 0 14px;
    font-size: clamp(1.55rem, 2.1vw, 2.05rem);
    font-weight: 650;
    line-height: 1.22;
    letter-spacing: -.02em;
    color: #FFFFFF;
}

.brand-headline em {
    font-style: normal;
    color: var(--auth-accent-soft);
}

.brand-sub {
    margin: 0 0 26px;
    font-size: var(--ff-text-md);
    line-height: 1.6;
    color: #C4C1F5;
}

.brand-foot {
    font-size: var(--ff-text-xs);
    color: #8D88DD;
}

/* --- Content panel --- */

.auth-main {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px clamp(16px, 4vw, 48px);
}

.auth-theme-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
}

.auth-mobile-brand {
    display: none;
    align-items: center;
    gap: 11px;
    align-self: flex-start;
    padding-top: 6px;
    color: var(--ff-text);
}

.auth-mobile-brand .brand-wordmark { color: var(--ff-text); font-size: var(--ff-text-md); }
.auth-mobile-brand .brand-wordmark span { opacity: .7; }

.auth-content {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 0;
}

.auth-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 18px 0 6px;
    font-size: var(--ff-text-xs);
    color: var(--ff-text-faint);
}

.auth-foot svg { width: 13px; height: 13px; opacity: .75; }
.auth-foot .dot { opacity: .5; }

/* ------------------------------------------------------------
   Card (extends ff-card)
   ------------------------------------------------------------ */

.auth-card {
    width: 100%;
    max-width: 408px;
    box-shadow: var(--ff-shadow-lg);
    animation: card-in .35s ease-out both;
}

.auth-card.wide { max-width: 460px; }

.auth-card > .ff-card__body { padding: clamp(28px, 4vw, 40px); }

@keyframes card-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .auth-card, .hub-content { animation: none; }
}

.auth-title {
    margin: 0 0 6px;
    font-size: var(--ff-text-xl);
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--ff-text);
}

.auth-sub {
    margin: 0 0 26px;
    font-size: var(--ff-text-base);
    line-height: 1.55;
    color: var(--ff-text-muted);
}

.auth-help {
    margin: 22px 0 0;
    padding-top: 18px;
    border-top: 1px solid var(--ff-border);
    font-size: var(--ff-text-xs);
    line-height: 1.5;
    text-align: center;
    color: var(--ff-text-faint);
}

/* Separator between the password form and the Microsoft SSO button */

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
    font-size: var(--ff-text-xs);
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ff-text-faint);
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--ff-border);
}

/* Icon badge for status pages */
.icon-badge {
    width: 54px;
    height: 54px;
    border-radius: var(--ff-radius-lg);
    display: grid;
    place-items: center;
    margin: 0 auto 18px;
}

.icon-badge svg { width: 26px; height: 26px; }
.icon-badge.danger { background: var(--ff-danger-soft); color: var(--ff-danger-soft-fg); }
.icon-badge.warn { background: var(--ff-warning-soft); color: var(--ff-warning-soft-fg); }
.icon-badge.brand { background: var(--ff-primary-soft); color: var(--ff-primary-soft-fg); }

.system-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding: 0;
    margin: 20px 0 0;
    list-style: none;
}

.system-chips li {
    padding: 5px 13px;
    border-radius: var(--ff-radius-full);
    font-size: var(--ff-text-xs);
    font-weight: 500;
    letter-spacing: .03em;
    color: var(--ff-text-muted);
    background: var(--ff-surface-sunken);
    border: 1px solid var(--ff-border);
}

.request-id {
    display: inline-block;
    margin-top: 4px;
    padding: 4px 10px;
    font-family: var(--ff-font-mono);
    font-size: var(--ff-text-xs);
    color: var(--ff-text-muted);
    background: var(--ff-surface-sunken);
    border: 1px solid var(--ff-border);
    border-radius: var(--ff-radius-md);
}

/* ------------------------------------------------------------
   Apps hub shell (/Apps) — topbar layout, no brand panel
   ------------------------------------------------------------ */

.hub-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.hub-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px clamp(20px, 4vw, 48px);
    background: var(--ff-surface-raised);
    border-bottom: 1px solid var(--ff-border);
}

.hub-topbar .brand-lockup { gap: 11px; }
.hub-topbar .brand-wordmark { color: var(--ff-text); font-size: var(--ff-text-md); }
.hub-topbar .brand-wordmark span { opacity: .7; }

.hub-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hub-user-name {
    font-size: var(--ff-text-sm);
    font-weight: 600;
    color: var(--ff-text-muted);
}

.hub-main {
    flex: 1;
    width: 100%;
    padding: clamp(28px, 4.5vw, 56px) clamp(20px, 4vw, 48px);
}

.hub-content {
    width: 100%;
    max-width: 1060px;
    margin: 0 auto;
    animation: card-in .35s ease-out both;
}

.hub-content.narrow { max-width: 560px; }
.hub-content.medium { max-width: 760px; }

.hub-foot {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    font-size: var(--ff-text-xs);
    color: var(--ff-text-faint);
    border-top: 1px solid var(--ff-border);
    background: var(--ff-surface-raised);
}

.hub-foot svg { width: 13px; height: 13px; opacity: .75; }
.hub-foot .dot { opacity: .5; }

.hub-section-title {
    margin: 22px 0 4px;
    font-size: var(--ff-text-xs);
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ff-text-faint);
}

.hub-url {
    font-family: var(--ff-font-mono);
    font-size: var(--ff-text-xs);
}

.hub-table-app {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--ff-text);
}

.ff-table tr.hub-row-muted td { opacity: .55; }

.inline-form { display: inline; margin: 0 0 0 6px; }

/* ------------------------------------------------------------
   App launcher tiles
   ------------------------------------------------------------ */

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.app-tile {
    position: relative;
    display: flex;
    align-items: center;
    gap: 13px;
    height: 100%;
    padding: 16px;
    border: 1px solid var(--ff-border);
    border-radius: var(--ff-radius-lg);
    background: var(--ff-surface-raised);
    box-shadow: var(--ff-shadow-sm);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--ff-transition-base), box-shadow var(--ff-transition-base), transform .06s ease;
}

a.app-tile:hover {
    border-color: var(--ff-primary);
    box-shadow: var(--ff-shadow-md);
    color: inherit;
}

a.app-tile:active { transform: translateY(1px); }

a.app-tile:focus-visible {
    outline: 2px solid var(--ff-ring);
    outline-offset: 1px;
}

.app-tile-icon {
    flex: none;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: var(--ff-radius-lg);
    font-size: var(--ff-text-sm);
    font-weight: 700;
    letter-spacing: .04em;
    color: #fff;
    /* mirrors the FreyFil logo palette — fixed brand gradient */
    background: linear-gradient(145deg, var(--auth-brand-mid), var(--auth-brand-2));
}

.app-tile-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.app-tile-icon.sm {
    width: 32px;
    height: 32px;
    border-radius: var(--ff-radius-md);
    font-size: var(--ff-text-xs);
}

.app-tile-text { display: grid; gap: 2px; min-width: 0; }

.app-tile-name {
    font-size: var(--ff-text-base);
    font-weight: 600;
    color: var(--ff-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-tile-desc {
    font-size: var(--ff-text-xs);
    line-height: 1.35;
    color: var(--ff-text-faint);
}

.app-tile.disabled {
    opacity: .62;
    background: var(--ff-surface-sunken);
}

.app-tile.disabled .app-tile-icon {
    background: linear-gradient(145deg, #94A3B8, #64748B);
}

.app-tile-lock {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 13px;
    height: 13px;
    color: var(--ff-text-faint);
}

.app-tile-lock svg { width: 13px; height: 13px; }

/* ------------------------------------------------------------
   App maintenance (/ManageApps) — create/edit form & one-time secret
   ------------------------------------------------------------ */

.hub-form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px 16px;
}

.hub-form-grid > .span-2 { grid-column: 1 / -1; }

.hub-check-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin-top: 6px;
}

.hub-secret {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.hub-secret .ff-input {
    flex: 1;
    font-family: var(--ff-font-mono);
    font-size: var(--ff-text-sm);
}

@media (min-width: 640px) {
    .hub-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ------------------------------------------------------------
   User maintenance (/ManageUsers) — check cards & role groups
   ------------------------------------------------------------ */

.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.check-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    padding: 11px 13px;
    border: 1px solid var(--ff-border);
    border-radius: var(--ff-radius-lg);
    background: var(--ff-surface-sunken);
    cursor: pointer;
    transition: border-color var(--ff-transition-base), background var(--ff-transition-base);
}

.check-card:hover { border-color: var(--ff-primary); background: var(--ff-surface-raised); }

.check-card-text { display: grid; gap: 2px; min-width: 0; }

.check-card-label {
    font-size: var(--ff-text-base);
    font-weight: 600;
    color: var(--ff-text);
}

.check-card-hint {
    font-size: var(--ff-text-xs);
    line-height: 1.35;
    color: var(--ff-text-faint);
}

.check-card.locked {
    cursor: default;
    opacity: .75;
    background: var(--ff-surface-sunken);
}

.check-card.locked:hover { border-color: var(--ff-border); }

.role-groups {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.role-group {
    margin: 0;
    padding: 11px 13px 12px;
    border: 1px solid var(--ff-border);
    border-radius: var(--ff-radius-lg);
    background: var(--ff-surface-sunken);
}

.role-group legend {
    float: none;
    width: auto;
    margin: 0 0 8px;
    padding: 0;
    font-size: var(--ff-text-base);
    font-weight: 600;
    color: var(--ff-text);
}

.role-group-options {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

/* ------------------------------------------------------------
   Responsive
   ------------------------------------------------------------ */

.auth-foot {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
}

.hub-topbar { flex-wrap: wrap; }
.hub-user { flex-wrap: wrap; justify-content: flex-end; }

/* Tablets and below: collapse the split panel */
@media (max-width: 991.98px) {
    .auth-shell { grid-template-columns: 1fr; }
    .brand-panel { display: none; }
    .auth-mobile-brand { display: flex; }
    .auth-content { padding: 20px 0; }
}

@media (max-width: 767.98px) {
    .hub-main { padding: 20px 16px; }
    .apps-grid { gap: 10px; }
    .check-grid, .role-groups { grid-template-columns: 1fr; }
}

/* Phones */
@media (max-width: 575.98px) {
    .auth-main { padding: 16px 14px; }
    .auth-card > .ff-card__body { padding: 24px 18px; }
    .auth-theme-toggle { top: 10px; right: 10px; }

    /* iOS Safari zooms into inputs rendered under 16px */
    .ff-input { font-size: 16px; }

    .hub-topbar { padding: 10px 14px; gap: 10px; }
    .hub-user { gap: 8px; }
    .hub-user-name { display: none; }
    .hub-signout-label { display: none; }
    .hub-main { padding: 16px 12px; }

    .ff-page-actions { width: 100%; }
    .ff-page-actions .ff-btn { flex: 1; justify-content: center; }

    .hub-grant-form { flex-direction: column; }
    .hub-grant-form .ff-btn { width: 100%; }

    .ff-card__footer { flex-wrap: wrap; }
    .ff-card__footer .ff-btn { flex: 1; justify-content: center; }
}

/* ---- Logo picker + cropper (/ManageApps form) ---- */
.logo-picker {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-picker .app-tile-icon {
    width: 64px;
    height: 64px;
    font-size: var(--ff-text-lg);
}

.logo-picker-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.logo-crop-stage {
    position: relative;
    width: min(280px, 100%);
    aspect-ratio: 1;
    margin: 0 auto 14px;
    overflow: hidden;
    border-radius: var(--ff-radius-lg);
    border: 1px solid var(--ff-border-strong);
    background: var(--ff-surface-sunken);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.logo-crop-stage:active { cursor: grabbing; }

.logo-crop-stage img {
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    display: block;
    pointer-events: none;
    will-change: transform;
}

.logo-crop-stage::after {
    /* rule-of-thirds guide, purely decorative */
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: .6;
    background:
        linear-gradient(to right, transparent calc(33.33% - .5px), var(--ff-border) calc(33.33% - .5px), var(--ff-border) calc(33.33% + .5px), transparent calc(33.33% + .5px), transparent calc(66.66% - .5px), var(--ff-border) calc(66.66% - .5px), var(--ff-border) calc(66.66% + .5px), transparent calc(66.66% + .5px)),
        linear-gradient(to bottom, transparent calc(33.33% - .5px), var(--ff-border) calc(33.33% - .5px), var(--ff-border) calc(33.33% + .5px), transparent calc(33.33% + .5px), transparent calc(66.66% - .5px), var(--ff-border) calc(66.66% - .5px), var(--ff-border) calc(66.66% + .5px), transparent calc(66.66% + .5px));
}

.logo-crop-zoom {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ff-text-muted);
}

.logo-crop-zoom input[type="range"] {
    flex: 1;
    accent-color: var(--ff-primary);
}

/* ---- User picker (/ManageApps → Access grant form) ---- */
.user-picker-text {
    display: grid;
    gap: 1px;
    min-width: 0;
}

.user-picker-email {
    font-size: var(--ff-text-xs);
    color: var(--ff-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- URL list fields (redirect / post-logout URIs on the /ManageApps form) ---- */
.uri-list {
    display: grid;
    gap: 8px;
}

.uri-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 6px;
    align-items: center;
}

.uri-row__error { grid-column: 1 / -1; }

.uri-list__actions {
    margin-top: 8px;
}

/* ---- Client secret generate / copy (/ManageApps form) ---- */
.hub-secret-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* ---- Launcher: search, favorites, show more (/Apps) ---- */
.launcher-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-bottom: 18px;
}

.launcher-search { width: min(360px, 100%); }

.launcher-section + .launcher-section { margin-top: 26px; }

.launcher-heading {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 10px;
    font-size: var(--ff-text-xs);
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ff-text-muted);
}

.launcher-heading svg { width: 14px; height: 14px; }

.app-tile-wrap { position: relative; }

.app-tile-wrap .app-tile { padding-right: 40px; }

.app-tile-fav {
    position: absolute;
    top: 8px;
    right: 8px;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: var(--ff-radius-md);
    background: transparent;
    color: var(--ff-text-faint);
    cursor: pointer;
    transition: color var(--ff-transition-base), background var(--ff-transition-base);
}

.app-tile-fav svg { width: 15px; height: 15px; }

.app-tile-fav:hover { color: var(--ff-text); background: var(--ff-surface-sunken); }

.app-tile-fav.is-active { color: var(--ff-warning, #eab308); }

.app-tile-fav.is-active svg { fill: currentColor; }

.app-tile-fav:focus-visible { outline: 2px solid var(--ff-ring); outline-offset: 1px; }

/* the lock sits left of the star when both are present */
.app-tile-wrap .app-tile-lock { right: 40px; }

.launcher-more {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
}

.launcher-more .ff-helper { margin-left: 4px; }

.launcher-empty { margin-top: 8px; }
