:root {
    /* Surfaces / page chrome */
    --neutral-layer-1: #f5ebdf;
    --neutral-layer-2: #f0e2d2;
    --surface-card: #fefbf7;
    --surface-elevated: #ffffff;
    --bg-page: #fbf6ef;
    --bg-sidebar: #f4ede5;
    --bg-topbar: #ffffff;
    --bg-rightpanel: #f8f2ea;

    /* Text */
    --text-primary: #1f1f1f;
    --text-secondary: #555555;
    --text-tertiary: #777777;
    --text-muted: #999999;

    /* Accents (coral) */
    --accent: #D85A30;
    --accent-deep: #B14A23;
    --accent-hover: #993C1D;
    --accent-tint: #f3d4c1;
    --on-accent: #ffffff;

    /* Org avatar fallback */
    --org-avatar: #2d7878;

    /* Borders */
    --border-soft: #e0d8c9;
    --border-input: #c9c2b3;

    /* Danger */
    --danger: #c14a3c;
    --danger-hover: #a23a2d;
    --danger-tint: #fcebea;

    /* Hover overlay used on neutral buttons / nav items. Slightly different
       per mode: a dark wash on light surfaces, a light wash on dark. */
    --hover-overlay: rgba(0, 0, 0, 0.05);
    --hover-overlay-strong: rgba(0, 0, 0, 0.08);

    /* Backdrops dim the page on top of either mode — kept rgba black so
       both modes render the same overlay. */
    --backdrop-strong: rgba(0, 0, 0, 0.35);
    --backdrop-soft: rgba(0, 0, 0, 0.25);

    --font-serif: "Instrument Serif", Georgia, "Times New Roman", serif;
    --font-sans: "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    color-scheme: light;
}

/* Dark mode tokens. Applied either by an explicit user choice (data-theme on
   <html> set by wwwroot/js/theme.js) or by the OS preference when the user
   has chosen "Auto" — the JS resolves "Auto" to one of light/dark before
   stamping data-theme, so the @media query below only acts as a graceful
   fallback when the JS hasn't run yet (initial flash protection lives in the
   inline <script> in App.razor's <head>). */
:root[data-theme="dark"] {
    --neutral-layer-1: #181614;
    --neutral-layer-2: #221f1c;
    --surface-card: #2a2724;
    --surface-elevated: #34302c;
    --bg-page: #181614;
    --bg-sidebar: #221f1c;
    --bg-topbar: #1e1b18;
    --bg-rightpanel: #1d1b18;

    --text-primary: #f0ebe0;
    --text-secondary: #b8b1a3;
    --text-tertiary: #8d8478;
    --text-muted: #6f6759;

    --accent: #F0997B;
    --accent-deep: #F5C4B3;
    --accent-hover: #F5C4B3;
    --accent-tint: #4A1B0C;
    --on-accent: #1a0e07;

    --border-soft: #3a3631;
    --border-input: #4a463f;

    --danger: #e07467;
    --danger-hover: #f0917e;
    --danger-tint: #3a1a16;

    --hover-overlay: rgba(255, 255, 255, 0.06);
    --hover-overlay-strong: rgba(255, 255, 255, 0.1);

    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) {
        --neutral-layer-1: #181614;
        --neutral-layer-2: #221f1c;
        --surface-card: #2a2724;
        --surface-elevated: #34302c;
        --bg-page: #181614;
        --bg-sidebar: #221f1c;
        --bg-topbar: #1e1b18;
        --bg-rightpanel: #1d1b18;

        --text-primary: #f0ebe0;
        --text-secondary: #b8b1a3;
        --text-tertiary: #8d8478;
        --text-muted: #6f6759;

        --accent: #F0997B;
        --accent-deep: #F5C4B3;
        --accent-hover: #F5C4B3;
        --accent-tint: #4A1B0C;
        --on-accent: #1a0e07;

        --border-soft: #3a3631;
        --border-input: #4a463f;

        --danger: #e07467;
        --danger-hover: #f0917e;
        --danger-tint: #3a1a16;

        --hover-overlay: rgba(255, 255, 255, 0.06);
        --hover-overlay-strong: rgba(255, 255, 255, 0.1);

        color-scheme: dark;
    }
}

html, body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-primary);
    margin: 0;
}

/* Lock scroll behind the mobile sidebar overlay. */
@media (max-width: 768px) {
    body.menu-open {
        overflow: hidden;
    }
}

/* Lock scroll behind the right-panel drawer on non-desktop widths. */
@media (max-width: 1180px) {
    body.right-panel-open {
        overflow: hidden;
    }
}

h1, h2, h3 {
    color: var(--text-primary);
}

h1 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 1.875rem;
}

.plus-icon {
    display: inline-block;
    margin-right: 0.25rem;
    font-size: 1.1em;
    line-height: 1;
    font-weight: 400;
    transform: translateY(-0.5px);
}

.crumbtrail {
    margin-bottom: 0.6rem;
    font-size: 0.85rem;
}

/* Card primitive — see Components/Shared/Card.razor. The component is just a
   typed wrapper around this markup, so raw <section class="card"> still works
   for variants (status-card, grid-card) that need direct flex children. */
.card {
    width: 100%;
    box-sizing: border-box;
    background: var(--surface-card);
    border: 0.5px solid var(--border-soft);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-bottom: 12px;
    border-bottom: 0.5px solid var(--border-soft);
}

.card-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card-header-row {
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
}

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

.card-header-row .card-header-actions {
    flex-shrink: 0;
}

.card-title {
    margin: 0;
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}

.card-header .muted {
    color: var(--text-secondary);
    font-size: 13px;
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card-body .empty {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/*
   FluentButton with class="danger-action" renders destructive actions in coral-red.
   We target the inner `<button>` because FluentButton wraps a host element that
   then injects the actual interactive element.
*/
fluent-button.danger-action::part(control),
.danger-action::part(control) {
    color: var(--danger);
}

fluent-button.danger-action:hover::part(control),
.danger-action:hover::part(control) {
    color: var(--danger-hover);
}

/* For Appearance.Accent buttons (coral fill), red text would be unreadable.
   Override to red fill + white text so the destructive action still reads as
   "danger" but has proper contrast. */
fluent-button.danger-action[appearance="accent"]::part(control) {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

fluent-button.danger-action[appearance="accent"]:hover::part(control) {
    background: var(--danger-hover);
    color: #fff;
    border-color: var(--danger-hover);
}

/* Form primitives used by static-SSR pages (Login, InviteRegister) where we keep
   Blazor's <InputText> for form binding. */
.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

/* :not([type]) catches Blazor's <InputText> which renders <input> without an
   explicit type attribute (HTML treats it as type="text" but the attribute
   selector won't match). */
.field input:not([type]),
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[readonly],
.field textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid #e3ddd6;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    box-sizing: border-box;
}

.field input:not([type]),
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field textarea {
    background: #fbf6ef;
}

.field textarea {
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
}

.field input[readonly] {
    background: var(--neutral-layer-2);
    color: var(--text-secondary);
}

/* Pin Fluent input fills + 1px stroke so textboxes blend into the page.
   Overriding Fluent's design tokens on the host element propagates into the
   shadow DOM and preserves the focus/hover ring behaviour. The ::part(control)
   fallback covers the few controls that paint the inner element directly. */
fluent-text-field,
fluent-text-area,
fluent-search,
fluent-number-field,
fluent-select,
fluent-combobox,
fluent-autocomplete {
    --neutral-fill-input-rest: #fbf6ef;
    --neutral-fill-input-hover: #fbf6ef;
    --neutral-fill-input-active: #fbf6ef;
    --neutral-fill-input-focus: #fbf6ef;
    --neutral-stroke-input-rest: #e3ddd6;
    --neutral-stroke-input-hover: #e3ddd6;
    --neutral-stroke-input-active: #e3ddd6;
    --neutral-stroke-input-focus: #e3ddd6;
    --stroke-width: 1px;
}

fluent-text-field::part(control),
fluent-text-area::part(control),
fluent-search::part(control),
fluent-number-field::part(control),
fluent-select::part(control),
fluent-combobox::part(control) {
    background: #fbf6ef;
    border: 1px solid #e3ddd6;
}

/* Dropdown options: Fluent paints content flush to the left edge by default
   and renders the selected-state accent rail inside the option's content
   area. Host padding (for vertical breathing room + right margin) plus
   ::part(content) padding-inline-start so the text clears the rail. */
fluent-option {
    padding: 6px 12px;
}

fluent-option::part(content) {
    padding-inline-start: 12px;
}

.validation-message {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* Page wrappers shared by anonymous flows */
.invite-page,
.denied-card,
.login-card {
    max-width: 480px;
    margin: 3rem auto;
    background: var(--surface-card);
    border: 0.5px solid var(--border-soft);
    border-radius: 10px;
    padding: 1.75rem 2rem;
}

.login-card {
    max-width: 360px;
}

.invite-page h1,
.denied-card h1,
.login-card h1 {
    margin-top: 0;
}

.invite-actions {
    margin-top: 1.25rem;
}

/* Toggle link between login modes (password vs. magic link). */
.mode-toggle {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.85rem;
}

.mode-toggle a {
    color: var(--accent);
    text-decoration: none;
}

.mode-toggle a:hover {
    text-decoration: underline;
}

/* Full-width submit FluentButton (used on auth pages). */
.submit-full {
    width: 100%;
    margin-top: 0.5rem;
}

.submit-full::part(control) {
    width: 100%;
    justify-content: center;
}

/* Dimmed hint text inside Fluent forms */
.hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* List-page pager (used by Feed, Calendar, Tickets, Members). */
.pager {
    margin-top: 1.5rem;
}

/* FluentMessageBar in dark mode: Fluent's component is on System theme, so
   when the OS is in light mode the bar renders its light pastel backgrounds
   (success-green, error-red, etc.) regardless of our user-toggle. Our
   body-level `color: var(--text-primary)` then leaks in as light text on
   the pastel background, which is unreadable. Pin the text color inside
   the bar back to a near-black so the contrast is sane, and keep the
   override scoped to data-theme="dark" so the light-mode appearance is
   untouched. Targets both the host element and its slot/parts. */
:root[data-theme="dark"] fluent-message-bar,
:root[data-theme="dark"] fluent-message-bar::part(message-container),
:root[data-theme="dark"] fluent-message-bar [slot] {
    color: #1f1f1f;
}

/* Full-viewport invisible button that catches outside-clicks for any open
   dropdown / popover (UserMenu, OrgSwitcher, NotificationBell, RowActionMenu).
   Sits below the popover (z-index: 19) so the popover (z-index: 20+) is still
   clickable. Promoted here so each new popover doesn't have to re-declare. */
.dropdown-backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: default;
    z-index: 19;
}

/* Compact icon-only button for primary per-row actions (Ladda ner, Kopiera,
   Impersonera, per-comment Ta bort). Square hit-target, currentColor stroke
   SVG inside, hover fills with a faint neutral. Add `danger` modifier for
   destructive icons (per-comment Ta bort, pending-invite Återkalla). */
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 4px;
    background: transparent;
    border: 0;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    text-decoration: none;
}

.icon-button:hover:not(:disabled) {
    background: var(--hover-overlay);
    color: var(--text-primary);
}

.icon-button:disabled {
    color: var(--text-muted);
    cursor: not-allowed;
}

.icon-button.danger {
    color: var(--danger);
}

.icon-button.danger:hover:not(:disabled) {
    background: var(--danger-tint);
    color: var(--danger-hover);
}

.icon-button svg {
    width: 18px;
    height: 18px;
}

/* FluentDataGrid sets `overflow: hidden` on every <td> (for ellipsised
   single-line text). That clips any kebab popover anchored inside the cell,
   so action columns that host a RowActionMenu must opt out. Apply via the
   column's `Class="action-cell"` attribute — Fluent forwards the class to
   both <th> and every <td> in that column. */
.action-cell {
    overflow: visible !important;
}

/* FluentDataGrid centers plain-text cells via `align-content: center` on the
   <td>, but cells whose content is an interactive control — a FluentSwitch,
   FluentButton(s), an .icon-button, or a RowActionMenu kebab — host wrapper
   <div>s / inline-block web components that don't inherit that centering and
   sink below the text columns in the same row (worse the taller the control).
   Flex-center just those cells so the controls line up with the text. Safe
   because control cells carry no ellipsised text of their own. */
td.action-cell,
.fluent-data-grid td:has(.row-action-menu),
.fluent-data-grid td:has(fluent-switch),
.fluent-data-grid td:has(.icon-button) {
    display: flex;
    align-items: center;
}

/* Responsive data grids: at tablet width drop low-priority columns and shrink
   the grid template to match. FluentDataGrid renders one big CSS grid on the
   root .fluent-data-grid (intermediate <thead>/<tbody>/<tr> are display:contents),
   so hiding cells alone leaves empty tracks unless we also override
   grid-template-columns on the root. The inline-style version takes precedence
   without !important, hence the bang. */
@media (max-width: 768px) {
    .tickets-grid .hide-narrow,
    .members-grid .hide-narrow,
    .pending-invites-grid .hide-narrow,
    .documents-grid .hide-narrow {
        display: none !important;
    }

    .tickets-grid {
        grid-template-columns: 2fr 1fr !important;
    }

    .members-grid {
        grid-template-columns: 1.4fr 0.7fr auto !important;
    }

    .pending-invites-grid {
        grid-template-columns: 2fr auto auto !important;
    }

    .documents-grid {
        grid-template-columns: 2fr 1fr auto !important;
    }
}

/* Member picker dialog.
   Desktop sizing is set inline on the FluentDialog via --dialog-width /
   --dialog-height. !important below overrides those inline values on mobile.
   The body override constrains height so .picker-grid can flex internally
   and the suggestion list scrolls — Fluent's default is `height: auto`. */
fluent-dialog.member-picker-dialog .fluent-dialog-body {
    height: 100% !important;
    min-height: 0 !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@media (max-width: 720px) {
    fluent-dialog.member-picker-dialog {
        --dialog-width: 96vw !important;
        --dialog-height: 92vh !important;
    }
}

/* Pill-shaped segmented control for switching between sibling views
   (e.g. Lista / Månad on /calendar). */
.view-toggle {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: var(--bg-sidebar);
    border-radius: 8px;
}

.view-toggle-option {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background-color 120ms ease, color 120ms ease;
}

.view-toggle-option:hover {
    color: var(--text-primary);
}

.view-toggle-option.active {
    background: var(--surface-card);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
