/**
 * ha-viewer.css
 *
 * Basislayout für den HAINBUCH Manual Viewer.
 * Definiert Seitenraster, App-Layout, Viewer-Grundelemente und Druckbasis.
 */

@font-face {
    font-family: "Helvetica Neue LT Pro";
    src: url("../fonts/HelveticaNeueLTPro_normal_normal_300.woff") format("woff");
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

:root {
    --hb-red: #e2001a;
    --hb-red-dark: #c80016;
    --hb-bg: #f5f5f7;
    --hb-page-bg: #ffffff;
    --hb-border: #e5e7eb;
    --hb-text: #111827;
    --hb-muted: #6b7280;
    --hb-soft: #f3f4f6;
    --hb-radius-page: 18px;
    --hb-shadow-page: 0 20px 45px rgba(15, 23, 42, 0.20);
    --hb-font-base: "Helvetica Neue LT Pro", Arial, Helvetica, "Microsoft YaHei", "SimSun", "Noto Sans CJK SC", "Noto Sans JP", "Noto Sans KR", sans-serif;

    /* A4-Messgrundlage für JS-Pagination */
    --hb-page-width: 210mm;
    --hb-page-height: 297mm;

    /* Seitenbereiche */
    --hb-page-x: 18mm;
    --hb-page-header-top: 14mm;
    --hb-page-header-bottom: 6mm;
    --hb-page-body-top: 9mm;
    --hb-page-body-bottom: 10mm;
    --hb-page-footer-top: 5mm;
    --hb-page-footer-bottom: 8mm;
}

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

html,
body {
    min-height: 100%;
    margin: 0;
    padding: 0;
    background: var(--hb-bg);
    color: var(--hb-text);
    font-family: var(--hb-font-base);
    font-weight: 300;
}

img,
svg,
canvas,
video {
    max-width: 100%;
}

button,
input,
textarea,
select {
    font: inherit;
    font-family: var(--hb-font-base);
}

/* App-Grundlayout */
.hb-app-shell {
    max-width: 1400px;
    margin: 24px auto 32px;
    padding: 0 16px;
}

.hb-app-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.hb-app-header-left {
    min-width: 0;
}

.hb-back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
    color: var(--hb-muted);
    font-size: 13px;
    text-decoration: none;
}

.hb-back-link:hover {
    text-decoration: underline;
}

.hb-app-title {
    margin: 0;
    color: var(--hb-red);
    font-size: 22px;
    font-weight: 600;
    line-height: 1.25;
}

.hb-app-header-right {
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.hb-print-btn {
    padding: 8px 18px;
    border: 0;
    border-radius: 999px;
    background: var(--hb-red);
    color: #ffffff;
    box-shadow: 0 10px 30px rgba(220, 38, 38, 0.35);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: transform 0.1s ease, box-shadow 0.1s ease, background-color 0.15s ease;
}

.hb-print-btn:hover {
    transform: translateY(-1px);
    background: var(--hb-red-dark);
    box-shadow: 0 14px 36px rgba(220, 38, 38, 0.40);
}

.hb-print-btn:active {
    transform: translateY(0);
    box-shadow: 0 8px 24px rgba(220, 38, 38, 0.30);
}

/* Viewer-Layout */
.hb-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 20px;
    align-items: flex-start;
}

.hb-main-column {
    min-width: 0;
}

/* Inhaltsverzeichnis */
.hb-toc-panel {
    position: sticky;
    top: 16px;
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 32px);
    padding: 14px 14px 10px;
    overflow: hidden;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.10);
    font-size: 13px;
}

.hb-toc-header {
    margin-bottom: 6px;
    color: var(--hb-muted);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.hb-toc-nav {
    margin: 0;
    padding-right: 4px;
    overflow: auto;
}

.hb-toc-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.hb-toc-item {
    margin: 2px 0;
}

.hb-toc-link {
    display: block;
    padding: 4px 6px;
    border-radius: 999px;
    color: var(--hb-text);
    cursor: pointer;
    font-size: 12px;
    line-height: 1.3;
    text-decoration: none;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.hb-toc-link:hover {
    background: var(--hb-soft);
}

.hb-toc-link.is-active {
    background: rgba(226, 0, 26, 0.08);
    color: var(--hb-red);
}

.hb-toc-link.level-1 {
    padding-left: 8px;
    font-weight: 600;
}

.hb-toc-link.level-2 {
    padding-left: 18px;
}

.hb-toc-link.level-3 {
    padding-left: 28px;
    color: var(--hb-muted);
    font-size: 11px;
}

/* Suche */
.hb-viewer-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.hb-search-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
}

.hb-search-input {
    width: 100%;
    min-width: 0;
    padding: 6px 36px 6px 12px;
    border: 1px solid var(--hb-border);
    border-radius: 999px;
    background: #ffffff;
    color: var(--hb-text);
    font-size: 13px;
    outline: none;
}

.hb-search-input:focus {
    border-color: var(--hb-red);
    box-shadow: 0 0 0 1px rgba(226, 0, 26, 0.4);
}

.hb-search-clear {
    position: absolute;
    top: 50%;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--hb-muted);
    cursor: pointer;
    transform: translateY(-50%);
}

.hb-search-clear:hover {
    background: var(--hb-soft);
    color: var(--hb-red);
}

.hb-search-status {
    color: var(--hb-muted);
    font-size: 12px;
    white-space: nowrap;
}

.hb-search-hit-line {
    background: #fef3f2;
    outline: 2px solid rgba(226, 0, 26, 0.6);
    outline-offset: 2px;
}

/* Seitenlayout */
.hb-pages {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.hb-page {
    position: relative;
    display: flex;
    flex-direction: column;
    width: var(--hb-page-width);
    height: var(--hb-page-height);
    margin: 0 auto;
    overflow: hidden;
    background: var(--hb-page-bg);
    border-radius: var(--hb-radius-page);
    box-shadow: var(--hb-shadow-page);
    font-family: var(--hb-font-base);
    font-weight: 300;
}

.hb-page-header {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12mm;
    padding: var(--hb-page-header-top) var(--hb-page-x) var(--hb-page-header-bottom);
    border-bottom: 1px solid var(--hb-border);
}

.hb-logo-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.hb-logo {
    flex: 0 0 auto;
    display: block;
    width: auto;
    height: 16mm;
}

.hb-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.hb-header-manual-type {
    color: var(--hb-muted);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    line-height: 1.25;
    text-transform: uppercase;
}

.hb-header-product {
    color: var(--hb-text);
    font-size: 17px;
    font-weight: 600;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.hb-page-meta {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.hb-page-count {
    color: var(--hb-muted);
    font-size: 11px;
}

.hb-page-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: var(--hb-page-body-top) var(--hb-page-x) var(--hb-page-body-bottom);
    overflow: hidden;
    color: var(--hb-text);
    font-family: var(--hb-font-base);
    font-size: 11pt;
    font-weight: 300;
    hyphens: auto;
    line-height: 1.42;
    overflow-wrap: break-word;
}

.hb-page-body > :first-child {
    margin-top: 0 !important;
}

.hb-page-body > :last-child {
    margin-bottom: 0 !important;
}

.hb-page-body h1,
.hb-page-body h2,
.hb-page-body h3,
.hb-page-body h4 {
    margin: 0 0 8px;
    color: var(--hb-text);
    font-weight: 600;
    line-height: 1.25;
    break-after: avoid;
    page-break-after: avoid;
}

.hb-page-body h1 {
    color: var(--hb-red);
    font-size: 18px;
}

.hb-page-body h2 {
    font-size: 15px;
}

.hb-page-body h3 {
    font-size: 13px;
}

.hb-page-body h4 {
    font-size: 12px;
}

.hb-page-body p {
    margin: 0 0 5px;
}

.hb-page-body ul,
.hb-page-body ol {
    margin: 0 0 6px 18px;
    padding-left: 0;
}

.hb-page-body li {
    margin: 0 0 2px;
}

/* Tabellenbasis */
.hb-page:not(.hb-page--cover) .hb-page-body table {
    max-width: 100%;
    margin: 6px 0 10px;
    border-collapse: collapse;
    font-size: 10pt;
}

.hb-page:not(.hb-page--cover) .hb-page-body table th,
.hb-page:not(.hb-page--cover) .hb-page-body table td {
    padding: 4px 6px;
    vertical-align: top;
}

.hb-page:not(.hb-page--cover) .hb-page-body table:not(.hb-docuglobe-layout-table):not(.hb-warning-table):not(.hb-note-table) th,
.hb-page:not(.hb-page--cover) .hb-page-body table:not(.hb-docuglobe-layout-table):not(.hb-warning-table):not(.hb-note-table) td {
    border: 1px solid var(--hb-border);
}

.hb-page:not(.hb-page--cover) .hb-page-body table:not(.hb-docuglobe-layout-table):not(.hb-warning-table):not(.hb-note-table) th {
    background: var(--hb-soft);
    font-weight: 600;
}

.hb-page-body img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 5px auto;
    cursor: zoom-in;
}

.hb-page-body svg {
    max-width: 100%;
    height: auto;
}

/* Seitenfuß */
.hb-page-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8mm;
    padding: var(--hb-page-footer-top) var(--hb-page-x) var(--hb-page-footer-bottom);
    border-top: 1px solid var(--hb-border);
    color: var(--hb-muted);
    font-size: 8.5pt;
    line-height: 1.25;
}

.hb-footer-left,
.hb-footer-right {
    white-space: nowrap;
}

/* Lightbox */
.hb-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}

.hb-lightbox.is-open {
    display: flex;
}

.hb-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.70);
}

.hb-lightbox-content {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 90vw;
    max-height: 90vh;
    padding: 10px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.hb-lightbox-img {
    display: block;
    max-width: 100%;
    max-height: 80vh;
}

.hb-lightbox-close {
    position: absolute;
    top: 4px;
    right: 6px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--hb-muted);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}

.hb-lightbox-close:hover {
    color: var(--hb-red);
}

/* Versteckte JS-Quelle */
.hb-flow-source {
    display: none !important;
}

/* Responsive */
@media (max-width: 1100px) {
    .hb-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .hb-toc-panel {
        display: none;
    }
}

@media (max-width: 900px) {
    .hb-app-shell {
        margin-top: 8px;
    }

    .hb-page {
        margin-bottom: calc((297mm * -0.25) + 8px);
        transform: scale(0.75);
        transform-origin: top center;
    }
}

@media (max-width: 640px) {
    .hb-app-shell {
        padding: 0 8px;
    }

    .hb-app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .hb-app-title {
        font-size: 18px;
    }

    .hb-app-header-right {
        align-self: stretch;
        justify-content: flex-start;
    }

    .hb-print-btn {
        width: 100%;
    }

    .hb-viewer-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .hb-search-status {
        white-space: normal;
    }

    .hb-page {
        margin-bottom: calc((297mm * -0.40) + 8px);
        transform: scale(0.6);
    }
}

@media (max-width: 430px) {
    .hb-page {
        margin-bottom: calc((297mm * -0.52) + 8px);
        transform: scale(0.48);
    }
}

/* Drucklayout */
@page {
    size: A4;
    margin: 0;
}

@media print {
    :root {
        --hb-radius-page: 0;
        --hb-shadow-page: none;
    }

    html,
    body {
        width: 210mm;
        min-height: 297mm;
        background: #ffffff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .hb-app-shell {
        width: auto !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .hb-app-header,
    .hb-toc-panel,
    .hb-viewer-toolbar,
    .hb-search-results,
    .hb-lightbox {
        display: none !important;
    }

    .hb-layout {
        display: block !important;
    }

    .hb-main-column {
        width: auto !important;
    }

    .hb-pages {
        display: block !important;
        gap: 0 !important;
    }

    .hb-page {
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        overflow: hidden !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        transform: none !important;
        page-break-after: always;
        break-after: page;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .hb-page:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    .hb-page-body {
        overflow: hidden !important;
    }
}