/* SlimSAM Image Editor — styles scoped under .slimsam-editor so nothing leaks
   into the site layout (loaded inside the Astro Base layout).
   Colors/fonts come from the site design tokens in src/styles/global.css. */

.slimsam-editor {
  /* Break out of the max-w-3xl prose column for an editor-width canvas */
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  width: min(1120px, 94vw);

  --se-radius: 12px;
  --se-radius-sm: 8px;
  --se-bg: #ffffff;
  --se-bg-sunk: color-mix(in srgb, var(--color-paper) 60%, #ffffff);
  --se-line: var(--color-line, #e2e5e0);
  --se-ink: var(--color-ink, #2b2b2b);
  --se-muted: var(--color-ink-muted, #6c6c66);
  --se-accent: var(--color-orange, #e8845a);
  --se-accent-ink: #ffffff;
  --se-blue: var(--color-blue, #4d80e6);
  --se-sage: var(--color-sage, #949b80);
  --se-shadow: 0 2px 14px rgba(20, 20, 19, 0.07);

  color: var(--se-ink);
  font-family: var(--font-sans);
  line-height: 1.5;
}

.slimsam-editor *,
.slimsam-editor *::before,
.slimsam-editor *::after { box-sizing: border-box; }

/* ---------- Status / model loader ---------- */
.se-status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  border: 1px solid var(--se-line);
  border-radius: var(--se-radius-sm);
  background: var(--se-bg-sunk);
  font-size: 0.82rem;
  color: var(--se-muted);
}
.se-status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--se-sage);
  flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--se-sage) 22%, transparent);
}
.se-status[data-state="loading"] .se-status-dot { background: var(--color-yellow, #e8c85a); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-yellow) 25%, transparent); animation: se-pulse 1.1s ease-in-out infinite; }
.se-status[data-state="ready"] .se-status-dot { background: var(--color-green, #92de86); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-green) 25%, transparent); }
.se-status[data-state="error"] .se-status-dot { background: var(--color-red, #b56666); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-red) 25%, transparent); }
@keyframes se-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.se-status-text { flex: 1; }
.se-status-text code { font-family: var(--font-mono); font-size: 0.78rem; }
.se-progress { width: 120px; height: 5px; border-radius: 999px; background: var(--se-line); overflow: hidden; flex: none; display: none; }
.se-status[data-state="loading"] .se-progress { display: block; }
.se-progress-bar { height: 100%; width: 0%; background: var(--se-accent); transition: width 0.2s ease; }

/* ---------- Dropzone ---------- */
.se-dropzone {
  border: 2px dashed color-mix(in srgb, var(--se-accent) 55%, var(--se-line));
  border-radius: var(--se-radius);
  background: var(--se-bg);
  padding: 3.4rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.se-dropzone:hover, .se-dropzone.se-drag { border-color: var(--se-blue); background: var(--se-bg-sunk); }
.se-drop-icon { color: var(--se-muted); opacity: 0.8; margin-bottom: 0.8rem; }
.se-drop-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; margin: 0 0 0.15rem; }
.se-drop-sub { color: var(--se-muted); font-size: 0.9rem; margin: 0 0 1rem; }
.se-drop-actions { display: flex; gap: 0.7rem; justify-content: center; flex-wrap: wrap; }
.se-drop-note { margin: 1.2rem 0 0; font-size: 0.78rem; color: var(--se-muted); }
.se-drop-note strong { color: var(--se-ink); font-weight: 600; }

/* ---------- Buttons ---------- */
.se-btn {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--se-line);
  border-radius: var(--se-radius-sm);
  background: var(--se-bg);
  color: var(--se-ink);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.se-btn:hover:not(:disabled) { border-color: var(--se-accent); color: var(--se-accent); }
.se-btn:active:not(:disabled) { transform: translateY(1px); }
.se-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.se-btn-primary { background: var(--se-accent); border-color: var(--se-accent); color: var(--se-accent-ink); }
.se-btn-primary:hover:not(:disabled) { background: #d4703f; border-color: #d4703f; color: #fff; }
.se-btn-ghost { background: transparent; border-color: transparent; color: var(--se-muted); padding: 0.5rem 0.6rem; }
.se-btn-ghost:hover:not(:disabled) { background: var(--se-bg-sunk); color: var(--se-ink); border-color: transparent; }
.se-w { width: 100%; }

/* ---------- Workspace ---------- */
.se-workspace[hidden] { display: none; }

.se-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--se-line);
  border-radius: var(--se-radius) var(--se-radius) 0 0;
  background: var(--se-bg-sunk);
  border-bottom: none;
}
.se-tool-group { display: inline-flex; border: 1px solid var(--se-line); border-radius: var(--se-radius-sm); overflow: hidden; background: var(--se-bg); }
.se-tool {
  font-family: var(--font-sans);
  font-size: 0.82rem; font-weight: 600;
  padding: 0.42rem 0.9rem; border: none; background: transparent; color: var(--se-muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.se-tool + .se-tool { border-left: 1px solid var(--se-line); }
.se-tool[data-active="true"] { background: var(--se-accent); color: #fff; }
#se-mode-include[data-active="true"] { background: #22a35a; color: #fff; }
#se-mode-exclude[data-active="true"] { background: #e23b3b; color: #fff; }
.se-hint { font-size: 0.78rem; color: var(--se-muted); }
.se-spacer { flex: 1; }

.se-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 0;
  border: 1px solid var(--se-line);
  border-radius: 0 0 var(--se-radius) var(--se-radius);
  overflow: hidden;
  background: var(--se-bg);
}

/* ---------- Stage / canvas ---------- */
.se-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background:
    linear-gradient(45deg, #eceef0 25%, transparent 25%, transparent 75%, #eceef0 75%),
    linear-gradient(45deg, #eceef0 25%, #f6f7f8 25%, #f6f7f8 75%, #eceef0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  min-height: 320px;
}
.se-canvas-wrap {
  position: relative;
  line-height: 0;
  max-width: 100%;
  box-shadow: var(--se-shadow);
}
.se-canvas-wrap canvas { display: block; max-width: 100%; height: auto; }
#se-base { border-radius: 2px; }
#se-overlay { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
.se-canvas-wrap.se-busy #se-overlay { cursor: wait; }

.se-spinner {
  position: absolute; top: 10px; right: 10px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.6);
  border-top-color: var(--se-accent);
  animation: se-spin 0.7s linear infinite;
  pointer-events: none;
}
.se-spinner[hidden] { display: none; }
@keyframes se-spin { to { transform: rotate(360deg); } }

/* mask candidate picker */
.se-masks { display: flex; align-items: center; gap: 0.55rem; margin-top: 0.9rem; flex-wrap: wrap; justify-content: center; }
.se-masks[hidden] { display: none; }
.se-masks-label { font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--se-muted); }
.se-mask-opts { display: inline-flex; gap: 0.35rem; }
.se-mask-opt {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  padding: 0.3rem 0.55rem; border: 1px solid var(--se-line); border-radius: 999px;
  background: var(--se-bg); color: var(--se-muted); cursor: pointer; line-height: 1;
}
.se-mask-opt small { opacity: 0.7; font-weight: 400; }
.se-mask-opt[data-active="true"] { border-color: var(--se-accent); color: var(--se-accent); background: color-mix(in srgb, var(--se-accent) 10%, transparent); }

/* ---------- Side panel ---------- */
.se-panel {
  border-left: 1px solid var(--se-line);
  background: var(--se-bg);
  padding: 0.4rem 0;
  overflow-y: auto;
  max-height: 640px;
}
.se-section { padding: 1rem 1.1rem; border-bottom: 1px solid var(--se-line); }
.se-section:last-child { border-bottom: none; }
.se-h {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--se-muted);
  margin: 0 0 0.7rem; display: flex; align-items: center; gap: 0.5rem;
}
.se-count {
  font-size: 0.68rem; background: var(--se-bg-sunk); border: 1px solid var(--se-line);
  border-radius: 999px; padding: 0.05rem 0.45rem; color: var(--se-ink);
}
.se-hint2 { font-size: 0.76rem; color: var(--se-muted); margin: -0.3rem 0 0.7rem; line-height: 1.45; }

.se-export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-top: 0.6rem; }
.se-export-grid .se-btn { padding: 0.45rem 0.4rem; font-size: 0.78rem; }

/* layers list */
.se-layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.se-layer {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.4rem 0.5rem; border: 1px solid var(--se-line); border-radius: var(--se-radius-sm);
  background: var(--se-bg-sunk); font-size: 0.82rem;
}
.se-layer-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; border: 1px solid rgba(0,0,0,0.12); }
.se-layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.se-layer-name[contenteditable="true"] { outline: 1px solid var(--se-accent); border-radius: 3px; padding: 0 2px; }
.se-icon-btn {
  border: none; background: transparent; cursor: pointer; color: var(--se-muted);
  padding: 2px; border-radius: 4px; line-height: 0; display: inline-flex;
}
.se-icon-btn:hover { color: var(--se-ink); background: rgba(0,0,0,0.05); }
.se-icon-btn[data-off="true"] { opacity: 0.35; }
.se-empty { font-size: 0.78rem; color: var(--se-muted); font-style: italic; margin: 0; }

/* controls */
.se-select {
  width: 100%; font-family: var(--font-sans); font-size: 0.84rem;
  padding: 0.45rem 0.55rem; border: 1px solid var(--se-line); border-radius: var(--se-radius-sm);
  background: var(--se-bg); color: var(--se-ink); cursor: pointer;
}
.se-bg-controls { margin: 0.7rem 0; display: flex; flex-direction: column; gap: 0.55rem; }
.se-bg-controls label { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; font-size: 0.8rem; color: var(--se-muted); }
.se-bg-controls label[hidden] { display: none; }
.se-bg-controls input[type="range"] { flex: 1; accent-color: var(--se-accent); }
.se-bg-controls input[type="color"] { width: 40px; height: 26px; border: 1px solid var(--se-line); border-radius: 5px; background: none; cursor: pointer; padding: 2px; }

/* toast */
.se-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--se-ink); color: #fff; font-size: 0.85rem; padding: 0.6rem 1rem;
  border-radius: 999px; box-shadow: 0 6px 20px rgba(0,0,0,0.25); opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease; pointer-events: none; z-index: 60;
}
.se-toast.se-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .se-body { grid-template-columns: 1fr; }
  .se-panel { border-left: none; border-top: 1px solid var(--se-line); max-height: none; }
}
