/* REV23 Cloud Studio - Identity Server Theme
   Dark glass cards with Blue → Cyan/Teal accent identity
   ========================================================================== */

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */
:root {
    /* Background */
    --bg: #1c1c21;

    /* Card (dark glass — matches REV23 Account) */
    --surface: rgba(42, 42, 48, 0.6);
    --surface-border: rgba(90, 90, 100, 0.35);
    --surface-hover: rgba(55, 55, 62, 0.7);

    /* Subsurface (for nested sections like local login) */
    --subsurface: rgba(24, 24, 27, 0.5);
    --subsurface-border: rgba(63, 63, 70, 0.4);

    /* Text (light for dark cards) */
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;

    /* Accent Colors — Cyan/Teal family */
    --blue: #3b82f6;
    --cyan: #06b6d4;
    --cyan-light: #22d3ee;
    --green: #34d399;
    --red: #f87171;
    --red-bg: rgba(239, 68, 68, 0.1);
    --red-border: rgba(239, 68, 68, 0.25);
    --yellow: #fbbf24;

    /* Gradients — Blue to Cyan */
    --gradient: linear-gradient(135deg, var(--blue) 0%, var(--cyan) 100%);

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    color-scheme: dark;
}

/* ==========================================================================
   Base Styles
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Atmospheric glow orbs — Blue + Cyan */
body::before,
body::after {
    content: '';
    position: fixed;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
}

body::before {
    background: var(--blue);
    top: -150px;
    right: -100px;
}

body::after {
    background: var(--cyan);
    bottom: -150px;
    left: -100px;
}

a {
    color: #67e8f9;
    text-decoration: none;
    transition: all 0.2s ease;
}

a:hover {
    color: var(--cyan-light);
}

/* ==========================================================================
   Layout
   ========================================================================== */
.main-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    position: relative;
    z-index: 1;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-sizing: border-box;
    max-width: 420px;
    padding: 2.5rem 2rem;
    width: 100%;
    position: relative;
    animation: cardIn 0.4s ease-out;
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Header / Branding
   ========================================================================== */
.auth-header {
    position: relative;
    margin-bottom: 1.75rem;
}

.auth-header .brand-logo {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
}

.auth-header .brand-logo .brand-rev23 {
    color: var(--text-primary);
}

.auth-header .brand-logo .brand-cloud-studio {
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-header .tenant-name {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
    letter-spacing: -0.01em;
}

.auth-header .tenant-logo {
    position: absolute;
    top: 0;
    right: 0;
    height: 36px;
    width: auto;
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   Page Titles
   ========================================================================== */
.page-title {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    text-align: center;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.page-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 1.25rem;
}

.page-description.text-center {
    text-align: center;
}

/* ==========================================================================
   Login Page - Dual Section Layout
   ========================================================================== */

/* REV23 Account Button */
.btn-rev23-id {
    background: var(--gradient);
    border: none;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
    box-sizing: border-box;
    color: #ffffff;
    display: block;
    font-size: 1.0625rem;
    font-weight: 700;
    max-width: 100%;
    padding: 1rem 1.5rem;
    position: relative;
    text-align: center;
    transition: all 0.3s ease;
    width: 100%;
    overflow: hidden;
    letter-spacing: -0.01em;
}

.btn-rev23-id:hover {
    color: #ffffff;
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.3), 0 4px 20px rgba(6, 182, 212, 0.2);
}

.btn-rev23-id:active {
    transform: translateY(0);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

.btn-rev23-id i {
    margin-right: 0.5rem;
}

.rev23-id-section {
    margin-bottom: 1.5rem;
}

.rev23-id-hint {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin-top: 0.75rem;
    text-align: center;
}

/* Divider */
.auth-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--surface-border);
}

.auth-divider span {
    padding: 0 1rem;
}

/* Local Login Section */
.local-login-section {
    background: var(--subsurface);
    border: 1px solid var(--subsurface-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    position: relative;
}

.local-login-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--cyan), var(--blue), transparent);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.local-login-header {
    color: var(--text-secondary);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.local-login-hint {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin-bottom: 1rem;
}

/* ==========================================================================
   Form Elements
   ========================================================================== */
.form-control {
    background: var(--subsurface) !important;
    border: 1px solid var(--surface-border) !important;
    border-radius: 10px !important;
    color: var(--text-primary) !important;
    font-family: inherit;
    font-size: 0.9rem !important;
    font-weight: 500;
    padding: 0.75rem 1rem !important;
    transition: all 0.2s ease;
    width: 100%;
    caret-color: var(--cyan-light);
}

.form-control::placeholder {
    color: #52525b !important;
}

.form-control:focus {
    background: var(--subsurface) !important;
    border-color: rgba(6, 182, 212, 0.5) !important;
    box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.15) !important;
    color: var(--text-primary) !important;
    outline: none;
}

/* Input styling within local login section */
.local-login-section .form-control {
    background: rgba(17, 17, 20, 0.5) !important;
    border: 1px solid rgba(63, 63, 70, 0.5) !important;
}

.local-login-section .form-control:focus {
    background: rgba(17, 17, 20, 0.5) !important;
    border-color: rgba(6, 182, 212, 0.5) !important;
}

.form-group {
    margin-bottom: 0.875rem;
}

label {
    color: var(--text-secondary);
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
}

/* Custom Checkbox */
.form-check {
    display: flex;
    align-items: center;
    padding-left: 0;
}

.form-check-input {
    appearance: none;
    -webkit-appearance: none;
    background: var(--subsurface) !important;
    border: 2px solid var(--surface-border) !important;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
    float: none !important;
    height: 18px !important;
    margin: 0 0.5rem 0 0 !important;
    position: relative;
    transition: all 0.2s ease;
    width: 18px !important;
}

.form-check-input:checked {
    background-color: var(--cyan) !important;
    border-color: var(--cyan) !important;
}

.form-check-input:checked::before {
    content: '\2713';
    color: white;
    font-size: 12px;
    font-weight: bold;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1;
}

.form-check-label {
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    margin-bottom: 0;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    border-radius: 10px !important;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem !important;
    font-weight: 600;
    padding: 0.75rem 1.25rem !important;
    text-align: center;
    transition: all 0.2s ease;
    letter-spacing: -0.01em;
}

.btn-primary {
    background: var(--gradient) !important;
    border: none !important;
    color: #ffffff !important;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.25), 0 4px 20px rgba(6, 182, 212, 0.15);
    color: #ffffff !important;
}

.btn-primary:active {
    transform: translateY(0);
    filter: brightness(0.95);
    box-shadow: none;
}

.btn-secondary {
    background: transparent !important;
    border: 1px solid var(--surface-border) !important;
    color: var(--text-secondary) !important;
}

.btn-secondary:hover {
    background: var(--surface-hover) !important;
    border-color: var(--text-muted) !important;
    color: var(--text-primary) !important;
}

.btn-danger {
    background: var(--red-bg) !important;
    border: 1px solid var(--red-border) !important;
    color: var(--red) !important;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2) !important;
    border-color: rgba(239, 68, 68, 0.4) !important;
    color: #fca5a5 !important;
}

.btn-sm {
    padding: 0.4rem 0.75rem !important;
    font-size: 0.8125rem !important;
}

.btn-block {
    display: block;
    width: 100%;
}

/* ==========================================================================
   Form Utilities
   ========================================================================== */
.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.form-link {
    color: #67e8f9;
    font-size: 0.8125rem;
    white-space: nowrap;
}

.form-link:hover {
    color: var(--cyan-light);
}

@media (max-width: 360px) {
    .form-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
}

/* ==========================================================================
   Alerts / Validation
   ========================================================================== */
.alert {
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    padding: 0.875rem 1rem;
}

.alert-danger {
    background: var(--red-bg);
    border: 1px solid var(--red-border);
    color: var(--red);
}

.alert-danger .alert-icon {
    color: var(--red);
    margin-right: 0.5rem;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: var(--green);
}

.alert-info {
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.25);
    color: var(--text-secondary);
}

/* Field Validation - Inline errors */
.form-control.input-validation-error {
    border-color: rgba(239, 68, 68, 0.5) !important;
    background-color: var(--red-bg) !important;
}

.form-control.input-validation-error:focus {
    border-color: rgba(239, 68, 68, 0.5) !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15) !important;
}

.field-validation-error {
    color: var(--red);
    font-size: 0.8125rem;
    display: block;
    margin-top: 0.375rem;
}

.field-validation-valid {
    display: none;
}

/* Model-level login error */
.login-error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--red);
    font-size: 0.8125rem;
    margin-bottom: 0.5rem;
}

.login-error i {
    flex-shrink: 0;
}

/* Login hint (e.g., REV23 Account suggestion) */
.login-hint {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--cyan-light);
    font-size: 0.8125rem;
    margin-bottom: 1rem;
}

.login-hint i {
    flex-shrink: 0;
    color: var(--yellow);
}

/* Summary validation (fallback) */
.validation-errors,
.validation-summary-errors {
    margin-bottom: 1rem;
}

.validation-errors ul,
.validation-summary-errors ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.validation-errors li,
.validation-summary-errors li {
    color: var(--red);
    font-size: 0.8125rem;
    padding: 0.25rem 0;
}

/* ==========================================================================
   Cards (for Consent page etc.)
   ========================================================================== */
.card {
    background: var(--subsurface);
    border: 1px solid var(--subsurface-border);
    border-radius: var(--radius-md);
    margin-bottom: 0.875rem;
    overflow: hidden;
}

.card-header {
    background: rgba(30, 30, 35, 0.6);
    border-bottom: 1px solid var(--subsurface-border);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.875rem 1rem;
}

.card-header i {
    color: var(--cyan);
    margin-right: 0.5rem;
}

.card-body {
    padding: 1rem;
}

.list-group {
    list-style: none;
    margin: 0;
    padding: 0;
}

.list-group-item {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--subsurface-border);
    color: var(--text-primary);
    padding: 0.875rem 1rem;
}

.list-group-item:last-child {
    border-bottom: none;
}

.list-group-item label {
    color: var(--text-primary);
    display: inline;
    margin-bottom: 0;
}

.consent-description {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin-top: 0.25rem;
    padding-left: 1.625rem;
}

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

/* Consent Page Header */
.consent-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--surface-border);
}

.consent-app-logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    flex-shrink: 0;
}

.consent-app-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: rgba(6, 182, 212, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cyan);
    font-size: 1.25rem;
    flex-shrink: 0;
}

.consent-header-text {
    flex: 1;
    min-width: 0;
}

.consent-header-text .page-title {
    text-align: left;
    margin-bottom: 0.125rem;
    font-size: 1.125rem;
}

.consent-header-text .page-description {
    text-align: left;
    margin-bottom: 0;
    font-size: 0.875rem;
}

/* ==========================================================================
   Grants / Diagnostics
   ========================================================================== */
.section-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--surface-border);
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

.grant-card {
    background: var(--subsurface);
    border: 1px solid var(--subsurface-border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.grant-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.grant-client {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.grant-logo {
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.grant-details {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.75rem;
    font-size: 0.8125rem;
    margin-bottom: 0;
}

.grant-details dt {
    color: var(--text-muted);
    font-weight: 500;
}

.grant-details dd {
    color: var(--text-secondary);
    margin-bottom: 0;
    word-break: break-word;
}

.text-break {
    word-break: break-all;
}

/* ==========================================================================
   Error/Status Pages
   ========================================================================== */
.status-page {
    text-align: center;
}

.status-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    color: var(--cyan);
}

.status-icon.success {
    color: var(--green);
}

.status-icon.error {
    color: var(--red);
}

.status-icon.warning {
    color: var(--yellow);
}

/* Redirect / Loading Spinner */
.redirect-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--surface-border);
    border-top-color: var(--cyan);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Button with icon */
.btn i {
    margin-right: 0.5rem;
}

/* Info Callout */
.info-callout {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    background: rgba(6, 182, 212, 0.08);
    border: 1px solid rgba(6, 182, 212, 0.2);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-top: 1.5rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.info-callout > i {
    flex-shrink: 0;
    margin-top: 0.125rem;
    color: var(--cyan);
}

.info-callout strong {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.info-callout a {
    color: #67e8f9;
    text-decoration: underline;
}

.info-callout a:hover {
    color: var(--cyan-light);
}

/* Back Link */
.back-link {
    color: var(--text-muted);
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: var(--text-primary);
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.875rem; }
.mb-4 { margin-bottom: 1.25rem; }
.mb-5 { margin-bottom: 1.5rem; }

.mt-3 { margin-top: 0.875rem; }
.mt-4 { margin-top: 1.25rem; }

.pt-3 { padding-top: 0.875rem; }

.small { font-size: 0.8125rem; }
.font-weight-bold { font-weight: 600; }

.gap-2 { gap: 0.5rem; }
.flex-fill { flex: 1 1 auto; }
.d-flex { display: flex; }

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */
@media (max-width: 576px) {
    body {
        align-items: flex-start;
    }

    body::before, body::after {
        width: 300px;
        height: 300px;
    }

    .main-container {
        padding: 0;
    }

    .auth-card {
        max-width: 100%;
        border-radius: 0;
        border: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--bg);
        padding: 2rem 1.5rem;
        padding-top: max(2rem, env(safe-area-inset-top));
        padding-bottom: max(2rem, env(safe-area-inset-bottom));
    }

    .local-login-section {
        padding: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    body::before,
    body::after {
        display: none;
    }

    .auth-card {
        animation: none;
    }
}

/* ==========================================================================
   Focus States for Accessibility
   ========================================================================== */
.btn:focus,
a:focus {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
}

.btn:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

/* Override Bootstrap focus-visible box-shadow */
.form-control:focus-visible {
    box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.15) !important;
}
