/* ─── Typeface ───────────────────────────────────────────────────────────────
 * Satoshi, the same three static faces the apps and the website use. The ranges match how
 * Compose resolves weights, so 700 renders Black here exactly as FontWeight.Bold does there.
 * Declare 400, 500 or 900 and nothing else.
 */
@font-face {
    font-family: "Satoshi";
    src: url("/fonts/satoshi_regular.otf") format("opentype");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Satoshi";
    src: url("/fonts/satoshi_medium.otf") format("opentype");
    font-weight: 500 600;
    font-display: swap;
}

@font-face {
    font-family: "Satoshi";
    src: url("/fonts/satoshi_black.otf") format("opentype");
    font-weight: 700 950;
    font-display: swap;
}

/* ─── Design tokens ─────────────────────────────────────────────────────────────
 * Paydot Active Dot. Values mirror brand/tokens/brand.tokens.json; the --pd- names are kept
 * so templates need no changes, but every one now resolves to a brand token.
 */
:root {
    --pd-blue: #2c43e6; /* Electric Blue — primary action, focus, selection */
    --pd-blue-strong: #1c31b8; /* hover */
    --pd-blue-stronger: #16279a; /* active / pressed */
    --pd-blue-soft: #e7eaff; /* action-tinted containers */
    --pd-coral: #fd4631; /* the signature dot — never chrome, never an action here */

    --pd-blue-muted: #c3cbf5; /* disabled action fills, spinner track */
    --pd-blue-tint: rgba(44, 67, 230, 0.07); /* sidebar hover / active background */

    /* Borders are neutral, not action-tinted — "default surfaces and borders remain neutral". */
    --pd-border: rgba(18, 19, 26, 0.1); /* cards, widgets, dividers */
    --pd-border-strong: rgba(18, 19, 26, 0.18); /* form controls, which need a visible edge */

    --pd-slate: #625b57; /* secondary text (warm Muted Ink) */
    --pd-charcoal: #12131a; /* primary text (Ink) */
    --pd-bg: #fbf8f4; /* page background (warm Canvas) */
    --pd-bg-secondary: #f3eee9; /* secondary background (Neutral Soft) */
    --pd-label: #625b57; /* muted label text */
    --pd-value: var(--pd-charcoal); /* data value text */
}

/* ─── Bootstrap global overrides ────────────────────────────────────────────── */
:root {
    /* Primary colour */
    --bs-primary: var(--pd-blue);
    --bs-primary-rgb: 44, 67, 230;

    /* Body */
    --bs-body-color: var(--pd-charcoal);
    --bs-body-bg: var(--pd-bg);
    --bs-body-font-family: "Satoshi", system-ui, sans-serif;

    /* Secondary / tertiary backgrounds */
    --bs-secondary-bg: var(--pd-bg-secondary);
    --bs-light-rgb: 251, 248, 244; /* bg-light → --pd-bg */

    /* Links */
    --bs-link-color: var(--pd-blue-strong);
    --bs-link-hover-color: var(--pd-blue-stronger);
    --bs-link-color-rgb: 28, 49, 184;

    /* Borders */
    --bs-border-color: var(--pd-border);
    --bs-border-color-translucent: rgba(18, 19, 26, 0.08);

    /* Border radii */
    --bs-border-radius: 0.75rem; /* 12px — fields and compact controls */
    --bs-border-radius-sm: 0.5rem; /* 8px  */
    --bs-border-radius-lg: 1.25rem; /* 20px — dialogs */
    --bs-border-radius-xl: 1.5rem; /* 24px — sheets */
    --bs-border-radius-xxl: 3rem; /* 48px */
    --bs-border-radius-pill: 50rem;

    /* Shadows — subtle, matching paydot.eu */
    --bs-box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --bs-box-shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.08);
    --bs-box-shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.10);

    /* Focus ring */
    --bs-focus-ring-width: 3px;
    /* pay-app and checkout-app step a field's border 1.5dp -> 2.5dp on focus. */
    --pd-focus-border-grow: 1px;
    --bs-focus-ring-color: rgba(44, 67, 230, 0.3);
}

/* ─── Base ───────────────────────────────────────────────────────────────────── */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--pd-blue-strong);
    text-decoration: none;
}

a:hover {
    color: var(--pd-blue-stronger);
    text-decoration: underline;
}

/* ─── Cards ──────────────────────────────────────────────────────────────────── */
.card {
    --bs-card-border-radius: 1rem;
    --bs-card-border-color: var(--pd-border);
    --bs-card-cap-bg: transparent;
    box-shadow: var(--bs-box-shadow);
    width: 100%;
    max-width: 500px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    /* Actions are 16px, not pills — the Active Dot geometry is structured. */
    --bs-btn-border-radius: 1rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.btn-primary {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--pd-blue);
    --bs-btn-border-color: var(--pd-blue);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--pd-blue-strong);
    --bs-btn-hover-border-color: var(--pd-blue-strong);
    --bs-btn-focus-shadow-rgb: 44, 67, 230;
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--pd-blue-stronger);
    --bs-btn-active-border-color: var(--pd-blue-stronger);
    /* Disabled keeps the blue family — "the primary action, currently off" — but the label has
       to stay readable. White on the muted fill was 1.59:1; the deep blue is 7.36:1. WCAG
       exempts disabled controls, which is not a reason to ship one nobody can read. */
    --bs-btn-disabled-bg: var(--pd-blue-muted);
    --bs-btn-disabled-border-color: var(--pd-blue-muted);
    --bs-btn-disabled-color: var(--pd-blue-stronger);
}

.btn-outline-primary {
    --bs-btn-color: var(--pd-blue);
    --bs-btn-border-color: var(--pd-blue);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--pd-blue);
    --bs-btn-hover-border-color: var(--pd-blue);
    --bs-btn-focus-shadow-rgb: 44, 67, 230;
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--pd-blue-strong);
    --bs-btn-active-border-color: var(--pd-blue-strong);
}

.btn-outline-light {
    --bs-btn-border-radius: 1rem;
}

/* ─── Form controls ──────────────────────────────────────────────────────────── */
.form-control,
.form-select {
    background-color: #fff;
    border-color: var(--pd-border-strong);
    border-radius: var(--bs-border-radius);
}

.form-control:disabled,
.form-select:disabled {
    background-color: var(--pd-bg-secondary);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--pd-blue);
    box-shadow: 0 0 0 var(--pd-focus-border-grow) var(--pd-blue);
}

.form-control.is-invalid,
.form-select.is-invalid {
    border-color: #c0182b;
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    border-color: #c0182b;
    box-shadow: 0 0 0 var(--pd-focus-border-grow) #c0182b;
}

.form-label {
    color: var(--pd-slate);
    font-weight: 500;
}

.form-check-input:checked {
    background-color: var(--pd-blue);
    border-color: var(--pd-blue);
}

.form-check-input:focus {
    border-color: var(--pd-blue);
    box-shadow: 0 0 0 var(--pd-focus-border-grow) var(--pd-blue);
}

/* ─── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
    border-radius: var(--bs-border-radius);
}

.alert-danger {
    --bs-alert-color: #7a1220;
    --bs-alert-bg: #ffdad6;
    --bs-alert-border-color: #f4b8b1;
}

.alert-success {
    --bs-alert-color: #075d32;
    --bs-alert-bg: #c9f6d8;
    --bs-alert-border-color: #9fe3ba;
}

/* ─── Utility: Paydot-branded link ───────────────────────────────────────────── */
.link-paydot {
    color: var(--pd-blue-strong);
    text-decoration: none;
}

.link-paydot:hover {
    color: var(--pd-blue-stronger);
    text-decoration: underline;
}

/* A control that must be a <button> (it drives an htmx verb) but should read as a link.
   Undoes the weight and tracking .btn adds so it matches an adjacent .link-paydot anchor. */
.pd-link-button {
    font-weight: 400;
    letter-spacing: normal;
}

/* ─── Portal card ────────────────────────────────────────────────────────────── */

/* Standard widget container for all portal pages. Replaces .card + .card-body. */
.pd-card {
    background-color: #fff;
    border: 1px solid var(--pd-border);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--bs-box-shadow-sm);
    width: 100%;
}

/* Section title inside a pd-card */
.pd-card-header {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--pd-charcoal);
    margin: 0 0 1rem;
}

/* ─── Data display ───────────────────────────────────────────────────────────── */

/* Descriptive labels — column headers, field labels, definition terms */
.pd-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--pd-label);
}

/* User-supplied values — company name, IBAN numbers, email addresses */
.pd-value {
    color: var(--pd-value);
    font-weight: 500;
    min-width: 0;
    overflow-wrap: break-word;
}

.pd-token {
    font-family: var(--bs-font-monospace);
    color: var(--pd-value);
}

.pd-field-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem;
}

.pd-field-row > :first-child {
    flex: 1 1 16rem;
    min-width: 0;
    max-width: 30rem;
}

.pd-field-row-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-left: auto;
}

/* ─── Data table ─────────────────────────────────────────────────────────────── */
.pd-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
}

.pd-table th {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--pd-label);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--pd-border);
    white-space: nowrap;
}

.pd-table td {
    padding: 0.875rem 0.75rem;
    border-bottom: 1px solid rgba(18, 19, 26, 0.07);
    vertical-align: middle;
}

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

/* ─── Form group ─────────────────────────────────────────────────────────────── */

/* Stacks a label above its input with consistent spacing. */
.pd-form-group {
    display: flex;
    flex-direction: column;
}

.pd-form-group > .pd-label {
    margin-bottom: 0.375rem;
}

/* ─── Dashboard layout ───────────────────────────────────────────────────────── */

/* Below md the page scrolls normally; from md up the shell is pinned to the viewport
   and #main-content is the only scroller. */
.pd-app-shell {
    min-height: 100vh;
}

@media (min-width: 768px) {
    .pd-app-body {
        overflow: hidden;
    }

    .pd-app-shell {
        height: 100vh;
    }

    .pd-main {
        overflow-y: auto;
    }
}

/* Sidebar. Below md it is a Bootstrap offcanvas drawer, whose width comes from the
   variable — .offcanvas-md.offcanvas-start outspecifies a plain width here. */
.pd-sidebar {
    --bs-offcanvas-width: 260px;
    width: 220px;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .pd-sidebar {
        min-height: 100vh;
    }
}

.pd-sidebar-toggle {
    color: var(--pd-slate);
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.pd-sidebar .nav-link {
    color: var(--pd-slate);
    border-radius: var(--bs-border-radius);
    font-size: 0.875rem;
    padding: 0.5rem 0.875rem;
}

.pd-sidebar .nav-link:hover {
    background-color: var(--pd-blue-tint);
    color: var(--pd-charcoal);
    text-decoration: none;
}

.pd-sidebar .nav-link.active {
    background-color: var(--pd-blue-tint);
    color: var(--pd-blue);
    font-weight: 600;
}

/* Top bar */
.pd-dashboard-topbar {
    min-height: 60px;
    flex-shrink: 0;
}

/* User initials badge */
.pd-user-badge {
    width: 32px;
    height: 32px;
    background-color: var(--pd-blue-soft);
    color: var(--pd-blue-stronger);
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Full-width card variant (removes 500px cap used on auth pages) */
.pd-card-full {
    max-width: none;
}

/* ─── QR code ────────────────────────────────────────────────────────────────── */
.pd-qr-code {
    display: block;
    border-radius: var(--bs-border-radius);
    transition: opacity 0.15s ease;
}

a:hover .pd-qr-code {
    opacity: 0.85;
    text-decoration: none;
}

/* ─── Loading and busy states ────────────────────────────────────────────────── */

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

@keyframes pd-progress-slide {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(400%);
    }
}

.pd-progress {
    position: fixed;
    inset: 0 0 auto 0;
    height: 3px;
    z-index: 1080;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.pd-progress.pd-progress-active {
    opacity: 1;
}

.pd-progress::after {
    content: "";
    display: block;
    width: 25%;
    height: 100%;
    border-radius: 50rem;
    background: linear-gradient(90deg,
    rgba(44, 67, 230, 0) 0%,
    var(--pd-blue) 50%,
    rgba(44, 67, 230, 0) 100%);
    animation: pd-progress-slide 1s ease-in-out infinite;
}

.btn.pd-busy {
    position: relative;
    color: transparent;
    pointer-events: none;
    transition: none;
    --bs-btn-disabled-bg: var(--bs-btn-bg);
    --bs-btn-disabled-border-color: var(--bs-btn-border-color);
    --bs-btn-disabled-color: transparent;
    --bs-btn-disabled-opacity: 1;
}

.btn.pd-busy::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1em;
    height: 1em;
    margin: -0.5em 0 0 -0.5em;
    border: 2px solid var(--bs-btn-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: pd-spin 0.6s linear infinite;
}

.pd-card.htmx-request {
    position: relative;
    min-height: 7.5rem;
}

.pd-card.htmx-request::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background-color: rgba(255, 255, 255, 0.65);
}

.pd-card.htmx-request::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1.5rem;
    height: 1.5rem;
    margin: -0.75rem 0 0 -0.75rem;
    border: 2px solid var(--pd-blue-muted);
    border-top-color: var(--pd-blue);
    border-radius: 50%;
    animation: pd-spin 0.7s linear infinite;
}

.form-check-input.pd-busy {
    opacity: 0.5;
    pointer-events: none;
}

.pd-sidebar .nav-link.htmx-request {
    background-color: var(--pd-blue-tint);
    color: var(--pd-blue);
    font-weight: 600;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .pd-progress::after,
    .btn.pd-busy::after,
    .pd-card.htmx-request::after {
        animation: none;
    }

    .pd-progress::after {
        width: 100%;
    }
}

/* ─── Print ──────────────────────────────────────────────────────────────────── */
@media print {
    #sidebar,
    #topbar,
    .pd-progress,
    .pd-print-hide {
        display: none !important;
    }

    body,
    #main-content {
        overflow: visible !important;
    }
}
