/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* BIMtwin HUB theme — same brand palette as the gbXML editor (blue #57c0ed,
   gray #404041, light gray #e3e1df, orange #e37200, Montserrat). Follows the
   SYSTEM light/dark preference; the canvas side mirrors these values by
   reading the CSS variables in app.js. */
:root {
    --ribbon-h: 68px;
    --bg:       #eef1f4;
    --ribbon-bg:#ffffff;
    --border:   #e1e5ea;
    --text:     #404041;
    --text-dim: #8b8f94;
    --accent:   #57c0ed;
    --accent-h: #3eb2e8;
    --accent-strong: #1d90c4;
    --danger:   #e05555;
    --warn:     #e37200;
    --field-bg: #f5f7f9;
    --field-h:  #e9edf0;
    --card-bg:  #ffffff;
    --overlay:  rgba(40, 48, 56, 0.42);
    --bubble-bg: rgba(255, 255, 255, 0.88);
    /* Canvas drawing colors (read by app.js) */
    --canvas-bg:   #f0f2f5;
    --linework:    #404041;
    --pill-bg:     rgba(255, 255, 255, 0.95);
    --pill-text:   #404041;
    --pill-border: rgba(64, 64, 65, 0.30);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:       #1a1b1e;
        --ribbon-bg:#232427;
        --border:   #3a3d42;
        --text:     #e3e1df;
        --text-dim: #8b8f94;
        --accent:   #57c0ed;
        --accent-h: #6fcbf1;
        --accent-strong: #7fd4f5;
        --field-bg: #2c2e32;
        --field-h:  #383b40;
        --card-bg:  #26272b;
        --overlay:  rgba(0, 0, 0, 0.55);
        --bubble-bg: rgba(35, 36, 39, 0.88);
        --canvas-bg:   #1e1f22;
        --linework:    #e3e1df;
        --pill-bg:     rgba(30, 32, 36, 0.92);
        --pill-text:   #e3e1df;
        --pill-border: rgba(255, 255, 255, 0.28);
    }
}

body {
    font-family: 'Montserrat', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    user-select: none;
}

/* ── Canvas ───────────────────────────────────────────────────────────────── */
#canvas {
    position: fixed;
    top: var(--ribbon-h);
    left: 0;
    width: 100%;
    height: calc(100% - var(--ribbon-h));
    display: block;
    touch-action: none;
}

/* ── Ribbon ───────────────────────────────────────────────────────────────── */
/* On a phone (or a narrow window) the row of tools is wider than the screen, so
   it scrolls sideways rather than hiding its tail: a swipe on touch, and on the
   desktop edge hover / wheel / the chevrons wired up in common/ribbon-scroll.js.
   The scrollbar itself stays hidden — the edge chevrons are the affordance. */
#ribbon {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--ribbon-h);
    background: var(--ribbon-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 8px;
    z-index: 100;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
#ribbon::-webkit-scrollbar { display: none; }

/* Groups keep their natural width — the ribbon overflows, it never squeezes. */
#ribbon > * { flex-shrink: 0; }

/* Edge chevrons — shown only while there is hidden ribbon that way, so once an
   end is reached the overlay clears and the buttons under it are clickable. */
.ribbon-edge {
    position: fixed;
    top: 0;
    width: 34px;
    display: flex;
    align-items: center;
    padding: 0 3px;
    border: 0;
    color: var(--text-dim);
    cursor: pointer;
    z-index: 110;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, color 0.12s;
}
.ribbon-edge.is-visible { opacity: 1; pointer-events: auto; }
.ribbon-edge:hover { color: var(--accent-strong); }
.ribbon-edge svg { width: 18px; height: 18px; fill: currentColor; }
.ribbon-edge-left {
    justify-content: flex-start;
    background: linear-gradient(to right, var(--ribbon-bg) 55%, transparent);
}
.ribbon-edge-right {
    justify-content: flex-end;
    background: linear-gradient(to left, var(--ribbon-bg) 55%, transparent);
}

#brand {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 12px 0 6px;
    flex-shrink: 0;
}
#brand img {
    width: 34px;
    height: 34px;
    display: block;
}
.brand-name {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    font-weight: 600;
}
.brand-bim {
    color: var(--text);
    font-size: 14px;
    letter-spacing: 0.02em;
}
.brand-hub {
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.18em;
}

.ribbon-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px;
}

.ribbon-separator {
    width: 1px;
    height: 40px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
}

/* Ribbon tool buttons — narrow, uniform across the whole ribbon (same fixed
   width as the gbXML editor, so the icons stay aligned in a single row). */
.ribbon-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 5px 3px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--text);
    cursor: pointer;
    font-size: 10px;
    line-height: 1.12;
    font-family: inherit;
    width: 66px;
    flex-shrink: 0;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

/* Labels are short enough to stay on a single line inside the fixed width. */
.ribbon-btn span {
    text-align: center;
    white-space: nowrap;
}
.ribbon-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}
.ribbon-btn:hover {
    background: var(--field-h);
    border-color: var(--border);
}
.ribbon-btn.active {
    background: rgba(87,192,237,0.16);
    border-color: var(--accent);
    color: var(--accent-strong);
}
.ribbon-btn-del:hover {
    background: rgba(224, 85, 85, 0.10);
    border-color: var(--danger);
    color: var(--danger);
}

/* Page navigation for multi-page PDFs — small square buttons around the label. */
.ribbon-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.ribbon-nav-btn svg { width: 16px; height: 16px; }
.ribbon-nav-btn:hover:not(:disabled) {
    background: var(--field-h);
    border-color: var(--border);
}
.ribbon-nav-btn:disabled { opacity: 0.3; cursor: default; }

#pdf-page-label {
    min-width: 46px;
    text-align: center;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
    white-space: nowrap;
}

#ribbon-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    min-width: 0;
}
.file-name {
    font-size: 12px;
    color: var(--text-dim);
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Drawing scale of the open PDF — measurements are only as right as this is. */
#scale-badge {
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-strong);
    background: rgba(87, 192, 237, 0.14);
    border: 1px solid var(--accent);
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Status bubble (top-left, below ribbon) ───────────────────────────────── */
#ribbon-status {
    position: fixed;
    top: calc(var(--ribbon-h) + 12px);
    left: 12px;
    z-index: 90;
    max-width: 560px;
    padding: 5px 12px;
    font-size: 12px;
    color: var(--text-dim);
    background: var(--bubble-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    backdrop-filter: blur(4px);
}
#ribbon-status:has(#tool-status:empty) { display: none; }
#tool-status.status-error { color: var(--danger); }

/* ── Coordinate readout (bottom-right) ────────────────────────────────────── */
#coord-readout {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 90;
    padding: 4px 10px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
    background: var(--bubble-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    backdrop-filter: blur(4px);
    pointer-events: none;
}
#coord-readout:empty { display: none; }

/* ── Empty state / drop zone ──────────────────────────────────────────────── */
#drop-zone {
    position: fixed;
    inset: var(--ribbon-h) 0 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 80;
}
#drop-zone.hidden { display: none; }
#drop-zone.drag-over .drop-card {
    border-color: var(--accent);
    background: rgba(87,192,237,0.08);
}
.drop-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 42px 56px;
    background: var(--card-bg);
    border: 2px dashed var(--border);
    border-radius: 14px;
    text-align: center;
}
.drop-card svg {
    width: 52px;
    height: 52px;
    fill: var(--accent);
}
.drop-card h2 {
    font-size: 17px;
    font-weight: 600;
}
.drop-card p {
    font-size: 13px;
    color: var(--text-dim);
}
/* What a visitor without an account can and cannot open. */
.drop-card .drop-note {
    max-width: 34ch;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.45;
    opacity: 0.85;
}
.btn-primary {
    margin-top: 8px;
    padding: 9px 22px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent-h);
    border-radius: 6px;
    cursor: pointer;
}
.btn-primary:hover { background: var(--accent-h); }

/* ── Modals (drawing scale, calibration) ──────────────────────────────────── */
/* Same card styling as the gbXML editor's dialogs. */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}
.modal-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 28px 32px;
    min-width: 400px;
    max-width: 92vw;
    box-shadow: 0 12px 36px rgba(30, 40, 50, 0.20);
}
.modal-card h2 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 18px;
}
.modal-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
    font-size: 13px;
}
.modal-field input[type="number"],
.modal-field select {
    padding: 7px 10px;
    background: var(--field-bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
}
.modal-value-display {
    padding: 7px 10px;
    background: var(--field-bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-dim);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.modal-hint {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 18px;
    line-height: 1.5;
}
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}
.modal-actions .btn-primary { margin-top: 0; }
.btn-secondary {
    padding: 8px 20px;
    background: var(--field-bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}
.btn-secondary:hover { background: var(--field-h); }

/* Přihlášení a registrace jsou odkazy, ne tlačítka — musí ale sedět do řady
   s ostatními akcemi dialogu. */
.btn-link {
    display: inline-block;
    text-decoration: none;
    line-height: normal;
}

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
}
.loading-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 22px 26px;
    min-width: 300px;
}
.loading-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--field-h);
    overflow: hidden;
    margin-bottom: 12px;
}
.loading-bar span {
    display: block;
    height: 100%;
    width: 40%;
    border-radius: 3px;
    background: var(--accent);
    animation: loading-slide 1.1s ease-in-out infinite;
}
@keyframes loading-slide {
    0%   { margin-left: -40%; }
    100% { margin-left: 100%; }
}
.loading-text {
    font-size: 13px;
    color: var(--text-dim);
    text-align: center;
}
