/* ==========================================================================
   Loftybits app styles (admin, account, and shared components)
   Fully custom: no Bootstrap. Brand tokens (--navy-*, --indigo-*, --sky-*,
   --emerald-*, --slate-*, radii, shadows, font) are defined in loftybits.css.

   Theme variables below default to the light admin theme. The public site
   wrapper (.lb-site in loftybits.css) re-points them to the dark brand theme,
   so shared components such as .section-card work in both places.
   ========================================================================== */

:root {
    --page-bg: var(--slate-50);
    --panel-bg: #ffffff;
    --panel-border: var(--slate-200);
    --ink: var(--navy-900);
    --muted: var(--slate-600);
    --accent: var(--indigo-600);
    --accent-2: var(--emerald-600);
    --accent-soft: #eef2ff;
    --shadow: var(--shadow-card);
    --field-bg: #ffffff;
    --field-border: var(--slate-300);
    --danger: #dc2626;
}

/* ---- Base reset ------------------------------------------------------- */

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--page-bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 0.5rem;
    color: var(--ink);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h1 { font-size: clamp(1.75rem, 1.4rem + 1.2vw, 2.25rem); font-weight: 800; letter-spacing: -0.03em; }
h2 { font-size: clamp(1.35rem, 1.2rem + 0.6vw, 1.6rem); }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
h5, h6 { font-size: 1rem; }

p,
ul,
ol,
dl {
    margin-top: 0;
    margin-bottom: 1rem;
}

ul,
ol {
    padding-left: 1.5rem;
}

dd {
    margin-left: 0;
    margin-bottom: 0.5rem;
}

b,
strong {
    font-weight: 700;
}

small,
.small {
    font-size: 0.875em;
}

a {
    color: var(--accent);
    text-underline-offset: 3px;
}

img,
svg {
    vertical-align: middle;
}

hr {
    margin: 1.25rem 0;
    border: 0;
    border-top: 1px solid var(--panel-border);
}

table {
    border-collapse: collapse;
    caption-side: bottom;
}

th {
    text-align: inherit;
}

label {
    display: inline-block;
}

button,
input,
select,
textarea {
    margin: 0;
    font: inherit;
    color: inherit;
}

button,
[role="button"] {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
}

textarea {
    resize: vertical;
}

code {
    padding: 0.1rem 0.35rem;
    border-radius: 0.35rem;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.875em;
}

[hidden] {
    display: none !important;
}

h1:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--sky-400);
    outline-offset: 2px;
}

/* ---- Layout helpers ----------------------------------------------------- */

.container,
.container-fluid {
    width: 100%;
    margin-inline: auto;
    padding-inline: var(--gutter);
}

.container {
    max-width: calc(var(--container) + var(--gutter) * 2);
}

.row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem 2rem;
}

.row > * {
    flex: 1 1 100%;
    min-width: 0;
}

@media (min-width: 768px) {
    .col-md-4 { flex: 0 1 calc(33.333% - 1.4rem); }
    .col-md-6 { flex: 0 1 calc(50% - 1rem); }
    .col-md-12 { flex: 1 1 100%; }
}

@media (min-width: 992px) {
    .col-lg-8 { flex: 0 1 66.666%; }
}

@media (min-width: 1200px) {
    .col-xl-6 { flex: 0 1 calc(50% - 1rem); }
}

.d-flex { display: flex; }
.d-grid { display: grid; }
.flex-column { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.justify-content-center { justify-content: center; }
.justify-content-end { justify-content: flex-end; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.w-100 { width: 100%; }
.h-100 { height: 100%; }
.mx-auto { margin-inline: auto; }
.mb-0 { margin-bottom: 0 !important; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.py-4 { padding-block: 1.5rem; }
.py-5 { padding-block: 3rem; }
.px-3 { padding-inline: 1rem; }
.px-4 { padding-inline: 1.5rem; }
.text-center { text-align: center; }
.text-end { text-align: right; }
.text-muted,
.text-secondary { color: var(--muted) !important; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--accent-2) !important; }
.text-info { color: var(--sky-500) !important; }
.font-weight-bold { font-weight: 700; }

/* ---- Buttons ------------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.6rem;
    padding: 0.55rem 1.15rem;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: var(--ink);
    font-size: 0.94rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: none;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.btn-lg {
    min-height: 3rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-sm {
    min-height: 2.1rem;
    padding: 0.35rem 0.85rem;
    font-size: 0.85rem;
}

.btn-primary {
    background: var(--indigo-600);
    color: #fff;
    box-shadow: 0 8px 20px -10px rgba(79, 70, 229, 0.8);
}

.btn-primary:hover {
    background: var(--indigo-500);
    color: #fff;
}

.btn-outline-dark {
    border-color: var(--field-border);
    background: var(--panel-bg);
    color: var(--ink);
}

.btn-outline-dark:hover {
    border-color: var(--slate-400);
    background: var(--slate-100);
    color: var(--ink);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
    color: #fff;
}

.btn-outline-danger {
    border-color: #fecaca;
    background: #fff;
    color: #b91c1c;
}

.btn-outline-danger:hover {
    border-color: var(--danger);
    background: #fef2f2;
    color: #991b1b;
}

.btn-link {
    min-height: auto;
    padding-inline: 0.25rem;
    color: var(--accent);
    font-weight: 600;
}

.btn-link:hover {
    text-decoration: underline;
    transform: none;
}

/* ---- Forms --------------------------------------------------------------- */

.form-label,
.control-label,
.field-group > label {
    margin-bottom: 0.35rem;
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 600;
}

.form-control,
.form-select {
    display: block;
    width: 100%;
    min-height: 2.75rem;
    padding: 0.6rem 0.9rem;
    border: 1.5px solid var(--field-border);
    border-radius: var(--radius-sm);
    background-color: var(--field-bg);
    color: var(--ink);
    line-height: 1.5;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.form-control::placeholder {
    color: var(--slate-400);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--indigo-600);
    outline: none;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.16);
}

.form-control:disabled,
.form-select:disabled,
.form-control[readonly] {
    background-color: var(--slate-100);
    color: var(--muted);
}

textarea.form-control {
    min-height: 7rem;
}

.form-select {
    padding-right: 2.5rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-position: right 0.85rem center;
    background-repeat: no-repeat;
    background-size: 1rem;
}

/* Identity pages use "floating" label markup (input, then label). Render it as a
   simple stacked field with the label above the input instead. */
.form-floating {
    display: flex;
    flex-direction: column;
}

.form-floating > label {
    order: -1;
    margin-bottom: 0.35rem;
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 600;
}

.form-floating > .text-danger,
.form-floating > .validation-message {
    margin-top: 0.35rem;
    font-size: 0.86rem;
}

.form-check-input,
.darker-border-checkbox {
    width: 1.1rem;
    height: 1.1rem;
    margin: 0 0.5rem 0 0;
    vertical-align: -0.15rem;
    accent-color: var(--indigo-600);
}

.checkbox label {
    display: inline-flex;
    align-items: center;
    font-weight: 500;
}

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group > .form-control {
    flex: 1 1 auto;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group-append,
.input-group-text {
    display: flex;
    align-items: center;
}

.input-group-text {
    padding-inline: 0.85rem;
    border: 1.5px solid var(--field-border);
    border-left: 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--slate-100);
}

/* A labelled field with an addon (e.g. the confirmed-email check on Manage > Email): the markup is
   both .form-floating (stacked) and .input-group (side by side). Put the label on its own row and
   keep the input and addon together on the next. */
.form-floating.input-group {
    flex-direction: row;
    flex-wrap: wrap;
}

.form-floating.input-group > label {
    flex: 0 0 100%;
}

.form-floating.input-group > .form-control {
    flex: 1 1 0;
    min-width: 0;
}

.input-group-text.text-success {
    border-color: #a7f3d0;
    background: #ecfdf5;
    font-weight: 800;
}

.validation-message {
    color: var(--danger);
    font-size: 0.86rem;
}

.valid.modified:not([type=checkbox]) {
    border-color: var(--emerald-500);
}

.invalid {
    border-color: var(--danger) !important;
}

/* ---- Alerts --------------------------------------------------------------- */

.alert {
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    background: var(--slate-100);
    color: var(--ink);
    line-height: 1.55;
}

.alert-success { border-color: #a7f3d0; background: #ecfdf5; color: #065f46; }
.alert-info { border-color: #bae6fd; background: #f0f9ff; color: #075985; }
.alert-warning { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.alert-danger { border-color: #fecaca; background: #fef2f2; color: #991b1b; }

/* ---- Tables -------------------------------------------------------------- */

.table {
    width: 100%;
    margin-bottom: 0;
    color: var(--ink);
    font-size: 0.94rem;
}

.table th {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--panel-border);
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--panel-border);
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.table-hover tbody tr {
    transition: background-color 120ms ease;
}

.table-hover tbody tr:hover {
    background: var(--slate-50);
}

.table a {
    font-weight: 700;
    text-decoration: none;
}

.table a:hover {
    text-decoration: underline;
}

.table-shell {
    overflow-x: auto;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    background: var(--panel-bg);
    box-shadow: var(--shadow);
}

/* ---- Shared cards (used by admin and, re-themed, by the public site) ---- */

.section-kicker {
    display: inline-flex;
    align-items: center;
    margin-bottom: 0.75rem;
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.section-card,
.legal-shell,
.admin-shell,
.ticket-shell {
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    background: var(--panel-bg);
    box-shadow: var(--shadow);
}

.section-card {
    padding: 1.6rem;
}

.section-card h2 {
    font-size: 1.3rem;
}

.section-card p,
.legal-shell p {
    color: var(--muted);
}

.compact-card {
    max-width: 40rem;
}

.loading-card {
    padding: 2rem;
    color: var(--muted);
}

.loading-card p::before {
    content: "";
    display: inline-block;
    width: 0.9rem;
    height: 0.9rem;
    margin-right: 0.6rem;
    vertical-align: -0.1rem;
    border: 2px solid var(--panel-border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: lb-spin 800ms linear infinite;
}

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

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.display-title {
    font-size: clamp(2rem, 1.6rem + 2vw, 3rem);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.08;
}

.eyebrow {
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.hero-copy {
    color: var(--muted);
    font-size: 1.08rem;
    line-height: 1.75;
}

/* Legal documents */

.legal-shell {
    max-width: 960px;
    padding: clamp(1.5rem, 4vw, 2.25rem);
}

.legal-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.legal-content {
    display: grid;
    gap: 0.25rem;
}

.legal-content h2 {
    margin-top: 1.5rem;
    font-size: 1.4rem;
}

.legal-content h3 {
    margin-top: 0.85rem;
    font-size: 1.1rem;
}

.legal-content :is(p, li) {
    color: var(--muted);
    line-height: 1.75;
}

.legal-content li {
    margin-bottom: 0.5rem;
}

/* App support pages */

.app-shell {
    display: grid;
    gap: 1.25rem;
}

.app-shell-title {
    max-width: 26ch;
    font-size: clamp(1.8rem, 1.4rem + 1.6vw, 2.6rem);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.08;
}

.app-shell-copy {
    max-width: 46rem;
    color: var(--muted);
    font-size: 1.05rem;
    line-height: 1.75;
}

.app-shell-link-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.app-support-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
}

.app-support-grid .section-card:last-child {
    grid-column: 1 / -1;
}

.app-support-grid :is(ul, ol) {
    color: var(--muted);
    line-height: 1.75;
}

/* ---- Admin views --------------------------------------------------------- */

.admin-shell {
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.admin-header,
.ticket-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem 2rem;
    margin-bottom: 1.75rem;
}

.admin-header p,
.ticket-header p {
    max-width: 44rem;
    margin: 0;
    color: var(--muted);
}

.admin-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.stat-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1.25rem 1.35rem;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    background: var(--panel-bg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.stat-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: var(--grad-brand);
}

.stat-card strong {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
}

.admin-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
    align-items: end;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding: 1.1rem 1.25rem;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    background: var(--panel-bg);
    box-shadow: var(--shadow);
}

.field-group {
    display: grid;
    gap: 0.35rem;
}

.ticket-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.table .ticket-actions {
    flex-wrap: nowrap;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.status-pill::before {
    content: "";
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: currentColor;
}

.status-open { background: #eef2ff; color: var(--indigo-600); }
.status-awaiting { background: #fffbeb; color: #b45309; }
.status-resolved { background: #ecfdf5; color: var(--emerald-600); }
.status-closed { background: var(--slate-100); color: var(--slate-600); }

/* Ticket detail */

.ticket-shell {
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.ticket-shell.compact-card,
.ticket-shell.loading-card {
    padding: 2rem;
    border: 1px solid var(--panel-border);
    background: var(--panel-bg);
    box-shadow: var(--shadow);
}

.ticket-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(18rem, 1fr);
    gap: 1.25rem;
    align-items: start;
}

.ticket-thread {
    display: grid;
    gap: 1rem;
}

.ticket-entry {
    padding: 1.25rem 1.35rem;
    border: 1px solid var(--panel-border);
    border-left: 4px solid var(--indigo-500);
    border-radius: var(--radius-md);
    background: var(--panel-bg);
    box-shadow: var(--shadow);
}

.ticket-entry.admin-entry {
    border-left-color: var(--emerald-500);
    background: #f8fffc;
}

.ticket-entry-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-bottom: 0.75rem;
    color: var(--muted);
    font-size: 0.86rem;
}

.ticket-message {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.7;
}

.ticket-meta-grid {
    display: grid;
    gap: 1rem;
}

.ticket-meta-card .ticket-meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 0.75rem;
}

.ticket-meta-card {
    padding: 1.15rem 1.25rem;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-md);
    background: var(--panel-bg);
    box-shadow: var(--shadow);
}

.ticket-meta-label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.ticket-meta-value {
    font-weight: 600;
    word-break: break-word;
}

.reply-form {
    display: grid;
    gap: 0.75rem;
}

/* Account "manage" pages: recovery codes */

.recovery-code {
    display: inline-block;
    margin: 0.25rem 0.5rem 0.25rem 0;
    padding: 0.35rem 0.6rem;
    border-radius: 0.4rem;
    background: var(--slate-100);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---- Framework UI -------------------------------------------------------- */

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 1000;
    width: 100%;
    padding: 0.8rem 3rem 0.9rem 1.25rem;
    background: #fef3c7;
    color: #451a03;
    font-weight: 600;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.2);
}

#blazor-error-ui .dismiss {
    position: absolute;
    top: 0.6rem;
    right: 0.9rem;
    cursor: pointer;
}

.blazor-error-boundary {
    padding: 1rem 1.25rem;
    border-left: 4px solid var(--danger);
    border-radius: var(--radius-sm);
    background: #7f1d1d;
    color: #fff;
}

.blazor-error-boundary::after {
    content: "Something went wrong displaying this section.";
}

/* ---- Responsive ---------------------------------------------------------- */

@media (max-width: 1100px) {
    .ticket-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .admin-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .admin-toolbar {
        grid-template-columns: 1fr;
    }

    .app-support-grid {
        grid-template-columns: 1fr;
    }
}

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