/* TrattoCAD - interfaccia. Colori e segni presi dal marchio: blu-nero del foglio, rosso del "C",
   quadratini di aggancio e quote. Un solo accento: il rosso. */
@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-wdth-normal.woff2") format("woff2");
  font-weight: 100 900; font-stretch: 62% 125%; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-ext-wdth-normal.woff2") format("woff2");
  font-weight: 100 900; font-stretch: 62% 125%; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --ink: #0A0E15;        /* fondo del marchio */
  --sheet: #0E131C;      /* foglio scuro del disegno */
  --panel: #111723;
  --raise: #182030;
  --line: #232C3B;
  --line-soft: #19212E;
  --text: #EEF1F6;
  --muted: #8C97A9;
  --faint: #5C6679;
  --red: #E3271E;
  --red-hi: #EF3A2E;
  --red-deep: #B9160F;
  --bar-h: 52px;
  --status-h: 32px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  font-family: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-stretch: 100%;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
.defs { position: absolute; width: 0; height: 0; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font-size: 14px; line-height: 1.45; overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
input, textarea {
  font: inherit; color: var(--text); background: var(--ink); width: 100%;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
:focus-visible { outline: 2px solid var(--red-hi); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible { outline-offset: -1px; }

/* ---------- pulsanti ---------- */
.btn {
  height: 34px; padding: 0 16px; border-radius: 7px; cursor: pointer; font-weight: 550; letter-spacing: .01em;
  border: 1px solid var(--line); background: var(--raise); transition: background .15s, border-color .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--raise); border-color: #2E394B; }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.red:hover:not(:disabled) { background: var(--red-hi); border-color: var(--red-hi); }
.btn.danger { color: #FF8A80; background: transparent; }
.btn.danger:hover { border-color: var(--red); }
.btn.big { height: 46px; padding: 0 28px; font-size: 15px; border-radius: 9px; }
.link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.link:hover { color: var(--text); }

/* ---------- barra in alto ---------- */
.bar {
  position: relative; z-index: 3; height: var(--bar-h); display: flex; align-items: center; gap: 18px; padding: 0 14px 0 16px;
  background: var(--ink); border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; flex: none; }
.brand-mark { width: 38px; height: 22px; }
.wordmark { font-stretch: 125%; font-weight: 640; font-size: 14.5px; letter-spacing: .16em; }
.wordmark b { color: var(--red); font-weight: 640; margin-left: .38em; }
.filename {
  flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding-left: 18px; border-left: 1px solid var(--line); line-height: 22px;
}
.filename:empty { border-left: 0; }
.bar-actions { display: flex; gap: 8px; }

/* ---------- area di lavoro ---------- */
.work { position: absolute; top: var(--bar-h); bottom: var(--status-h); left: 0; right: 0; display: flex; }
.panel { width: 248px; flex: none; background: var(--panel); display: flex; flex-direction: column; min-height: 0; transition: margin .25s var(--ease); }
.panel.left { border-right: 1px solid var(--line-soft); }
.panel.right { border-left: 1px solid var(--line-soft); width: 300px; }
body.empty .panel.left { margin-left: -248px; }
body.empty .panel.right { margin-right: -300px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 14px 10px; }
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 640; letter-spacing: .01em; }
.count { color: var(--faint); font-weight: 500; margin-left: 4px; font-variant-numeric: tabular-nums; }
.search-wrap { padding: 0 12px 8px; }
.search { padding: 6px 9px; font-size: 13px; background: var(--ink); }

.layers { list-style: none; margin: 0; padding: 0 6px 12px; overflow: auto; flex: 1; }
.layers li { display: flex; align-items: center; gap: 10px; height: 30px; padding: 0 8px; border-radius: 6px; cursor: pointer; user-select: none; }
.layers li:hover { background: var(--raise); }
.layers .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(255,255,255,.14); }
.layers .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; font-size: 13px; }
.layers .eye { width: 16px; height: 16px; flex: none; color: var(--muted); }
.layers li.off .nm { color: var(--faint); }
.layers li.off .sw { opacity: .25; }
.layers li.off .eye { color: var(--faint); }
.layers li.off .eye .pupil { display: none; }
.layers li:not(.off) .eye .slash { display: none; }

/* ---------- foglio ---------- */
.stage { position: relative; flex: 1; min-width: 0; overflow: hidden; background: var(--sheet); touch-action: none; }
.stage.paper { background: #fff; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; }
.stage.t-pan { cursor: grab; }
.stage.t-pan.dragging { cursor: grabbing; }
.stage.t-distance, .stage.t-area, .stage.t-comment { cursor: crosshair; }

/* barra degli strumenti: lo strumento attivo porta il quadratino d'aggancio rosso del marchio */
.tools {
  position: absolute; top: 14px; left: 14px; z-index: 2; display: flex; flex-direction: column; gap: 2px; padding: 6px;
  background: rgba(17, 23, 35, .92); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(8px); box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
.tool { position: relative; width: 38px; height: 38px; border: 0; border-radius: 7px; background: transparent; display: grid; place-items: center; cursor: pointer; }
.tool:hover { background: var(--raise); }
.tool svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; transition: stroke .15s; }
.tool:hover svg { stroke: var(--text); }
.tool svg .fill { fill: var(--muted); stroke: none; }
.tool svg .dot { fill: var(--muted); stroke: none; }
.tool.active { background: rgba(227, 39, 30, .12); }
.tool.active svg { stroke: var(--red-hi); }
.tool.active svg .dot { fill: var(--red-hi); }
.tool.active svg .area { fill: rgba(239, 58, 46, .18); }
.tool.active::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 6px; height: 6px;
  border: 1.5px solid var(--red-hi); box-sizing: border-box;
}
.tools .sep { height: 1px; background: var(--line); margin: 4px 6px; }

.measure-box {
  position: absolute; top: 14px; left: 74px; z-index: 2; min-width: 210px; max-width: 320px;
  background: rgba(17, 23, 35, .94); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px 11px;
  backdrop-filter: blur(8px); font-variant-numeric: tabular-nums; box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
.measure-box .k { color: var(--muted); font-size: 12px; }
.measure-box .v { font-size: 22px; font-weight: 600; font-stretch: 112%; letter-spacing: .01em; line-height: 1.2; }
.measure-box .v.none { color: var(--faint); font-size: 15px; font-weight: 500; font-stretch: 100%; }
.measure-box .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.measure-box .hint { color: var(--faint); font-size: 12px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-soft); }

/* ---------- pagina vuota: il marchio si costruisce come un disegno ---------- */
.drop {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 24px; overflow: auto;
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, rgba(14, 19, 28, 0) 0%, var(--ink) 78%),
    linear-gradient(var(--line-soft) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--ink);
}
.hero { max-width: 560px; text-align: center; }
.construct { width: min(320px, 70vw); height: auto; display: block; margin: 0 auto 18px; overflow: visible; }
.construct .cl path, .construct .cl circle, .construct .dim path { fill: none; stroke: #7C879A; stroke-width: 4; }
.construct .c-ring { stroke-dasharray: 40 14 6 14; }
.construct .snap { fill: none; stroke: #7C879A; stroke-width: 5; }
.construct .snap.s2 { stroke: var(--red); }
.hero h1 { margin: 0 0 12px; font-size: clamp(26px, 3.2vw, 36px); font-weight: 650; font-stretch: 112%; letter-spacing: -.005em; line-height: 1.12; }
.hero p { margin: 0 auto 26px; color: var(--muted); font-size: 15.5px; line-height: 1.6; max-width: 46ch; }
.hero .fine { margin: 20px auto 0; max-width: none; font-size: 12.5px; color: var(--faint); }

/* sequenza d'apertura, una volta sola */
@media (prefers-reduced-motion: no-preference) {
  .construct .cl path, .construct .dim path { stroke-dasharray: 1000; stroke-dashoffset: 1000; animation: draw 0.9s var(--ease) forwards; }
  .construct .c-ring { opacity: 0; transform-box: fill-box; transform-origin: center; animation: ring 1s .1s var(--ease) forwards; }
  .construct .c-v { animation-delay: .15s; }
  .construct .c-ctr { animation-delay: .35s; }
  .construct .snap { opacity: 0; transform-box: fill-box; transform-origin: center; animation: snap .35s .55s var(--ease) forwards; }
  .construct .snap.s2 { animation-delay: .7s; }
  .construct .g-t, .construct .g-c { opacity: 0; transform-box: fill-box; transform-origin: center; animation: glyph .6s var(--ease) forwards; }
  .construct .g-t { animation-delay: .75s; }
  .construct .g-c { animation-delay: .9s; }
  .construct .d-ext { animation-delay: 1s; }
  .construct .d-line { animation-delay: 1.1s; }
  .construct .d-tick { animation-delay: 1.35s; }
  .hero h1, .hero p, .hero .btn, .hero .fine { opacity: 0; animation: rise .5s var(--ease) forwards; }
  .hero h1 { animation-delay: 1.05s; } .hero p { animation-delay: 1.15s; } .hero .btn { animation-delay: 1.25s; } .hero .fine { animation-delay: 1.35s; }
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes ring { from { opacity: 0; transform: rotate(-60deg) scale(.86); } to { opacity: 1; transform: none; } }
@keyframes snap { from { opacity: 0; transform: scale(1.8); } to { opacity: 1; transform: none; } }
@keyframes glyph { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* trascinando un file: una finestra di selezione con i quadratini agli angoli */
.drop-frame { position: absolute; inset: 14px; border: 1.5px dashed var(--red); border-radius: 4px; opacity: 0; pointer-events: none; transition: opacity .15s; }
.drop-frame i { position: absolute; width: 10px; height: 10px; border: 2px solid var(--red-hi); background: var(--ink); }
.drop-frame i:nth-child(1) { top: -6px; left: -6px; } .drop-frame i:nth-child(2) { top: -6px; right: -6px; }
.drop-frame i:nth-child(3) { bottom: -6px; left: -6px; } .drop-frame i:nth-child(4) { bottom: -6px; right: -6px; }
.drop-frame span { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--red); color: #fff; padding: 6px 14px; border-radius: 6px; font-weight: 600; }
.drop.hover .drop-frame { opacity: 1; }
body:not(.empty) .drop { background: rgba(10, 14, 21, .55); }
body:not(.empty) .drop .hero { display: none; }
body:not(.empty) .drop:not(.hover) { display: none; }

/* ---------- attesa, messaggi ---------- */
.busy { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(10, 14, 21, .55); backdrop-filter: blur(2px); }
.busy-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; width: min(340px, 86vw); box-shadow: 0 20px 60px rgba(0,0,0,.45); }
#busyText { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 3px; background: var(--line); border-radius: 2px; margin-top: 14px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--red); transition: width .15s; }

.toast {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 6; max-width: min(560px, 90%);
  background: var(--raise); border: 1px solid var(--line); border-left: 3px solid var(--muted);
  padding: 11px 16px; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.error { border-left-color: var(--red); }

/* ---------- commenti ---------- */
.comments-empty { padding: 18px 20px; color: var(--muted); text-align: center; }
.comments-empty svg { width: 30px; height: 30px; fill: none; stroke: var(--faint); stroke-width: 1.5; margin: 18px auto 8px; display: block; }
.comments-empty p { margin: 0; font-size: 13px; line-height: 1.55; }
.threads { list-style: none; margin: 0; padding: 2px 10px 14px; overflow: auto; flex: 1; }
.thread { position: relative; padding: 12px 12px 10px 14px; margin-bottom: 8px; border-radius: 9px; background: var(--raise); border: 1px solid transparent; cursor: pointer; transition: border-color .15s; }
.thread:hover { border-color: var(--line); }
.thread.sel { border-color: rgba(239, 58, 46, .55); }
.thread.resolved { opacity: .55; }
.thread .head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.pin-no { min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px 10px 10px 2px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; flex: none; font-variant-numeric: tabular-nums; }
.thread.resolved .pin-no { background: var(--faint); }
.thread .who { font-weight: 620; font-size: 13px; }
.thread .when { color: var(--faint); font-size: 11.5px; margin-left: auto; white-space: nowrap; }
.thread .body { white-space: pre-wrap; word-break: break-word; font-size: 13.5px; line-height: 1.5; }
.thread .body.gone { color: var(--faint); font-style: italic; }
.reply { margin: 10px 0 0 4px; padding-left: 12px; border-left: 2px solid var(--line); }
.reply .head { margin-bottom: 2px; }
.reply .who { font-size: 12.5px; }
.reply .link { margin-top: 4px; }
.thread-actions { display: flex; gap: 14px; margin-top: 10px; }
.reply-form { display: flex; gap: 6px; margin-top: 10px; }
.reply-form input { padding: 6px 9px; font-size: 13px; }
.reply-form .btn { height: 32px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.check input { width: auto; accent-color: var(--red); margin: 0; }

/* ---------- barra in basso ---------- */
.status { position: absolute; left: 0; right: 0; bottom: 0; height: var(--status-h); display: flex; align-items: stretch; background: var(--ink); border-top: 1px solid var(--line-soft); font-size: 12.5px; }
.tabs { display: flex; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.tabs button { position: relative; background: none; border: 0; padding: 0 16px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); background: var(--panel); }
.tabs button[aria-selected="true"]::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: var(--red); }
.coords { padding: 0 14px; display: flex; align-items: center; gap: 14px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.coords b { color: var(--faint); font-weight: 500; margin-right: 4px; }
.engine-tag { padding: 0 14px; display: flex; align-items: center; color: #F6B26B; white-space: nowrap; border-left: 1px solid var(--line-soft); }
.engine-tag:empty { display: none; }

/* ---------- finestre di dialogo ---------- */
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,.55); }
.dlg.small { width: min(420px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(5, 8, 12, .6); backdrop-filter: blur(2px); }
.dlg h2 { margin: 0 0 6px; font-size: 19px; font-weight: 650; font-stretch: 112%; }
.dlg .muted, .muted { color: var(--muted); margin: 0; }
.field { display: block; margin-top: 14px; }
.field span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field textarea { resize: vertical; }
.copyrow { display: flex; gap: 8px; margin: 18px 0 10px; }
.fine { color: var(--faint); font-size: 12.5px; line-height: 1.55; margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dlg-actions .danger { margin-right: auto; }

/* ---------- schermi stretti ---------- */
.only-narrow { display: none; }
@media (max-width: 860px) {
  .only-narrow { display: inline-block; }
  .panel.left { display: none; }
  .panel.right { position: absolute; right: 0; top: 0; bottom: 0; z-index: 5; width: min(320px, 88vw); transform: translateX(100%); transition: transform .22s var(--ease); box-shadow: -20px 0 50px rgba(0,0,0,.4); }
  body.empty .panel.right { margin-right: 0; }
  .panel.right.open { transform: none; }
  .wordmark { display: none; }
  .filename { display: none; }
  .engine-tag { display: none; }
  .bar { gap: 10px; }
  .tools { top: auto; bottom: 14px; left: 50%; transform: translateX(-50%); flex-direction: row; }
  .tools .sep { width: 1px; height: auto; margin: 6px 4px; }
  .measure-box { left: 12px; right: 12px; max-width: none; }
  .coords { gap: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
