/* Gemmes-Tech — app shell, built on the "Modernist" design system tokens:
   flat, zero radius, strong 2px rules, a single red accent.
   Every class is prefixed with `gt-` because the certificate fragment injects
   global rules (body, p, input, .row, .field, .header…) into this document. */

:root {
    --color-bg: #f3f2f2;
    --color-surface: #eae9e9;
    --color-text: #201e1d;
    --color-accent: #ec3013;
    --color-divider: color-mix(in srgb, #201e1d 40%, transparent);

    --color-neutral-100: #f8f4f4;
    --color-neutral-200: #eae7e7;
    --color-neutral-300: #d7d3d3;
    --color-neutral-500: #9b9797;
    --color-neutral-700: #605d5d;
    --color-neutral-900: #2d2b2b;

    --color-accent-100: #fff2ef;
    --color-accent-200: #ffe0d9;
    --color-accent-600: #dd2b0f;
    --color-accent-700: #ae1800;
    --color-accent-800: #7c1405;

    --font-heading: "Archivo", system-ui, sans-serif;
    --font-body: "Archivo", system-ui, sans-serif;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;

    --shadow-sm: 0 1px 2px color-mix(in srgb, #2d2b2b 14%, transparent);
    --shadow-md: 0 3px 10px color-mix(in srgb, #2d2b2b 16%, transparent);
    --shadow-lg: 0 12px 32px color-mix(in srgb, #2d2b2b 22%, transparent);

    --sidebar-width: 340px;
    --header-height: 64px;
}

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

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--color-bg);
}

.gt-app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.45;
    color: var(--color-text);
    background: var(--color-bg);
}

.gt-app :focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.gt-app ::selection {
    background: color-mix(in srgb, var(--color-accent) 30%, transparent);
}

/* — Header — */
.gt-header {
    height: var(--header-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0 var(--space-6);
    border-bottom: 2px solid var(--color-text);
}

.gt-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.gt-brand__logo {
    display: block;
    flex-shrink: 0;
}

.gt-brand__logo img {
    display: block;
    height: 40px;
    width: auto;
    /* The PNG has an opaque white ground: blend it into the header. */
    mix-blend-mode: multiply;
}

.gt-brand__sub {
    margin-left: var(--space-2);
    padding-left: var(--space-4);
    border-left: 1px solid var(--color-divider);
    font-size: 14px;
    color: var(--color-neutral-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gt-header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.gt-version {
    font-size: 13px;
    color: var(--color-neutral-700);
}

/* — Buttons — */
.gt-btn {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) calc(var(--space-3) * 1.2);
    min-height: 36px;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 14px;
    line-height: 1.2;
    color: var(--color-text);
    text-decoration: none;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0;
    cursor: pointer;
}

.gt-btn svg { display: block; flex-shrink: 0; }
.gt-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.gt-btn[hidden] { display: none; }

.gt-btn--primary { background: var(--color-accent); color: var(--color-bg); }
.gt-btn--primary:hover { background: var(--color-accent-600); color: var(--color-bg); }
.gt-btn--primary:active { background: var(--color-accent-700); }

.gt-btn--secondary { border-color: var(--color-divider); }
.gt-btn--secondary:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.gt-btn--secondary:active { background: color-mix(in srgb, var(--color-text) 14%, transparent); }

.gt-btn--danger { border-color: var(--color-accent); color: var(--color-accent-700); }
.gt-btn--danger:hover { background: color-mix(in srgb, var(--color-accent) 10%, transparent); }
.gt-btn--danger:active { background: color-mix(in srgb, var(--color-accent) 18%, transparent); }

.gt-btn--ghost { color: var(--color-text); }
.gt-btn--ghost:hover { color: var(--color-accent-700); background: color-mix(in srgb, var(--color-accent) 10%, transparent); }
.gt-btn--ghost:active { background: color-mix(in srgb, var(--color-accent) 18%, transparent); }

.gt-btn--icon { width: 36px; height: 36px; padding: 0; justify-content: center; }

.gt-btn--print { min-width: 220px; }

/* — Inputs — */
.gt-input {
    width: 100%;
    min-height: 36px;
    padding: 6px 10px;
    font: inherit;
    font-size: 14px;
    color: var(--color-text);
    caret-color: var(--color-accent);
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    border-radius: 0;
}

.gt-input:hover { border-color: color-mix(in srgb, var(--color-text) 60%, transparent); }
.gt-input:focus-visible { border-color: var(--color-accent); outline-offset: 0; }
textarea.gt-input { resize: vertical; }

.gt-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: 0;
}

.gt-field__label {
    font-size: 13px;
    font-weight: 600;
}

/* Neutralise the global `label` rule injected by the certificate fragment. */
.gt-app label.gt-field,
.gt-app label.product-edit__field {
    font-size: 15px;
    font-weight: 400;
    font-style: normal;
    text-decoration: none;
    margin-bottom: 0;
}

.gt-app .gt-input::placeholder {
    font-style: normal;
    color: var(--color-neutral-500);
}

/* — Layout — */
.gt-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

.gt-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 2px solid var(--color-text);
}

.gt-sidebar__tools {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
    border-bottom: 2px solid var(--color-text);
}

.gt-sidebar__heading {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-neutral-700);
    border-bottom: 1px solid var(--color-divider);
}

.gt-product-list {
    flex: 1;
    overflow-y: auto;
}

.gt-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.gt-preview {
    flex: 1;
    overflow: auto;
    padding: var(--space-8);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: var(--color-surface);
}

/* The certificate keeps its own typography: it relied on the body rules
   of its fragment, which the shell overrides through .gt-app. */
.gt-certificate {
    flex-shrink: 0;
    width: 210mm;
    height: 297mm;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    box-shadow: var(--shadow-md);
    font-family: 'Roboto', Helvetica, sans-serif;
    font-size: 10pt;
    line-height: 1.5;
    color: #000;
}

/* Printing makes no sense while the product editor replaces the preview. */
.is-editing-product .gt-btn--print {
    opacity: 0.45;
    pointer-events: none;
}

/* — Product card (rendered by nav.js) — */
.product-card {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--color-divider);
    cursor: pointer;
}

.product-card:hover { background: var(--color-surface); }

.product-card.is-selected { background: var(--color-accent-100); }
.product-card.is-selected .product-card__ref { color: var(--color-accent-700); }

.product-card__image {
    display: block;
    width: 56px;
    height: 56px;
    object-fit: cover;
    background: var(--color-neutral-200);
}

.product-card__infos {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.product-card__ref {
    font-weight: 700;
    font-size: 15px;
}

.product-card__meta {
    font-size: 13px;
    color: var(--color-neutral-700);
}

.product-card__ref,
.product-card__meta {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-card__actions {
    display: flex;
    gap: var(--space-1);
}

.gt-empty {
    padding: var(--space-6) var(--space-4);
    font-size: 14px;
    color: var(--color-neutral-700);
}

/* — Print: only the A4 certificate — */
@media print {
    html, body,
    .gt-app,
    .gt-body,
    .gt-main,
    .gt-preview,
    #certificate-editor {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        display: block !important;
        position: static !important;
        background: none !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }

    body * {
        visibility: hidden;
    }

    .gt-header,
    .gt-sidebar {
        display: none !important;
    }

    #certificateContainer,
    #certificateContainer * {
        visibility: visible;
    }

    #certificateContainer {
        position: absolute;
        top: 0;
        left: 0;
        width: 210mm;
        height: 297mm;
        transform: none !important;
        box-shadow: none !important;
        border: none !important;
    }

    @page {
        size: A4;
        margin: 0;
    }
}
