/* ═══════════════════════════════════════════════════════════════
   Overlays — Modal, Toast, Tooltips, Context Menu, Help, Tour
   ═══════════════════════════════════════════════════════════════ */

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed; top: -60px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff;
  padding: 10px 16px; border-radius: var(--r-sm);
  z-index: 500; display: flex; align-items: center; gap: 8px;
  opacity: 0; transition: top .35s ease, opacity .35s ease;
  box-shadow: var(--shadow-lg); font-weight: 500;
}
.toast.show { top: 14px; opacity: 1; }
.toast .check { width: 16px; height: 16px; position: relative; }
.toast .check:after {
  content: ''; position: absolute; left: 2px; top: -1px;
  width: 9px; height: 14px;
  border-right: 3px solid #fff; border-bottom: 3px solid #fff;
  transform: rotate(45deg);
}


/* ── Tooltips ───────────────────────────────────────────────── */
.hint { position: relative; display: inline-flex; align-items: center; }
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--separator-opaque); color: var(--text-tertiary);
  font-weight: 700; font-size: 12px; line-height: 16px; margin-left: 6px;
  cursor: help; background: transparent;
}
.tip {
  position: absolute; top: 50%; left: 22px; transform: translateY(-50%);
  min-width: 360px; max-width: min(560px, calc(100vw - 56px));
  background: var(--bg-primary); color: var(--text-secondary);
  padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--separator-opaque); box-shadow: var(--shadow-lg);
  font-size: 12px; line-height: 1.45; opacity: 0; pointer-events: none;
  transition: .15s; z-index: 200;
}
.hint:hover .tip { opacity: 1; }
.tip::before { content: ""; position: absolute; left: -6px; top: 50%; transform: translateY(-50%); width: 0; height: 0; border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-right: 6px solid var(--separator-opaque); }
.tip::after { content: ""; position: absolute; left: -5px; top: 50%; transform: translateY(-50%); width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-right: 5px solid var(--bg-primary); }


/* ── Context Menu ───────────────────────────────────────────── */
.fp2d-context-menu { position: fixed; z-index: 300; background: var(--bg-primary); border: 1px solid var(--separator-opaque); border-radius: var(--r-sm); box-shadow: var(--shadow-lg); min-width: 160px; padding: 4px 0; font-size: 13px; }
.fp2d-ctx-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 12px; border: none; background: transparent; text-align: left; cursor: pointer; color: var(--text-primary); transition: background 0.1s; font-family: inherit; }
.fp2d-ctx-btn:hover:not(:disabled) { background: var(--bg-secondary); }
.fp2d-ctx-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.fp2d-ctx-btn.danger { color: var(--red); }
.fp2d-ctx-btn.danger:hover:not(:disabled) { background: rgba(255,59,48,0.06); }
.fp2d-ctx-btn .icon { width: 18px; text-align: center; }
.fp2d-ctx-divider { height: 1px; background: var(--separator); margin: 4px 0; }


/* ── Modal ──────────────────────────────────────────────────── */
.calc-modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 400; }
.calc-modal-backdrop[hidden] { display: none !important; }
.calc-modal {
  width: min(520px, calc(100% - 32px)); max-height: calc(100% - 32px);
  background: var(--bg-primary); border-radius: var(--r-lg);
  border: 0.5px solid var(--separator); box-shadow: var(--shadow-xl);
  padding: 24px; display: flex; flex-direction: column; box-sizing: border-box;
}
.calc-modal header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.calc-modal__title { margin: 0; font-size: 18px; font-weight: 700; color: var(--text-primary); display: flex; align-items: center; }
.calc-modal__icon { font-size: 24px; margin-right: 10px; line-height: 1; }
.calc-modal__close { background: none; border: none; font-size: 22px; color: var(--text-tertiary); cursor: pointer; padding: 0; line-height: 1; }
.calc-modal__close:hover { color: var(--text-primary); }
.calc-modal__body { font-size: 13px; line-height: 1.55; color: var(--text-secondary); overflow: auto; }
.calc-modal__subtitle { margin: 0 0 14px; font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.calc-modal__features { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.calc-modal__feature {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--bg-secondary); border: 1px solid var(--separator);
  transition: background var(--dur-fast, 150ms);
}
.calc-modal__feature:hover { background: var(--accent-bg); }
.calc-modal__feature-icon { font-size: 20px; flex-shrink: 0; line-height: 1.3; }
.calc-modal__feature b { display: block; font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.calc-modal__feature span { font-size: 11px; color: var(--text-tertiary); line-height: 1.4; }
.calc-modal__list { margin: 6px 0 0 18px; padding: 0; }
.calc-modal__list li { margin-bottom: 4px; }
.calc-modal__dont-show { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-tertiary); cursor: pointer; margin-right: auto; }
.calc-modal__footer { margin-top: 14px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.calc-modal .btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
  font-weight: 600; padding: 9px 20px; border-radius: var(--r-sm);
}
.calc-modal .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
body.has-modal { overflow: hidden; }


/* ── Help Panel ─────────────────────────────────────────────── */
.drawing-help-panel {
  display: none; position: fixed; top: 80px; right: 20px;
  background: var(--bg-primary); border: 1px solid var(--separator-opaque);
  border-radius: var(--r-md); box-shadow: var(--shadow-xl);
  width: 420px; max-height: calc(100vh - 120px); z-index: 300; font-size: 13px;
}
.drawing-help-panel.visible { display: block; }
.help-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--separator);
  font-weight: 600; font-size: 14px; color: var(--text-primary);
  background: var(--bg-secondary);
  border-radius: var(--r-md) var(--r-md) 0 0;
}
.help-panel-close { border: none; background: transparent; font-size: 20px; color: var(--text-tertiary); cursor: pointer; padding: 0 0 0 8px; line-height: 1; }
.help-panel-close:hover { color: var(--text-primary); }
.help-panel-content { padding: 16px; max-height: calc(100vh - 180px); overflow-y: auto; }
.help-panel-content::-webkit-scrollbar { width: 5px; }
.help-panel-content::-webkit-scrollbar-thumb { background: var(--separator-opaque); border-radius: 3px; }
.help-section { margin-bottom: 16px; }
.help-section:last-child { margin-bottom: 0; }
.help-title {
  font-weight: 600; color: var(--accent); margin-bottom: 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  padding-bottom: 4px; border-bottom: 1px solid var(--separator);
}
.help-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--text-primary); }
.help-row kbd,
.help-keys-table kbd {
  display: inline-block; min-width: 22px; padding: 2px 6px;
  background: var(--bg-secondary); border: 1px solid var(--separator-opaque);
  border-radius: 4px; font-family: inherit; font-size: 11px;
  font-weight: 500; text-align: center; color: var(--text-secondary);
  white-space: nowrap;
}
.help-row b { font-weight: 600; color: var(--text-primary); }
.help-item { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--bg-secondary); }
.help-item:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.help-item-header { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 13px; }
.help-item-header b { color: var(--text-primary); }
.help-item-header kbd { margin-left: auto; }
.help-item-desc { font-size: 12px; color: var(--text-tertiary); line-height: 1.5; padding-left: 24px; }
.help-item-desc kbd { font-size: 10px; padding: 1px 4px; vertical-align: 1px; }
.help-icon { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; font-size: 13px; color: var(--text-tertiary); }
/* Keys table */
.help-keys-table { width: 100%; border-collapse: collapse; }
.help-keys-table td { padding: 3px 0; font-size: 12px; color: var(--text-primary); vertical-align: middle; }
.help-keys-table td:first-child { width: 140px; padding-right: 10px; white-space: nowrap; }
.help-keys-table td:last-child { color: var(--text-tertiary); }
.help-keys-sep td { height: 6px; }
/* Tips list */
.help-tips { margin: 0; padding: 0 0 0 18px; }
.help-tips li { font-size: 12px; color: var(--text-tertiary); line-height: 1.5; margin-bottom: 4px; }
.help-tips li:last-child { margin-bottom: 0; }
.help-tips b { color: var(--text-primary); font-weight: 600; }


/* ── Accordion (legacy) ─────────────────────────────────────── */
details.acc { border: 1px solid var(--separator); border-radius: var(--r-md); background: var(--bg-primary); overflow: hidden; }
details.acc + details.acc { margin-top: 8px; }
details.acc > summary { padding: 10px 12px; cursor: pointer; list-style: none; user-select: none; position: relative; font-weight: 600; color: var(--text-primary); }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc[open] > summary { border-bottom: 1px dashed var(--separator); }
details.acc > summary::after { content: "\25BE"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); opacity: .6; }
details.acc[open] > summary::after { content: "\25B4"; }
details.acc .acc-body { padding: 10px 12px; }
details.acc .acc-body > * + * { margin-top: 8px; }


/* ── Animations ─────────────────────────────────────────────── */
@keyframes flashSec {
  0%   { outline: 2px solid rgba(244,163,0,1); outline-offset: 2px; background: var(--accent-bg); }
  60%  { outline-color: rgba(244,163,0,.35); background: transparent; }
  100% { outline-color: transparent; outline-offset: 0; background: inherit; }
}
.flash-section { animation: flashSec .9s ease-out 1; }
@keyframes flashSection {
  0%   { box-shadow: 0 0 0 0 rgba(255, 200, 0, .0); }
  30%  { box-shadow: 0 0 0 3px rgba(255, 200, 0, .35); }
  100% { box-shadow: 0 0 0 0 rgba(255, 200, 0, .0); }
}
@keyframes snap-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}


/* ── Tour Guide ─────────────────────────────────────────────── */
.t-overlay { position: fixed; inset: 0; z-index: 600; display: none; pointer-events: none; }
.t-overlay.is-on { display: block; pointer-events: auto; }
.t-mask { position: absolute; background: var(--t-backdrop); transition: background .18s ease; }
.t-ring {
  position: absolute; pointer-events: none;
  border: 2.5px solid var(--accent);
  border-radius: var(--t-radius);
  box-shadow: 0 0 0 4px rgba(245,158,11,.18), 0 0 24px rgba(245,158,11,.12);
  animation: tRingBreath 2s ease-in-out infinite;
  transition: left .22s cubic-bezier(.4,0,.2,1), top .22s cubic-bezier(.4,0,.2,1),
              width .22s cubic-bezier(.4,0,.2,1), height .22s cubic-bezier(.4,0,.2,1),
              border-radius .22s cubic-bezier(.4,0,.2,1);
}
@keyframes tRingBreath {
  0%, 100% { box-shadow: 0 0 0 4px rgba(245,158,11,.18), 0 0 24px rgba(245,158,11,.12); }
  50%      { box-shadow: 0 0 0 6px rgba(245,158,11,.25), 0 0 32px rgba(245,158,11,.18); }
}
.t-ring--step { animation: tRingFlash .4s ease-out 1; }
@keyframes tRingFlash {
  0%   { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(245,158,11,.35), 0 0 40px rgba(245,158,11,.25); }
  100% { transform: none; box-shadow: 0 0 0 4px rgba(245,158,11,.18), 0 0 24px rgba(245,158,11,.12); }
}
.t-pop { position: absolute; min-width: 280px; max-width: 460px; background: var(--t-pop-bg); border: 1px solid var(--t-pop-border); border-radius: var(--t-radius); box-shadow: var(--t-pop-shadow); color: var(--t-text); padding: var(--t-pad); animation: tPopFade .18s ease-out; }
@keyframes tPopFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.t-pop--pop { animation: tPopPop .18s ease-out; }
@keyframes tPopPop { from { transform: scale(.985); } to { transform: scale(1); } }
.t-pop__arrow { position: absolute; width: 12px; height: 12px; background: var(--t-pop-bg); border: 1px solid var(--t-pop-border); transform: rotate(45deg); }
.t-pop[data-place="right"] .t-pop__arrow { left: -6px; border-right: none; border-bottom: none; }
.t-pop[data-place="left"] .t-pop__arrow { right: -6px; border-left: none; border-top: none; }
.t-pop[data-place="bottom"] .t-pop__arrow { top: -6px; border-left: none; border-bottom: none; }
.t-pop[data-place="top"] .t-pop__arrow { bottom: -6px; border-right: none; border-top: none; }
.t-pop__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.t-pop__title { font-weight: 800; color: var(--t-title); font-size: 14px; letter-spacing: .2px; }
.t-pop__progress { font-size: 12px; color: var(--t-muted); }
.t-pop__dots { display: flex; gap: 4px; align-items: center; }
.t-pop__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--separator-opaque); transition: all var(--dur-fast, 150ms); }
.t-pop__dot.is-active { width: 18px; border-radius: 3px; background: var(--accent); }
.t-pop__dot.is-done { background: var(--accent); opacity: .45; }
.t-pop__body { font-size: 13px; line-height: 1.55; }
.t-pop__body b { color: var(--t-title); }
.t-pop__nav { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.t-row { display: flex; gap: 8px; align-items: center; }
.t-btn { cursor: pointer; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--separator-opaque); background: var(--bg-primary); font-weight: 700; font-size: 12px; transition: transform .06s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease; box-shadow: 0 1px 0 rgba(2,6,23,.04); font-family: inherit; }
.t-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.t-btn:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.t-btn.primary { background: var(--t-accent); border-color: var(--t-accent); color: #fff; }
.t-btn.primary:hover { background: var(--t-accent-hover); border-color: var(--t-accent-hover); }
.t-btn.ghost:hover { background: var(--bg-secondary); }
.t-pop__nav > .t-btn.ghost[data-act="close"] {
  padding: 4px 8px; font-size: 16px; line-height: 1; border: none; box-shadow: none;
  color: var(--t-muted); opacity: .7;
}
.t-pop__nav > .t-btn.ghost[data-act="close"]:hover { opacity: 1; background: var(--bg-secondary); transform: none; box-shadow: none; }
