/*
 * Adapted from app/style.css (see UI-STYLE-GUIDE.md for the design tokens this all comes from).
 * Differences from the local app's stylesheet, all because this now lives INSIDE a normal
 * WordPress page instead of owning the whole browser tab (see SLIDER-CSS-IN-HOST-PAGE-SNIPPET.md
 * for the full diagnosis - three separate host-page issues, not one):
 *   1. Everything is scoped under .halftone-web-app instead of bare html/body - a shortcode
 *      must never restyle the rest of the site.
 *   2. #app gets a bounded height (not 100vh) - it sits as a panel within the page's content
 *      area, with its own internal layout/scrolling, not the whole viewport.
 *   3. Every font-size below is a fixed px value, never rem - rem is relative to the HOST
 *      page's <html> font-size, not this component, so a theme/Elementor Kit that sets a
 *      bigger root font-size (common - 18px instead of the browser default 16px) would inflate
 *      every rem-based size here, even though the app was designed against 16px=1rem.
 *   4. font-family AND line-height are both reset with !important on every descendant - a
 *      host theme's global line-height (often 1.6-1.8, fine for body text) otherwise still
 *      wins on every label/line in the panel even with font-family alone reset.
 *   5. input[type=range] is fully hand-drawn (track + thumb, both browser engines) instead of
 *      relying on appearance:auto + accent-color - some host themes' own global slider reset
 *      (e.g. a bare `input[type=range]{-webkit-appearance:none}` somewhere in their CSS) can
 *      partially override our rendering while leaving native pieces underneath, producing a
 *      "slider drawn on top of a slider" look. Hand-drawing every part with !important removes
 *      any dependency on what the host page does.
 */
.halftone-web-app {
  --bg:          #0d1117;
  --panel:       #12161e;
  --card:        #161b24;
  --line:        rgba(255,255,255,.14);
  --text:        #e8ecf2;
  --muted:       #98a2b3;
  --accent:      #dca24a;
  --accent-soft: #d3a05a;
  --accent2:     #2f86ff;
  --ok:          #33bd6b;
  --input:       #10151d;

  background: var(--bg); color: var(--text);
  direction: rtl;
  border-radius: 14px; overflow: hidden;
}
.halftone-web-app, .halftone-web-app * {
  font-family: "Rubik", "Segoe UI", system-ui, sans-serif !important;
  line-height: normal !important;
}
.halftone-web-app *, .halftone-web-app *::before, .halftone-web-app *::after { box-sizing: border-box; }

.halftone-web-app #app   { display: flex; flex-direction: column; height: 900px; max-height: 85vh; }
.halftone-web-app #topbar{ flex-shrink: 0; background: var(--panel);
         border-bottom: 1px solid var(--line); padding: 12px 22px;
         display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.halftone-web-app #topbar h1 { font-size: 20.8px; font-weight: 800; color: var(--accent); letter-spacing: .3px; margin: 0; }
.halftone-web-app #topbar .subtitle { font-size: 13.6px; color: var(--muted); margin-top: 2px; }
.halftone-web-app .topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }
.halftone-web-app .topbar-actions button.ghost { width: auto; font-size: 12.8px; padding: 14px 16px; white-space: nowrap; }
.halftone-web-app #main  { display: flex; flex: 1; min-height: 0; }

.halftone-web-app #viewport { position: relative; flex: 1; min-width: 0; background: #05070a; overflow: hidden;
            display: flex; align-items: center; justify-content: center; }
.halftone-web-app #panel    { width: 340px; flex-shrink: 0; background: var(--panel);
            border-left: 1px solid var(--line); overflow-y: auto; padding: 12px 14px; }

.halftone-web-app #mobile-notice { display: none; } /* shown only under the @media block at the
                                                         very end of this file - see there */

.halftone-web-app canvas#preview2d { display: block; max-width: 100%; max-height: 100%; }
.halftone-web-app #preview3d { position: absolute; inset: 0; }
.halftone-web-app #preview3d[hidden], .halftone-web-app canvas#preview2d[hidden] { display: none !important; }

.halftone-web-app .card   { background: var(--card); border: 1px solid var(--line);
          border-radius: 11px; padding: 9px 12px; margin-bottom: 10px; }
.halftone-web-app .card h2{ font-size: 15.2px; color: var(--accent); margin: 0 0 8px;
          font-weight: 700; letter-spacing: .2px; }
.halftone-web-app .card.locked        { opacity: .5; pointer-events: none; }
.halftone-web-app .card.locked h2     { color: var(--muted); }
.halftone-web-app .card p.hint        { font-size: 12.48px; color: var(--muted); line-height: 1.5 !important; margin: 0 0 10px; }
.halftone-web-app .card p.hint.warn   { color: var(--accent); font-weight: 600; }

.halftone-web-app .accordion-card { padding: 0; overflow: hidden; }
.halftone-web-app .accordion-header {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: transparent; border: none; cursor: pointer; padding: 9px 12px;
  font-size: 15.2px; color: var(--accent); font-weight: 700; letter-spacing: .2px;
  font-family: inherit; text-align: inherit;
}
.halftone-web-app .accordion-header:hover { color: var(--accent-soft); }
.halftone-web-app .accordion-chevron { color: var(--muted); font-size: 12px; transition: transform .15s ease; transform: rotate(-90deg); }
.halftone-web-app .accordion-card.open .accordion-chevron { transform: rotate(0deg); }
.halftone-web-app .accordion-body { padding: 4px 12px 9px; }
.halftone-web-app .accordion-body[hidden] { display: none; }

.halftone-web-app button.primary {
  background: var(--accent-soft); color: #201603; border: none;
  border-radius: 9px; padding: 11px; font-weight: 700; font-size: 14.72px;
  cursor: pointer; width: 100%;
}
.halftone-web-app button.primary:hover    { filter: brightness(1.06); }
.halftone-web-app button.primary:disabled { opacity: .45; cursor: not-allowed; }
.halftone-web-app button.primary.alt { background: var(--ok); color: #fff; }

.halftone-web-app button.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 7px 10px; font-size: 13.12px; cursor: pointer; width: 100%;
}
.halftone-web-app button.ghost:hover        { color: var(--text); border-color: var(--accent2); }
.halftone-web-app button.ghost.accent { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.halftone-web-app button.ghost.accent:hover { background: rgba(220,162,74,.12); border-color: var(--accent-soft); color: var(--accent-soft); }

.halftone-web-app .tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.halftone-web-app .pattern-tabs { display: grid; grid-template-columns: repeat(3, 1fr); }
.halftone-web-app .tab  { flex: 1; background: transparent; color: var(--muted);
        border: 1px solid var(--line); border-radius: 9px; padding: 9px 6px;
        font-weight: 600; font-size: 13.12px; cursor: pointer; }
.halftone-web-app .tab:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.halftone-web-app .tab.active   { color: #201603; background: var(--accent-soft); border-color: var(--accent-soft); }
.halftone-web-app .tab:disabled { opacity: .4; cursor: not-allowed; }

.halftone-web-app .field { margin-bottom: 10px; }
.halftone-web-app .field label { display: flex; justify-content: space-between; font-size: 12.48px;
               color: var(--muted); margin-bottom: 4px; }
.halftone-web-app .field label .val { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.halftone-web-app .field label .val-wrap { display: inline-flex; align-items: center; gap: 4px; }
.halftone-web-app .val-editable { cursor: text; border-bottom: 1px dashed var(--muted); }
.halftone-web-app .val-editable:hover { border-color: var(--accent2); color: var(--text); }
.halftone-web-app .val-edit-input {
  width: 4.5em; background: var(--input); border: 1px solid var(--accent2);
  color: var(--text); border-radius: 4px; padding: 1px 4px; font: inherit;
  font-variant-numeric: tabular-nums; direction: ltr; text-align: left;
}
.halftone-web-app .reset-param {
  background: transparent; border: none; color: var(--accent2);
  font-size: 14.4px; line-height: 1 !important; padding: 0 1px; cursor: pointer;
}
.halftone-web-app .reset-param:hover { color: var(--text); }
.halftone-web-app .reset-param[hidden] { display: none; }

/* Sliders - fully hand-drawn (see the file-level comment above for why appearance:auto +
   accent-color isn't reliable inside a host page). --range-progress is a 0-100% custom
   property, set once at init and updated on every 'input' event - see updateRangeFill() in
   assets/js/ui.js. Gradient direction is "to left" because this app is always dir="rtl" (the
   fill visually starts from the right edge, where RTL reading starts) - see
   SLIDER-CSS-IN-HOST-PAGE-SNIPPET.md §4; would need to be "to right" in an LTR app. */
.halftone-web-app .field input[type=range] {
  --range-progress: 0%;
  -webkit-appearance: none !important; appearance: none !important;
  width: 100%; height: 16px; margin: 0; padding: 0 !important;
  background: none !important; border: none !important; box-shadow: none !important;
  cursor: pointer;
}
.halftone-web-app .field input[type=range]::-webkit-slider-runnable-track {
  -webkit-appearance: none !important;
  height: 3px !important; border-radius: 999px !important;
  background: linear-gradient(
    to left,
    var(--accent) 0%, var(--accent) var(--range-progress),
    var(--line) var(--range-progress), var(--line) 100%
  ) !important;
  border: none !important; box-shadow: none !important;
}
.halftone-web-app .field input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none !important;
  width: 14px !important; height: 14px !important; border-radius: 50% !important;
  background: var(--accent) !important; border: none !important; box-shadow: none !important;
  margin-top: -5.5px !important; cursor: pointer;
}
.halftone-web-app .field input[type=range]::-moz-range-track {
  height: 3px !important; border-radius: 999px !important;
  background: var(--line) !important; border: none !important; box-shadow: none !important;
}
.halftone-web-app .field input[type=range]::-moz-range-progress {
  height: 3px !important; border-radius: 999px !important;
  background: var(--accent) !important; border: none !important; box-shadow: none !important;
}
.halftone-web-app .field input[type=range]::-moz-range-thumb {
  width: 14px !important; height: 14px !important; border-radius: 50% !important;
  background: var(--accent) !important; border: none !important; box-shadow: none !important;
}

.halftone-web-app .field input[type=color] {
  width: 100%; height: 34px; background: var(--input); border: 1px solid var(--line);
  border-radius: 7px; padding: 3px; cursor: pointer;
}
.halftone-web-app .field input[type=number] {
  width: 100%; background: var(--input); border: 1px solid var(--line);
  color: var(--text); border-radius: 7px; padding: 6px; font-size: 13.6px;
}
.halftone-web-app .field input[type=checkbox] { accent-color: var(--accent2); width: 15px; height: 15px; }
.halftone-web-app .checkrow { display: flex; align-items: center; gap: 8px; font-size: 13.6px; color: var(--text); margin-bottom: 10px; }

.halftone-web-app .select {
  width: 100%; background: var(--input); border: 1px solid var(--line);
  color: var(--text); border-radius: 9px; padding: 10px 12px; font-size: 14.4px;
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%238a93a6' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: left 12px center;
}
.halftone-web-app .select:hover, .halftone-web-app .select:focus { border-color: var(--accent); outline: none; }

.halftone-web-app .spinner { position: absolute; inset: 0; display: flex; flex-direction: column;
           align-items: center; justify-content: center; gap: 14px;
           background: rgba(16,19,26,.6); color: var(--text); z-index: 5; }
.halftone-web-app .spinner[hidden] { display: none; }
.halftone-web-app .spin    { width: 44px; height: 44px; border: 4px solid var(--line);
           border-top-color: var(--accent); border-radius: 50%;
           animation: halftone-web-spin 1s linear infinite; }
@keyframes halftone-web-spin { to { transform: rotate(360deg); } }

.halftone-web-app .viewport-banners { position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
                     display: flex; flex-direction: column; }
.halftone-web-app .banner { background: linear-gradient(180deg, #3a2c0c, #2c2109);
          color: var(--accent); border-top: 1px solid rgba(220,162,74,.5);
          text-align: center; font-size: 13.6px; font-weight: 600;
          padding: 9px 16px; pointer-events: none; }
.halftone-web-app .banner[hidden] { display: none; }

.halftone-web-app .stats-banner { background: rgba(18,22,30,.92); color: var(--text);
                border-top: 1px solid var(--line); text-align: center;
                font-size: 13.6px; font-weight: 700; letter-spacing: .2px;
                padding: 9px 16px; pointer-events: none; font-variant-numeric: tabular-nums; }
.halftone-web-app .stats-banner[hidden] { display: none; }
.halftone-web-app .stats-banner .sep { color: var(--muted); margin: 0 8px; font-weight: 400; }

.halftone-web-app .overlay-tools        { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; z-index: 3; }
.halftone-web-app .overlay-tools button { background: rgba(30,36,48,.8); color: var(--text);
                        border: 1px solid var(--line); border-radius: 8px;
                        padding: 6px 10px; font-size: 13.12px; cursor: pointer; white-space: nowrap; }
.halftone-web-app .overlay-tools button.active { color: #201603; background: var(--accent-soft); border-color: var(--accent-soft); }
.halftone-web-app .overlay-tools button:hover { border-color: var(--accent2); }

.halftone-web-app .upload-drop {
  border: 2px dashed var(--line); border-radius: 9px; padding: 18px 10px;
  text-align: center; color: var(--muted); font-size: 13.12px; cursor: pointer;
  margin-bottom: 8px; transition: border-color .12s, background .12s, color .12s;
}
.halftone-web-app .upload-drop:hover { border-color: var(--accent); color: var(--text); }
.halftone-web-app .upload-drop.drag-over {
  border-style: solid; border-color: var(--accent2); color: var(--text);
  background: rgba(47,134,255,.10);
}
.halftone-web-app .upload-drop.has-image { border-style: solid; border-color: var(--ok); color: var(--text); }

.halftone-web-app #file-input { display: none; }

/* Credit cost shown on the download button (see includes/class-shortcode.php) - only rendered
   at all when the admin-configured cost is > 0 (see class-admin-settings.php). */
/* Single-line button: "הורדת קובץ STL" + a compact number/icon badge, never wrapping onto a
   second line and never spelled out as "(עולה N קרדיטים)" - matches the reference screenshot
   the cost was checked against. */
.halftone-web-app #btn-export {
  display: flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.halftone-web-app .credit-cost { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; }
.halftone-web-app .credit-cost img { width: 16px; height: 16px; }

/* Insufficient-credits notice - a normal/expected outcome, not a server fault, so it's a small
   inline line near the button rather than the red msgbox (see error-msgbox-snippet.md's own
   guidance: "normal" errors get inline status, only server/communication faults get the modal). */
.halftone-web-app .credit-status { font-size: 12.8px; color: var(--muted); margin-top: 6px; text-align: center; }
.halftone-web-app .credit-status.error { color: #ff8a8a; }

/* msgbox - copied verbatim from error-msgbox-snippet.md (the shared "house standard" dialog
   for server/communication faults specifically). */
.halftone-web-app .msgbox { position: fixed; inset: 0; z-index: 9999; display: flex;
          align-items: center; justify-content: center; padding: 20px;
          background: rgba(8,11,20,.66); }
.halftone-web-app .msgbox[hidden] { display: none; }
.halftone-web-app .msgbox-card {
  width: min(430px,100%); text-align: center; direction: rtl;
  background: #1e2438; border: 1px solid #2b3350; border-top: 4px solid #ff5c72;
  border-radius: 16px; padding: 26px 24px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
  animation: halftone-web-msgbox-pop .16s ease-out;
}
.halftone-web-app .msgbox-icon  { font-size: 40px; line-height: 1 !important; margin-bottom: 10px; }
.halftone-web-app .msgbox-title { margin: 0 0 8px; font-size: 18px; font-weight: 700; color: #e7eaf3; }
.halftone-web-app .msgbox-msg   { margin: 0 0 20px; font-size: 14px; line-height: 1.65 !important; color: #9aa3bd; }
.halftone-web-app .msgbox-btn   { min-width: 130px; padding: 10px 18px; border-radius: 10px; border: none;
                font-weight: 700; font-size: 14px; color: #fff; cursor: pointer;
                background: linear-gradient(90deg, #5b8cff, #7c5cff); }
.halftone-web-app .msgbox-btn:hover { filter: brightness(1.08); }
@keyframes halftone-web-msgbox-pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .halftone-web-app .msgbox-card { animation: none; } }

/* "Please log in" note - copied verbatim from login-note-snippet.md, renamed to a plugin
   -specific class (as the snippet itself recommends) so it can't collide with another app's
   copy of the same block on the same site. Also gets the fixed-px/line-height treatment since
   it's a host-page fragment too, just like the app itself. */
.halftone-web-login-note, .halftone-web-login-note * {
  font-family: "Rubik", "Segoe UI", system-ui, sans-serif !important;
}
.halftone-web-login-note {
  direction: rtl; box-sizing: border-box; margin: 0 auto; max-width: 760px;
  padding: 30px 28px; text-align: center; border-radius: 16px;
  font-size: 19px; line-height: 1.6 !important; font-weight: 600; color: #e7ecff;
  background: linear-gradient(180deg,#0f1636,#0a1024);
  border: 1px solid rgba(255,214,120,.55);
  box-shadow:
    0 0 0 1px rgba(255,214,120,.12),
    0 0 34px rgba(120,150,255,.28),
    inset 0 0 26px rgba(120,150,255,.10);
}
.halftone-web-login-note a {
  color: #ffd66b; font-weight: 700; text-decoration: none;
  border-bottom: 1px solid rgba(255,214,120,.5); padding-bottom: 1px;
}
.halftone-web-login-note a:hover { color: #ffe49a; border-color: rgba(255,214,120,.9); }

/* ---------------------------------------------------------------------------------------------
 * Mobile layout (see MOBILE-RESPONSIVE-GUIDE.md). MUST stay the LAST block in this file: every
 * selector below (.halftone-web-app #panel etc.) has the exact same specificity as its base
 * rule earlier in the file (same class + same id) - with equal specificity, whichever rule is
 * LATER in the file wins, @media condition or not. Moving this block earlier would silently
 * make the media query lose to the unconditional base rule on real phones.
 *
 * This assumes the page's own <head> has <meta name="viewport" content="width=device-width,
 * initial-scale=1"> - virtually every modern WordPress theme already sets this site-wide, but
 * if a phone shows no change at all after installing this update, that tag missing is the
 * first thing to rule out (see the guide's §2) - without it, mobile browsers render the whole
 * page at a fake ~980px-wide viewport and zoom out, so this @media (max-width: 768px) block
 * never actually activates.
 * --------------------------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .halftone-web-app #main    { flex-direction: column; }
  /* order:-1 puts the viewport visually first despite #panel coming first in the actual markup
     (see class-shortcode.php) - the guide's own example assumes viewport-before-panel source
     order, which isn't true here; flex order achieves the same "viewport rises to the top"
     result without reordering the DOM (which assets/js/ui.js's element lookups don't care about
     either way, but there's no reason to touch markup when a pure-CSS reorder does the job). */
  .halftone-web-app #viewport{ flex: 0 0 42vh; min-height: 220px; order: -1; }
  .halftone-web-app #panel   { width: 100%; flex: 1; min-height: 0; border-left: none;
                                border-top: 1px solid var(--line); }

  .halftone-web-app #mobile-notice {
    display: block; text-align: center; font-weight: 700; font-size: 13px;
    background: var(--accent-soft); color: #201603;
    border-radius: 9px; padding: 8px 10px; margin-bottom: 10px;
  }
}
