/*
 * Reusable component styles ("bricks"). Each class is a self-contained, reusable
 * piece built only from the design tokens in tokens.css. Razor components in
 * Components/ render the markup that uses these classes (AppButton, AppTextField).
 */

/* ---- Auth screen: full-bleed brand gradient, centred content ---- */
.auth-bg {
    min-height: 100vh;
    min-height: 100svh;   /* small-viewport unit: avoids the iOS URL-bar overlap/jump; falls back to vh */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    /* at least 1.5rem, but grow to clear the notch / home indicator where safe-area insets are larger */
    padding: max(1.5rem, env(safe-area-inset-top)) max(1.5rem, env(safe-area-inset-right))
             max(1.5rem, env(safe-area-inset-bottom)) max(1.5rem, env(safe-area-inset-left));
    background: var(--brand-gradient);
    font-family: var(--font-body);
}

/* ---- Frosted-glass card ---- */
.auth-card {
    /* Figma: 371 × 304, radius 24, padding 40/32/32/32, gap 32. Treated as intent, not a
       hard box: max-width keeps it responsive; height comes from the content + padding + gaps
       (≈304) so the 32px bottom padding sits right under the button — no dead space. */
    width: 100%;
    max-width: 371px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;   /* space between welcome text and input (also applies to logo→title, form→error) */
    padding: 40px 32px 32px;
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgb(from var(--color-brand-ink) r g b / 0.15);
}

.auth-logo {
    width: 110px;
    height: auto;
    display: block;
}

/* Welcome heading — Figma: Space Grotesk 500 / 16px / centred, in a 226 × 40 box.
   40px tall across two lines = 20px per line → line-height 1.25 (the old 100%/16px was too tight).
   max-width 226px matches the Figma text box; it stays centred via the card's align-items: center. */
.auth-title {
    margin: 0;
    max-width: 226px;
    text-align: center;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 16px;
    line-height: 1.25;
    letter-spacing: 0;
    color: var(--color-brand-ink);
}

/* Inline form error message, shown inside the card. */
.auth-error {
    margin: 0;
    text-align: center;
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--color-error);
}

/* Small underlined link — Helvetica Neue 400 / 12px / underlined / centred. Two contexts:
   .auth-footer-link sits on the dark brand background; .auth-resend-link sits on the light card. */
.auth-footer-link,
.auth-resend-link {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 12px;
    line-height: 100%;
    text-align: center;
    text-decoration: underline;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}

.auth-footer-link {
    color: rgba(255, 255, 255, 0.92);   /* on the dark brand background */
}

/* "Ikke mottatt kode? Send på nytt" — same link, but on the light card (Base/Text Positive). */
.auth-resend-link {
    color: var(--color-text-positive);
}

.auth-resend-link:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ---- Reusable text field (rendered by Components/AppTextField.razor) ---- */
.app-field {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 35px;   /* vertical space between stacked controls — e.g. the input and the login button */
    align-items: center;
}

.app-input {
    width: 100%;
    max-width: var(--control-width);
    height: var(--input-height);
    box-sizing: border-box;
    padding: 9px var(--control-pad-x);
    border: 0.75px solid rgb(from var(--color-brand-ink) r g b / 0.25);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--color-brand-ink);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.app-input::placeholder {
    color: rgb(from var(--color-brand-ink) r g b / 0.45);
}

.app-input:focus {
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px rgb(from var(--color-brand) r g b / 0.25);
}

/* ---- Segmented code input (rendered by Components/AppCodeInput.razor) ----
   A row of equal-width single-character boxes for OTP-style codes. The boxes flex to fill
   the shared control width, so 4/6/8 digits all stay aligned with the inputs and buttons. */
.app-code {
    width: 100%;
    max-width: var(--control-width);
    display: flex;
    gap: 8px;
}

.app-code-box {
    flex: 1 1 0;
    min-width: 0;
    height: 44px;
    box-sizing: border-box;
    padding: 0;
    border: 0.75px solid rgb(from var(--color-brand-ink) r g b / 0.25);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    text-align: center;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 18px;
    color: var(--color-brand);   /* typed digits render in brand green (per Login3) */
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.app-code-box:focus {
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px rgb(from var(--color-brand) r g b / 0.25);
}

/* ---- Reusable button (rendered by Components/AppButton.razor) ---- */
.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: var(--control-width);
    height: var(--button-height);
    padding: 0 var(--control-pad-x);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.app-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* Tactile press feedback (works for both click and tap; not transitioned, so it feels instant). */
.app-btn:active:not(:disabled) {
    transform: translateY(1px);
}

/* Subtle variant — transparent, 1px muted border + text (the "Logg inn" button).
   Text: Space Grotesk 500 / 14px / line-height 100% / letter-spacing -1%.
   Full `border` shorthand (not just border-color) so it always wins over the base. */
.app-btn--subtle {
    background: transparent;
    border: 1px solid var(--color-text-subtle);
    color: var(--color-text-subtle);
    font-family: var(--font-display);
    font-weight: 500;
    line-height: 1;
    letter-spacing: -0.01em;
}

.app-btn--subtle:hover:not(:disabled) {
    background: rgb(from var(--color-text-subtle) r g b / 0.08);
}

/* Solid variant — filled brand button for primary actions elsewhere. */
.app-btn--primary {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: var(--color-text-negative);
}

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

/* Dark variant — solid dark teal (--color-brand-ink), white text. Used for the active
   "Logg inn" on the code screen once all digits are entered (Login3). */
.app-btn--dark {
    background: var(--color-brand-ink);
    border-color: var(--color-brand-ink);
    color: var(--color-text-negative);
}

.app-btn--dark:hover:not(:disabled) {
    background: var(--color-brand-ink-hover);
    border-color: var(--color-brand-ink-hover);
}

/* ---- Mobile / touch adaptations -----------------------------------------------------
   The login is already a single centred column (mobile-appropriate), so this is not a
   re-layout — it fixes what only bites on phones: touch-target size, the iOS <16px input
   auto-zoom, and cramped width on the smallest screens. Keyed on input method (pointer)
   rather than width, so a touch laptop gets the larger targets too. */
@media (pointer: coarse) {
    /* 16px stops iOS Safari auto-zooming the page on focus; 44px is the min comfortable target. */
    .app-input {
        height: 44px;
        font-size: 16px;
    }

    .app-btn {
        height: 44px;
    }

    /* Give the small secondary links a 44px tap target WITHOUT shifting the tuned spacing:
       padding grows the hit area, the matching negative margin cancels its effect on layout. */
    .auth-footer-link,
    .auth-resend-link {
        padding: 16px 12px;
        margin: -16px -12px;
    }
}

/* Smallest phones (≤360px): reclaim content width by trimming the card's generous padding. */
@media (max-width: 360px) {
    .auth-card {
        padding: 32px 20px 24px;
    }
}

/* ---- Chips / pills (reusable tags) — Figma: Inter Medium 10px / radius 40 / h17 ---- */
.app-pill {
    display: inline-flex;
    align-items: center;
    height: 17px;
    padding: 0 16px;
    border-radius: 40px;
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: 10px;
    line-height: 1;
    color: var(--color-text-positive);
    white-space: nowrap;
}

.app-pill--product { background: var(--color-tag-product); }
.app-pill--outline { border: 1px solid var(--color-surface-2); }

/* ---- Tanker module: cards (Components/TankCard.razor) ---- */
/* All tanks shown in one responsive grid (≈3 across at panel width, wraps for more). */
.tank-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 8px;
    width: 100%;
    align-items: stretch;
}

.tank-card {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    background: var(--color-surface);
    border-radius: 8px;
    box-shadow: 0 4px 6px rgb(from var(--color-brand-dark) r g b / 0.012);
}

/* FORHÅNDSKJØP variant — green frame + label wrapping a white inner card. */
.tank-card--prebought {
    gap: 2px;
    padding: 2px 0 0;
    background: var(--color-brand);
    align-items: center;
}

.tank-prebought-label {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 10px;
    letter-spacing: 0.03em;
    color: var(--color-surface);
}

.tank-card-inner {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    background: var(--color-surface);
    border-radius: 8px;
}

.tank-card-head {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.tank-name {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 28px;
    line-height: 1;
    letter-spacing: -0.0054em;
    color: var(--color-text-positive);
}

.tank-chevron {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    background-color: var(--color-text-positive);
    -webkit-mask: url("/img/icons/down.svg") center / contain no-repeat;
    mask: url("/img/icons/down.svg") center / contain no-repeat;
}

.tank-body {
    display: flex;
    gap: 16px;
    align-items: center;
}

.tank-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tank-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tank-stats {
    display: flex;
    gap: 24px;
}

.tank-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tank-stat-label {
    font-family: var(--font-body);
    font-size: 10px;
    line-height: 1.2;
    color: var(--color-text-subtle);
}

.tank-stat-value {
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 1.2;
    color: var(--color-text-positive);
}

.tank-stat-value--strong { font-weight: 700; }

/* Fill gauge — a rounded track with a level-coloured fill rising from the bottom. */
.tank-gauge {
    position: relative;
    width: 103px;
    height: 54px;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    background: var(--surface-card);
    overflow: hidden;
}

.tank-gauge-fill {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0 0 16px 16px;
}

.tank-gauge-fill--green { background: var(--color-brand); }
.tank-gauge-fill--yellow { background: var(--color-warning); }
.tank-gauge-fill--red { background: var(--color-danger); }
.tank-gauge-fill--empty { background: transparent; }

.tank-gauge-value {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 24px;
    letter-spacing: -0.02em;
    color: var(--color-text-positive);
}

/* ---- Custom dropdown (Components/AppSelect.razor) — replaces the native <select> ---- */
.app-dd {
    position: relative;
    width: 100%;
    max-width: var(--control-width);
}

.app-dd-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    height: var(--input-height);
    box-sizing: border-box;
    padding: 0 var(--control-pad-x);
    border: 0.75px solid rgb(from var(--color-brand-ink) r g b / 0.25);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--color-brand-ink);
    text-align: left;
    cursor: pointer;
}

.app-dd-trigger:disabled { opacity: 0.6; cursor: default; }

.app-dd-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* CSS chevron that flips when open */
.app-dd-caret {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    margin-top: -3px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.15s ease, margin-top 0.15s ease;
}

.app-dd--open .app-dd-caret { margin-top: 3px; transform: rotate(-135deg); }

/* full-screen catcher so an outside click closes the menu */
.app-dd-backdrop { position: fixed; inset: 0; z-index: 90; background: transparent; }

.app-dd-menu {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 100;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: var(--color-surface);
    border: 0.75px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 32px rgb(from var(--color-brand-ink) r g b / 0.18);
    max-height: 240px;
    overflow-y: auto;
}

.app-dd--up .app-dd-menu { top: auto; bottom: calc(100% + 4px); }

.app-dd-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--color-brand-ink);
    cursor: pointer;
    white-space: nowrap;
}

.app-dd-option:hover { background: var(--surface-card); }
.app-dd-option.is-selected { background: var(--color-brand); color: var(--color-brand-dark); }

/* Sidebar (dark) variant — dark trigger + a DISTINCT dark menu panel (not the sidebar's own green,
   which previously made the open menu blend in and look broken). */
.app-dd--sidebar { max-width: none; }

.app-dd--sidebar .app-dd-trigger {
    height: auto;
    padding: 7px 10px;
    border: 1px solid var(--color-brand-border);
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-negative);
    font-family: var(--font-display);
    font-size: 12px;
    letter-spacing: -0.01em;
}

.app-dd--sidebar .app-dd-menu {
    background: var(--color-brand-dark);
    border-color: var(--color-brand-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.app-dd--sidebar .app-dd-option {
    color: var(--color-text-negative);
    font-family: var(--font-display);
    font-size: 12px;
    letter-spacing: -0.01em;
}

.app-dd--sidebar .app-dd-option:hover { background: rgba(255, 255, 255, 0.10); }
.app-dd--sidebar .app-dd-option.is-selected { background: var(--color-brand); color: var(--color-brand-dark); }

/* Top-bar (mobile) variant — a borderless white trigger centred on the green bar; the menu drops
   downward and is centred under the trigger (the default white panel reads fine over the content). */
.app-dd--topbar {
    width: auto;
    max-width: 60vw;
}

.app-dd--topbar .app-dd-trigger {
    height: auto;
    padding: 4px 6px;
    border: 0;
    background: transparent;
    color: var(--color-on-brand);
    font-family: var(--font-display);
    font-size: 14px;
    letter-spacing: -0.01em;
    justify-content: center;
}

/* Caret is the shared down.svg tinted brand green (Figma), not the CSS border chevron. */
.app-dd--topbar .app-dd-caret {
    width: 16px;
    height: 16px;
    margin: 0;
    border: 0;
    transform: none;
    background-color: var(--color-brand);
    -webkit-mask: url("/img/icons/down.svg") center / contain no-repeat;
    mask: url("/img/icons/down.svg") center / contain no-repeat;
}

.app-dd--topbar.app-dd--open .app-dd-caret {
    transform: rotate(180deg);
}

.app-dd--topbar .app-dd-menu {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    min-width: 220px;
}

/* ---- Checkbox row (box + label) ---- */
.app-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--color-brand-ink);
    cursor: pointer;
    user-select: none;
}

.app-check input {
    width: 16px;
    height: 16px;
    accent-color: var(--color-brand);
    cursor: pointer;
}

/* ---- Login client chooser layout ---- */
.auth-choose {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* The dropdown and button fill the column, but the checkbox is intrinsic-width — left-align it
   to the controls' edge instead of letting the column centre it. */
.auth-choose .app-check {
    align-self: flex-start;
}
