/* 3D Print Estimator - main stylesheet */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --accent: #4f46e5;
    --accent-dark: #4338ca;
    --accent-soft: #eef2ff;
    --danger: #dc2626;
    --success: #16a34a;
}

html, body { height: 100%; }

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-header {
    height: 64px;
    flex: 0 0 auto;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-mark {
    width: 32px; height: 32px; border-radius: 9px; color: #fff;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    display: flex; align-items: center; justify-content: center;
}

.lang-select {
    font-family: inherit; font-size: 13.5px; font-weight: 500; color: #334155;
    background: #f1f5f9; border: 1px solid var(--line); border-radius: 9px;
    padding: 7px 10px; cursor: pointer;
}
.lang-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15); }

/* Right side of the header: language switcher; .admin-link is used by the /admin page's "Client site" back link */
.header-actions { display: flex; align-items: center; gap: 10px; }
.admin-link {
    font-size: 13.5px; font-weight: 600; color: var(--accent-dark); text-decoration: none;
    background: var(--accent-soft); border-radius: 9px; padding: 7px 12px;
    transition: background 0.15s, box-shadow 0.15s;
}
.admin-link:hover { background: #e0e7ff; }

.layout { flex: 1; display: grid; grid-template-columns: minmax(360px, 430px) 1fr; min-height: 0; }

.panel {
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    padding: 28px 26px 40px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.panel h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }

.dropzone {
    border: 1.5px dashed #c9d3e4;
    border-radius: 14px;
    background: #f8fafc;
    padding: 26px 18px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { color: #94a3b8; display: flex; justify-content: center; }
.dz-title { margin-top: 10px; font-size: 13.5px; color: var(--muted); line-height: 1.45; }

.file-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
/* Two-line row: line 1 = filename + size + stepper + price + remove, line 2 (below the name) = this
   file's material pick + color strip. The picks get a full-width line so long filenames stay visible. */
.file-row {
    display: flex; flex-direction: column; gap: 8px;
    background: #f8fafc; border: 1px solid #e9edf5; border-radius: 10px;
    padding: 10px 12px; font-size: 13.5px; cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.file-row:hover { border-color: var(--accent); background: #f4f7fe; }
.file-row.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15); }
/* Line 1: the loaded model's info — name takes all remaining width (ellipsis only for very long names) */
.file-row-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
/* Line 2, below the filename: this file's own material pick + color strip on a full-width row */
.file-row-picks {
    display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; min-width: 0;
    padding-top: 8px; border-top: 1px solid #e9edf5;
}
.file-name { color: #1e293b; font-weight: 500; flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { color: var(--muted); font-size: 12.5px; flex: 0 0 auto; }
.file-price { color: var(--accent-dark, #4338ca); font-weight: 600; font-size: 13px; flex: 0 0 auto; font-variant-numeric: tabular-nums; }
/* Quantity stepper per model row [− n +]: how many pieces of that model are needed. The row's price
   is the line total (unit × qty), so the value and buttons stay compact and right-aligned. */
.file-qty { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; }
.qty-btn {
    width: 24px; height: 24px; border-radius: 7px; padding: 0; cursor: pointer;
    border: 1px solid #d5dbe8; background: #fff; color: #334155;
    font-size: 15px; line-height: 1; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.qty-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.qty-value { min-width: 26px; text-align: center; font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; color: #1e293b; }
.file-remove {
    flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%; padding: 0;
    border: none; background: transparent; color: var(--muted); cursor: pointer;
    font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.file-remove:hover { background: #fee2e2; color: #dc2626; }
.file-list-note { margin-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.4; }

.btn {
    font-family: inherit; font-size: 14.5px; font-weight: 600;
    border: none; border-radius: 11px; padding: 13px 18px; cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s, border-color 0.15s, color 0.15s;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.3); }
.btn-block { width: 100%; }

.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn-outline { width: 100%; background: #fff; color: var(--accent); border: 1.5px solid #c7d2fe; }
.btn-outline:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }

.btn-danger-ghost { width: 100%; background: transparent; color: var(--danger); border: 1.5px solid #fecaca; }
.btn-danger-ghost:hover { background: #fef2f2; border-color: #f87171; }

.btn:disabled { cursor: not-allowed; background: #e8ecf3; color: #9aa4b2; box-shadow: none; border-color: transparent; }

/* Loading state for a button waiting on a long server call (Estimate while /upload runs the material
   estimator): keep the accent look + spinner instead of the grey :disabled styling, "progress" cursor. */
.btn.loading { display: inline-flex; align-items: center; justify-content: center; gap: 9px; cursor: progress; }
.btn-primary.loading, .btn-primary.loading:disabled { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18); }
.btn-spinner { width: 16px; height: 16px; flex: 0 0 auto; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; animation: btn-spin 0.7s linear infinite; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* Attention pulse for the buttons that point the client forward: Estimate (ready to price — model
   loaded + every unpriced row has its material & color picked), Order Print (an estimated price is on
   screen) and Send Order (the delivery form above it is fully filled in): a soft expanding accent ring.
   app.js adds .pulse in updateEstimateGate() / updateOrderPulse() / updateSendOrderPulse() (+ the
   orderFormComplete readiness state kept by updateOrderFormReadiness()) and removes it on click via
   dismissEstimatePulse() / dismissOrderPulse() / dismissSendOrderPulse(). */
.btn.pulse { animation: btn-pulse 1.5s ease-in-out infinite; }
@keyframes btn-pulse {
    0%, 100% { box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18), 0 0 0 0 rgba(79, 70, 229, 0.45); }
    50% { box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18), 0 0 0 10px rgba(79, 70, 229, 0); }
}

.divider { height: 1px; background: var(--line); flex: 0 0 auto; }

/* Per-file material pick + color strip on the second line of each model row (each row is priced with its own filament) */
.file-material {
    flex: 0 1 auto; max-width: min(260px, 100%); padding: 6px 8px; font-family: inherit; font-size: 12.5px;
    color: #334155; background: #fff; border: 1px solid #d5dbe8; border-radius: 8px; cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.file-material:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14); }

/* FDM/SLA segmented toggle above the dropzone: sets the technology NEWLY added files start as (each
   row keeps its own pick). The SLA button is disabled while /api/resins has no configured resin —
   the backend would reject an SLA upload otherwise. */
.tech-toggle { display: inline-flex; gap: 4px; padding: 4px; background: #eef2f9; border-radius: 10px; width: fit-content; }
.tech-btn {
    font-family: inherit; font-size: 13px; font-weight: 600; color: #475569; cursor: pointer;
    border: none; background: transparent; border-radius: 7px; padding: 6px 20px;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.tech-btn:hover:not(:disabled) { color: var(--accent); }
.tech-btn.active { background: #fff; color: var(--accent-dark, #4338ca); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.15); }
.tech-btn:disabled { cursor: not-allowed; color: #b6bfce; }

/* SLA resin pick on the second line of a model row (mirrors .file-material): material type from /api/resins */
.file-resin {
    flex: 0 1 auto; max-width: min(320px, 100%); padding: 6px 8px; font-family: inherit; font-size: 12.5px;
    color: #334155; background: #fff; border: 1px solid #d5dbe8; border-radius: 8px; cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.file-resin:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14); }
/* Rows carry data-tech="fdm"|"sla": each row shows exactly its own pickers — filament+color for FDM,
   resin type + that type's color palette (its .file-resin-colors strip) for SLA */
.file-row[data-tech="sla"] .file-material, .file-row[data-tech="sla"] .file-colors:not(.file-resin-colors) { display: none; }
.file-row[data-tech="fdm"] .file-resin, .file-row[data-tech="fdm"] .file-resin-colors { display: none; }
/* "ⓘ" info button next to each picker: hover/focus/click opens the styled .tip-pop with a short tip on
   when that material/resin is best. Mirrors the pickers' per-row visibility — FDM rows show the filament
   hint, SLA rows the resin one */
.pick-hint {
    flex: 0 0 auto; align-self: center; width: 20px; height: 20px; padding: 0; border-radius: 50%;
    border: 1px solid var(--line); background: transparent; color: var(--muted);
    font-size: 12px; line-height: 1; cursor: help; transition: border-color 0.15s, color 0.15s;
}
.pick-hint:hover { border-color: var(--accent); color: var(--accent); }
.file-row[data-tech="sla"] .pick-hint-material, .file-row[data-tech="fdm"] .pick-hint-resin { display: none; }
/* Small-part hint under an estimated FDM row (bounding box below the configured SLA threshold) */
.file-sla-hint { flex: 1 1 100%; font-size: 12px; color: var(--accent-dark, #4338ca); line-height: 1.4; }

/* One-shot "switch this small part to SLA?" dialog (built in order-list.js after an estimate flags a
   model via suggest_sla) — same card language as the admin delete-confirmation overlay */
.sla-overlay {
    position: fixed; inset: 0; z-index: 1200; /* above toasts, same band as the celebration overlay */
    background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; padding: 20px;
}
.sla-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28); max-width: 430px; width: 100%; padding: 22px 24px;
    animation: slaPopIn 0.16s ease-out; /* entrance only — closing is instant on purpose */
}
@keyframes slaPopIn { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; transform: none; } }
.sla-title { margin: 0 0 8px; font-size: 16.5px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
.sla-text { margin: 0; font-size: 13.5px; line-height: 1.55; color: var(--muted); word-break: break-word; }
.sla-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.sla-actions .btn { width: auto; padding: 9px 16px; font-size: 13.5px; border-radius: 9px; }

@media (prefers-reduced-motion: reduce) {
    .sla-card { animation: none; }
}
/* Own line below the filename — full width available, swatches wrap to a second row only if there are many */
.file-colors { flex: 1 1 auto; min-width: 0; display: inline-flex; flex-wrap: wrap; gap: 5px; align-items: center; }

/* Color strip: one square swatch per Spoolman color of this row's material (compact inside the row) */
.swatch {
    width: 24px; height: 24px; border-radius: 6px; padding: 0; flex: 0 0 auto; cursor: pointer;
    position: relative; border: 1px solid rgba(15, 23, 42, 0.3);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.swatch:hover:not(:disabled) { transform: scale(1.12); }
.swatch:disabled { opacity: 0.5; cursor: not-allowed; }
.swatch:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.4); }
.swatch.selected { border-color: transparent; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.swatch-check {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; line-height: 1; opacity: 0; pointer-events: none;
}
.swatch.selected .swatch-check { opacity: 1; }
.palette-hint { font-size: 12.5px; color: var(--muted); font-style: italic; }

.materials-status { margin: 0; font-size: 12.5px; color: var(--danger); line-height: 1.4; }
.materials-status.hint { color: var(--muted); }
.retry-link { color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }

.price-card {
    background: var(--accent-soft); border: 1px solid #dbe3fd; border-radius: 12px;
    padding: 14px 16px; min-height: 52px; display: flex; align-items: center;
}
#priceInfo { width: 100%; font-size: 16px; font-weight: 600; color: #3730a3; letter-spacing: -0.01em; }

/* Optional extras (order options): checkbox rows above the price card, hidden when none configured */
.options-section { margin-bottom: 14px; }
.options-section h3 { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.options-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.option-row label {
    display: flex; align-items: center; gap: 9px; cursor: pointer;
    background: #fff; border: 1px solid #d8e0ee; border-radius: 10px; padding: 9px 12px;
    font-size: 14px; color: var(--ink); transition: border-color 0.15s, box-shadow 0.15s;
}
.option-row label:hover { border-color: var(--accent); }
.option-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex: 0 0 auto; }
.option-name { flex: 1 1 auto; font-weight: 500; }
.option-price { font-size: 13px; font-weight: 700; color: #3730a3; white-space: nowrap; }
.option-free { font-size: 12.5px; font-weight: 600; color: var(--muted); font-style: italic; white-space: nowrap; }

.client-form h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.client-form input[type="text"], .client-form input[type="email"], .client-form input[type="tel"], .client-form textarea {
    width: 100%; padding: 12px 13px; margin-bottom: 12px;
    border: 1px solid #d8e0ee; border-radius: 10px; background: #fff;
    font-family: inherit; font-size: 14px; color: var(--ink);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.client-form textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
.client-form input::placeholder, .client-form textarea::placeholder { color: #98a2b3; }
.client-form input:focus, .client-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14); }
/* Inline field validation errors (order form): hidden while empty so the layout never shifts */
.client-form .field-error { display: none; font-size: 12px; color: var(--danger); line-height: 1.35; margin: -6px 2px 10px; }
.client-form .field-error:not(:empty) { display: block; }
.client-form input.invalid, .client-form textarea.invalid { border-color: var(--danger); }
.client-form input.invalid:focus, .client-form textarea.invalid:focus { outline: none; border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14); }

.viewer-wrap {
    position: relative; min-width: 0; min-height: 0;
    /* Mid slate-blue studio backdrop (was near-black navy): dark filaments — especially black —
       need a clearly lighter background to keep silhouette contrast. Keep in sync with the
       scene.fog color in js/app.js (~line 35). */
    background: radial-gradient(120% 90% at 70% 10%, #3f5178 0%, #26334e 55%, #1a2439 100%);
}
#threejs-container { position: absolute; inset: 0; }
#threejs-container canvas { display: block; }

.viewer-overlay {
    position: absolute; inset: 0; z-index: 2; pointer-events: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    transition: opacity 0.25s, visibility 0.25s;
}
.viewer-overlay.hidden { opacity: 0; visibility: hidden; }
.viewer-overlay svg { width: 54px; height: 54px; color: #64748b; opacity: 0.6; }
#viewerEmptyText { font-size: 14px; line-height: 1.5; max-width: 320px; text-align: center; color: #8aa0c6; }

.viewer-hint {
    position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 2;
    font-size: 12px; color: #9fb0cc; pointer-events: none; white-space: nowrap;
    background: rgba(8, 13, 24, 0.55); border: 1px solid rgba(148, 163, 184, 0.18);
    padding: 6px 12px; border-radius: 999px; backdrop-filter: blur(4px);
}

@media (max-width: 920px) {
    .layout { display: flex; flex-direction: column; }
    .viewer-wrap { order: -1; height: 42vh; border-bottom: 1px solid var(--line); }
    .panel { border-right: none; flex: 1; padding: 20px 18px 32px; }
}

/* On narrow phones the model-name + stepper + line total already fill a row — drop the size. */
@media (max-width: 480px) {
    .file-row .file-size { display: none; }
}

/* ---------------- Toast notifications (non-blocking replacement for alert()) ---------------- */
.toast-container {
    position: fixed; bottom: 24px; right: 24px; z-index: 1000;
    display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}

.toast {
    display: flex; align-items: center; gap: 10px;
    max-width: min(340px, calc(100vw - 48px));
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: 11px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
    font-size: 13.5px; font-weight: 500; color: var(--ink);
    opacity: 0; transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show { opacity: 1; transform: translateY(0); }

.toast-icon {
    flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; color: #fff;
}

.toast-success .toast-icon { background: var(--success); }
.toast-error   .toast-icon { background: var(--danger); }

/* ---------------- Styled tooltip popup (replaces the native title boxes) ---------------- */
/* One shared floating card for every [data-tip] trigger (ⓘ hint buttons, FDM/SLA toggle, color swatches):
   same surface/shadow family as toasts, dark ink so it reads as a tooltip rather than a notification.
   Positioned by the JS engine in app.js (centered above its trigger, clamped to the viewport). */
.tip-pop {
    position: fixed; z-index: 1300; /* above toasts (1000) and the celebration overlay (1200) */
    max-width: min(280px, calc(100vw - 16px));
    padding: 9px 12px;
    background: var(--ink); color: #f8fafc;
    border-radius: 10px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.28);
    font-size: 12.5px; line-height: 1.45; text-align: left;
    opacity: 0; visibility: hidden; transform: translateY(4px); pointer-events: none; /* never blocks clicks */
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.tip-pop.show { opacity: 1; visibility: visible; transform: translateY(0); }

/* ---------------- Order celebration (confetti + success card; replaces the old alert()) ---------------- */
.celebration-overlay {
    position: fixed; inset: 0; z-index: 1200; /* above toasts (1000) — it owns this moment */
    display: flex; align-items: center; justify-content: center;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(3px);
    opacity: 0; cursor: pointer;
    transition: opacity 0.25s ease;
}

.celebration-overlay.show { opacity: 1; }

.celebration-card {
    background: var(--surface); border-radius: 18px; padding: 34px 40px 30px;
    text-align: center; max-width: min(420px, calc(100vw - 48px));
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.35);
    opacity: 0; transform: scale(0.8) translateY(12px);
    /* springy pop-in with a slight overshoot */
    transition: transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.22s ease;
}

.celebration-overlay.show .celebration-card { opacity: 1; transform: scale(1) translateY(0); }

.celebration-check {
    width: 72px; height: 72px; margin: 0 auto 18px; border-radius: 50%; color: #fff;
    background: linear-gradient(135deg, #4f46e5, #7c3aed); /* matches .brand-mark */
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 10px 24px rgba(79, 70, 229, 0.35);
}

.celebration-check svg { width: 36px; height: 36px; }
/* the checkmark draws itself in right after the card pops */
.celebration-check polyline { stroke-dasharray: 30; stroke-dashoffset: 30; transition: stroke-dashoffset 0.45s ease 0.28s; }
.celebration-overlay.show .celebration-check polyline { stroke-dashoffset: 0; }

.celebration-title { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.celebration-sub { margin-top: 8px; font-size: 14px; line-height: 1.5; color: var(--muted); }

/* confetti falls in front of the card but never eats pointer events */
.confetti-canvas { position: fixed; inset: 0; z-index: 1210; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
    .celebration-overlay, .celebration-card, .celebration-check polyline { transition: none; }
    .btn.pulse { animation: none; } /* the attention pulses are motion — respect the preference */
}
