/* =========================================================
   CRKD LOGIN
   Uses the same design tokens as the management pages
   (design/dashboard.css), so both areas match.

   The dark theme is the default; html[data-theme="light"]
   swaps the colour tokens. Text colours meet WCAG 2.2 AA
   contrast (4.5:1) on the surfaces they are used on, and
   control borders and focus rings meet 3:1.
========================================================= */

/* =========================
   DESIGN TOKENS (copied from dashboard.css)
========================= */
:root {
    color-scheme: dark;

    /* Chrome: the logo band. It follows the theme like the management
       sidebar and top bar; the logo is inverted in the light theme. */
    --chrome-bg: #000000;
    --chrome-border: #262626;
    --chrome-text-strong: #ffffff;
    --focus-chrome: #8ab4f8;

    /* Dark theme colours */
    --color-bg: #0d0d0d;
    --color-surface: #161616;
    --color-surface-2: #1f1f1f;
    --color-surface-3: #2a2a2a;
    --color-border: #2e2e2e;
    --color-border-strong: #7a7a7a;
    --color-text: #f5f5f5;
    --color-text-muted: #c2c2c2;
    --color-text-subtle: #a3a3a3;
    --color-input-bg: #1f1f1f;
    --color-overlay: rgba(0, 0, 0, 0.72);

    --color-primary: #ffffff;
    --color-primary-hover: #e2e2e2;
    --color-on-primary: #0d0d0d;

    --color-success: #4ade80;
    --color-danger: #f87171;
    --color-danger-solid: #dc2626;
    --color-danger-solid-hover: #b91c1c;

    --focus-theme: #8ab4f8;
    --color-focus: var(--focus-theme);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);

    /* Sizes */
    --control-height: 40px;
    --button-min-width: 120px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --font-family: Arial, Helvetica, sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 13px;
    --font-size-md: 14px;
    --font-size-lg: 16px;

    --theme-transition-duration: 300ms;

    --z-modal: 2000;
    --z-dialog: 9999;
}

html[data-theme="light"] {
    color-scheme: light;

    --chrome-bg: #ffffff;
    --chrome-border: #dcdcdc;
    --chrome-text-strong: #171717;
    --focus-chrome: #1a56db;

    --color-bg: #f4f4f5;
    --color-surface: #ffffff;
    --color-surface-2: #f0f0f0;
    --color-surface-3: #e4e4e4;
    --color-border: #dcdcdc;
    --color-border-strong: #7a7a7a;
    --color-text: #171717;
    --color-text-muted: #404040;
    --color-text-subtle: #595959;
    --color-input-bg: #ffffff;
    --color-overlay: rgba(0, 0, 0, 0.55);

    --color-primary: #111111;
    --color-primary-hover: #333333;
    --color-on-primary: #ffffff;

    --color-success: #166534;
    --color-danger: #b91c1c;
    --color-danger-solid: #b91c1c;
    --color-danger-solid-hover: #991b1b;

    --focus-theme: #1a56db;
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.18);
}

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

body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 100vh;
    margin: 0;
    padding: 16px;
    /* The soft glow is the same in both themes; only the background colour changes,
       so the theme switch can fade it (gradients cannot be faded). */
    background-color: var(--color-bg);
    background-image: radial-gradient(circle at center, rgba(255, 255, 255, 0.06) 0%, transparent 65%);
    background-attachment: fixed;
    color: var(--color-text);
    font-family: var(--font-family);
    font-size: var(--font-size-lg);
    line-height: 1.5;
}

button,
input {
    font: inherit;
}

/* Visible keyboard focus on every interactive element (WCAG 2.4.7). */
:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

/* Theme switch: theme.js adds this class for a moment so colours fade
   between light and dark instead of flashing. It only fades colours
   (no movement), so it stays on for people who prefer reduced motion. */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
    transition-property: background-color, color, border-color, outline-color, fill, stroke, box-shadow, filter !important;
    transition-duration: var(--theme-transition-duration) !important;
    transition-timing-function: ease-in-out !important;
    transition-delay: 0s !important;
}

/* =========================
   BUTTONS (same as dashboard.css)
========================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: var(--button-min-width);
    min-height: var(--control-height);
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--font-size-md);
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-icon {
    min-width: 0;
    width: var(--control-height);
    padding: 0;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-on-primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-surface-2);
    border-color: var(--color-border-strong);
    color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface-3);
}

.btn-danger {
    background: var(--color-danger-solid);
    border-color: var(--color-danger-solid);
    color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
    background: var(--color-danger-solid-hover);
    border-color: var(--color-danger-solid-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--color-surface-2);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* A button that looks like a text link (it opens a dialog, so it is not a real link). */
.link-button {
    min-height: var(--control-height);
    padding: 0 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

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

/* =========================
   FORM CONTROLS
========================= */
input[type="text"],
input[type="password"] {
    width: 100%;
    min-height: var(--control-height);
    padding: 0 12px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-input-bg);
    color: var(--color-text);
    font-size: var(--font-size-md);
}

input::placeholder {
    color: var(--color-text-subtle);
    opacity: 1;
}

input:focus-visible {
    border-color: var(--color-focus);
    outline-offset: 1px;
}

input[aria-invalid="true"] {
    border-color: var(--color-danger);
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    text-align: left;
}

.form-field label {
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

/* Status line under a form: "Logging in...", errors and success messages. */
.form-message {
    min-height: 1.5em;
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
    text-align: center;
}

.form-message.is-error {
    color: var(--color-danger);
}

.form-message.is-success {
    color: var(--color-success);
}

/* =========================
   LOGIN CARD
========================= */
.login-toolbar {
    display: flex;
    justify-content: flex-end;
}

.login-card {
    width: min(100%, 440px);
    margin: auto;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
}

.login-brand {
    --color-focus: var(--focus-chrome);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 24px 24px;
    border-bottom: 1px solid var(--chrome-border);
    background: var(--chrome-bg);
    color: var(--chrome-text-strong);
}

.logo-img {
    display: block;
    width: 140px;
    height: auto;
}

/* The logo is white on black; inverting it gives black on white for the light theme. */
html[data-theme="light"] .logo-img {
    filter: invert(1);
}

.login-title {
    margin: 0;
    color: var(--chrome-text-strong);
    font-family: 'UnifrakturMaguntia', serif;
    font-size: 48px;
    font-weight: 400;
    line-height: 1.1;
    text-align: center;
}

.login-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 28px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-form .btn {
    margin-top: 4px;
}

.login-extras {
    text-align: center;
}

/* =========================
   OWNER RECOVERY MODAL
========================= */
.modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
    background: var(--color-overlay);
    animation: fade-in 0.15s ease-out;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    width: min(100%, 440px);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    padding: 28px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
    animation: rise-in 0.2s ease-out;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.modal-header h2 {
    margin: 0;
    color: var(--color-text);
    font-size: 20px;
    line-height: 1.25;
}

.modal-header p {
    margin: 6px 0 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
}

.modal-actions .btn {
    min-width: 140px;
}

/* The confirmation dialog (showDialog in index.js) is styled in components.css. */

body.modal-open {
    overflow: hidden;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes rise-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================
   REDUCED MOTION
   Movement is replaced by a plain fade (WCAG 2.3.3).
========================= */
@media (prefers-reduced-motion: reduce) {
    .modal-content {
        animation-name: fade-in;
    }
}

/* =========================
   RESPONSIVE
========================= */
@media (max-width: 520px) {
    .login-body,
    .modal-content {
        padding: 20px;
    }

    .modal {
        padding: 16px;
    }

    .logo-img {
        width: 112px;
    }

    .login-title {
        font-size: 40px;
    }

    .modal-actions,
    .dialog-actions {
        flex-direction: column-reverse;
    }

    .modal-actions .btn,
    .dialog-actions .btn {
        width: 100%;
    }
}
