/* ============ Ark Image Editor — upload a picture, get an editable design ============ */

:root {
    --accent: #4f46e5;
    --accent-soft: #eef2ff;
    --bg: #f4f6fa;
    --chrome: #ffffff;
    --border: #dde3ec;
    --text: #1f2937;
    --muted: #6b7280;
    --danger: #dc2626;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
    --radius: 8px;
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}

#ie-app {
    display: grid;
    grid-template-rows: 48px 1fr 26px;
    height: 100vh;
}

/* ---------- Top bar ---------- */

#ie-topbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    background: var(--chrome);
    border-bottom: 1px solid var(--border);
    z-index: 30;
    overflow-x: auto;
    scrollbar-width: none;
}
#ie-topbar::-webkit-scrollbar { display: none; }

.ie-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    color: var(--accent);
    padding-right: 12px;
    white-space: nowrap;
}
.ie-brand-mark { width: 22px; height: 22px; stroke: var(--accent); stroke-width: 1.8; fill: var(--accent-soft); }
.ie-brand-logo { width: auto; height: 30px; max-width: 150px; object-fit: contain; flex: none; }

.ie-group { display: flex; align-items: center; gap: 2px; }
.ie-sep { width: 1px; height: 24px; background: var(--border); margin: 0 6px; flex: none; }
.ie-spacer { flex: 1; }

.ie-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 32px;
    height: 32px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.ie-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ie-btn:hover { background: var(--accent-soft); color: var(--accent); }
.ie-btn:disabled { opacity: .4; cursor: default; }
.ie-btn:disabled:hover { background: transparent; color: var(--text); }
.ie-btn-label { padding: 0 10px; }
.ie-btn.active, .ie-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.ie-btn.ie-danger:hover { background: #fef2f2; color: var(--danger); }
.ie-zoom-label { font-size: 12px; font-weight: 600; min-width: 46px; }
.ie-primary-btn { background: var(--accent); color: #fff; }
.ie-primary-btn:hover { background: #4338ca; color: #fff; }
.ie-primary-btn:disabled { background: transparent; color: var(--text); }

.ie-tool-quick span { font-size: 12.5px; font-weight: 600; }

.ie-nav-link {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    padding: 6px 8px;
    border-radius: 6px;
}
.ie-nav-link:hover { color: var(--accent); background: var(--accent-soft); }

/* Export dropdown */
.ie-menu-wrap { position: relative; }
.ie-menu {
    position: absolute;
    top: 38px;
    right: 0;
    min-width: 220px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 4px;
    z-index: 40;
}
.ie-menu button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding: 7px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}
.ie-menu button small { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.ie-menu button:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- Main split ---------- */

#ie-main {
    --ie-tools-w: 48px;
    --ie-drawer-w: 0px;
    --ie-panel-w: 300px;
    display: grid;
    grid-template-columns: var(--ie-tools-w) var(--ie-drawer-w) 1fr var(--ie-panel-w);
    min-height: 0;
}
#ie-tools { grid-column: 1; }
#ie-drawer { grid-column: 2; }
#ie-stage { grid-column: 3; }
#ie-panel { grid-column: 4; }

body:not(.ie-loaded) #ie-main { --ie-tools-w: 0px; --ie-panel-w: 0px; }
body:not(.ie-loaded) #ie-panel { display: none; }
body.ie-drawer-open #ie-main { --ie-drawer-w: 236px; }

/* ---------- Tool palette ---------- */

#ie-tools {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 0;
    background: var(--chrome);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    scrollbar-width: none;
}
#ie-tools::-webkit-scrollbar { display: none; }
body:not(.ie-loaded) #ie-tools { display: none; }

.ie-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: none;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}
.ie-tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ie-tool:hover { background: var(--accent-soft); color: var(--accent); }
.ie-tool.active, .ie-tool[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.ie-tool-sep { width: 22px; height: 1px; background: var(--border); margin: 5px 0; flex: none; }

/* ---------- Drawer (icon library / custom SVG) ---------- */

#ie-drawer { display: flex; flex-direction: column; min-height: 0; background: var(--chrome); border-right: 1px solid var(--border); }
.ie-drawer-pane { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.ie-drawer-head { padding: 8px; border-bottom: 1px solid var(--border); }
#ie-icon-search {
    width: 100%; padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px;
    font: inherit; font-size: 13px; color: var(--text); background: #fff;
}
#ie-icon-search:focus { border-color: var(--accent); outline: none; }
#ie-icon-list { flex: 1; overflow-y: auto; padding: 4px 6px 10px; }
.ie-icon-group > h4 { margin: 10px 0 4px; padding: 0 4px; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ie-icon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.ie-icon-item {
    display: flex; align-items: center; justify-content: center; height: 38px;
    border: 1px solid transparent; border-radius: 6px; background: transparent;
    color: var(--text); cursor: grab;
}
.ie-icon-item svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ie-icon-item:hover { background: var(--accent-soft); border-color: var(--border); color: var(--accent); }
.ie-icon-item:active { cursor: grabbing; }
.ie-drawer-note { padding: 0 8px 8px; margin: 0; }
#ie-card-list { flex: 1; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.ie-card-item {
    display: flex; align-items: center; gap: 10px; padding: 8px; text-align: left;
    border: 1px solid var(--border); border-radius: 8px; background: #fff;
    color: var(--text); cursor: grab;
}
.ie-card-item-icon { width: 20px; height: 20px; flex: none; }
.ie-card-item-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ie-card-item-text strong { font-size: 12.5px; font-weight: 700; }
.ie-card-item-text small { font-size: 11px; color: var(--muted); }
.ie-card-item:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ie-card-item:hover small { color: var(--accent); }
.ie-card-item:active { cursor: grabbing; }
#ie-customsvg-input {
    margin: 8px; width: calc(100% - 16px); padding: 8px; border: 1px solid var(--border); border-radius: 6px;
    font: inherit; font-size: 12.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--text); background: #fff; resize: vertical;
}
.ie-drawer-btn { margin: 0 8px 8px; align-self: flex-start; }

/* ---------- Stage ---------- */

#ie-stage {
    position: relative;
    overflow: auto;
    padding: 32px;
    background-image: radial-gradient(circle, #d6dde9 1px, transparent 1px);
    background-size: 20px 20px;
    user-select: none;
    -webkit-user-select: none;
}
#ie-stage.ie-dragover { outline: 2px dashed var(--accent); outline-offset: -6px; }
#ie-content { position: relative; display: inline-block; }
#ie-canvas svg { display: block; background: #ffffff; border-radius: 4px; box-shadow: var(--shadow); }
body:not(.ie-loaded) #ie-content { display: none; }

body.ie-crosshair #ie-stage, body.ie-crosshair #ie-canvas svg { cursor: crosshair; }

/* Selection overlay lives *inside* the same <svg> as the content (see
   image-editor.js) so it tracks pan/zoom for free; these rules only set the
   parts CSS does better than inline attributes. */
.ie-selbox { fill: none; stroke: var(--accent); pointer-events: none; }
.ie-marquee { fill: rgba(79, 70, 229, .08); stroke: var(--accent); stroke-dasharray: 4 3; pointer-events: none; }
/* Group an area selection is restricted to, and the band's would-be catch while dragging */
.ie-scopebox { fill: rgba(14, 165, 233, .05); stroke: #0ea5e9; stroke-dasharray: 6 4; pointer-events: none; }
.ie-marquee-hit { fill: none; stroke: var(--accent); opacity: .55; pointer-events: none; }
.ie-handle { fill: #ffffff; stroke: var(--accent); }
.ie-handle[data-dir="nw"], .ie-handle[data-dir="se"] { cursor: nwse-resize; }
.ie-handle[data-dir="ne"], .ie-handle[data-dir="sw"] { cursor: nesw-resize; }
.ie-handle[data-dir="n"], .ie-handle[data-dir="s"] { cursor: ns-resize; }
.ie-handle[data-dir="e"], .ie-handle[data-dir="w"] { cursor: ew-resize; }
.ie-rotate-handle { fill: #ffffff; stroke: var(--accent); cursor: grab; }
.ie-rotate-handle:active { cursor: grabbing; }
.ie-rotate-line { stroke: var(--accent); }

/* Drop zone / empty state */
#ie-dropzone {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 6px; color: var(--muted); cursor: pointer;
}
body.ie-loaded #ie-dropzone { display: none; }
.ie-drop-icon { width: 56px; height: 56px; fill: none; stroke: #b6c1d4; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 8px; }
.ie-drop-title { margin: 0; font-size: 17px; font-weight: 600; color: var(--text); }
.ie-drop-sub { margin: 0; font-size: 13px; }

.ie-primary {
    margin-top: 6px; padding: 9px 18px; border: none; border-radius: var(--radius);
    background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; box-shadow: var(--shadow);
}
.ie-primary:hover { background: #4338ca; }

.ie-blank-divider {
    display: flex; align-items: center; gap: 10px; width: 100%; max-width: 360px; margin: 18px 0 4px; color: var(--muted); font-size: 12px;
}
.ie-blank-divider::before, .ie-blank-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
#ie-blank-start { display: flex; flex-direction: column; align-items: center; gap: 10px; cursor: default; }
.ie-blank-presets { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 360px; }
.ie-blank-presets button {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff;
    font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text); cursor: pointer; text-align: center;
    box-shadow: none;
}
.ie-blank-presets button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.ie-blank-presets button small { display: block; margin-top: 2px; font-size: 11px; font-weight: 400; color: var(--muted); }
.ie-blank-presets button:hover small { color: var(--accent); }
.ie-blank-custom { display: flex; align-items: center; gap: 6px; }
.ie-blank-custom label { font-size: 12.5px; color: var(--muted); }
.ie-blank-custom input[type="number"] {
    width: 68px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
    font: inherit; font-size: 13px; color: var(--text); background: #fff; text-align: center;
}
.ie-blank-custom input[type="number"]:focus { border-color: var(--accent); outline: none; }
.ie-blank-custom .ie-primary { margin-top: 0; padding: 8px 14px; }

/* Busy overlay */
#ie-busy {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(244, 246, 250, .82); z-index: 25;
}
.ie-busy-card { width: 320px; padding: 18px 20px; background: #fff; border-radius: 10px; box-shadow: var(--shadow); text-align: center; }
.ie-bar { height: 6px; border-radius: 4px; background: var(--border); overflow: hidden; margin-bottom: 10px; }
.ie-bar-fill { height: 100%; width: 8%; background: var(--accent); border-radius: 4px; transition: width .25s ease; }
#ie-busy p { margin: 0; font-size: 13px; color: var(--muted); }

/* ---------- Right panel: layers + inspector ---------- */

#ie-panel {
    background: var(--chrome);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#ie-layers-sec {
    flex: 0 1 38%;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border);
    padding: 12px 8px 8px;
    min-height: 0;
}
#ie-inspector-sec {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px 20px;
    min-height: 0;
}

.ie-panel-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 6px 6px; }
.ie-panel-head h3 { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

#ie-layers-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.ie-layer-row {
    display: flex; align-items: center; gap: 5px; padding: 5px 6px;
    border-radius: 6px; cursor: pointer; font-size: 12.5px; color: var(--text);
    border: 1px solid transparent;
}
.ie-layer-row:hover { background: var(--bg); }
.ie-layer-row.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ie-layer-row.ie-drag-over { border-top: 2px solid var(--accent); }
.ie-layer-row.ie-dim { opacity: .45; }
.ie-layer-indent { flex: none; }
.ie-layer-icon { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; opacity: .8; }
.ie-layer-name {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    background: transparent; border: none; font: inherit; color: inherit; padding: 2px 0;
}
.ie-layer-name:focus { outline: 1px solid var(--accent); border-radius: 3px; }
.ie-layer-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
    flex: none; border: none; background: transparent; color: var(--muted); border-radius: 4px; cursor: pointer;
}
.ie-layer-btn:hover { background: #e5e9f0; color: var(--text); }
.ie-layer-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.ie-layers-empty { padding: 10px 6px; }
#ie-layers-list:not(:empty) + .ie-layers-empty { display: none; }

/* ---------- Inspector controls (shared look with the SVG editor) ---------- */

#ie-hint { margin: 4px 2px 8px; font-size: 12.5px; line-height: 1.7; color: var(--muted); }

.ie-sec { margin-bottom: 18px; }
.ie-sec h3 { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.ie-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ie-row > label:first-child { width: 46px; flex: none; font-size: 12.5px; color: var(--muted); }

.ie-row input[type="color"] { width: 34px; height: 26px; padding: 1px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
.ie-row input[type="color"]:disabled { opacity: .35; cursor: default; }

.ie-row input[type="number"], .ie-row input[type="text"], .ie-row select, #ie-text-content {
    flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
    font: inherit; font-size: 13px; color: var(--text); background: #fff;
}
.ie-row input:focus, .ie-row select:focus, #ie-text-content:focus { border-color: var(--accent); outline: none; }
.ie-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.ie-val { font-size: 12px; color: var(--muted); min-width: 32px; text-align: right; }

.ie-check { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.ie-check input { accent-color: var(--accent); }

.ie-tag {
    display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft);
    color: var(--accent); font-size: 12px; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
#ie-el-name {
    flex: 1; min-width: 0; padding: 4px 7px; border: 1px solid transparent; border-radius: 6px;
    font: inherit; font-size: 13px; font-weight: 600; color: var(--text); background: transparent;
}
#ie-el-name:hover, #ie-el-name:focus { border-color: var(--border); background: #fff; outline: none; }

.ie-note { margin: 6px 0 0; font-size: 11.5px; line-height: 1.6; color: var(--muted); }

#ie-text-content { display: block; width: 100%; margin-bottom: 8px; line-height: 1.4; resize: vertical; }

.ie-toggles { display: flex; gap: 4px; flex: 1; min-width: 0; }
.ie-toggles button {
    flex: 1; min-width: 0; padding: 5px 0; border: 1px solid var(--border); border-radius: 6px;
    background: #fff; font: inherit; font-size: 12.5px; color: var(--text); cursor: pointer;
}
.ie-toggles button:hover { border-color: var(--accent); color: var(--accent); }
.ie-toggles button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.ie-actions { flex-wrap: wrap; }
.ie-actions .ie-btn { border: 1px solid var(--border); flex: 1; }

/* ---------- Status bar ---------- */

#ie-status {
    display: flex; align-items: center; gap: 10px; padding: 0 12px; font-size: 12px; color: var(--muted);
    background: var(--chrome); border-top: 1px solid var(--border); white-space: nowrap; overflow: hidden;
}

/* ---------- Inline text editing ----------
   A textarea laid over the text element inside #ie-content, so it scales and
   rotates with the zoom; position, font and colour are set inline from the element. */
.ie-inline-text {
    position: absolute; z-index: 5; margin: 0; border: none; border-radius: 2px;
    outline: 1px dashed var(--accent); outline-offset: 2px;
    background: transparent; resize: none; overflow: hidden; white-space: pre; box-sizing: border-box;
    caret-color: var(--accent); user-select: text; -webkit-user-select: text;
}
.ie-inline-text:focus { outline-color: var(--accent); }
.ie-text-inline-note { margin: -2px 0 10px; }

/* ---------- Extract tool ---------- */
/* The band being dragged, and its label; green so it reads as "analyse", not "select" */
.ie-extract-band { fill: rgba(16, 185, 129, .10); stroke: #059669; stroke-dasharray: 6 4; pointer-events: none; }
.ie-extract-label { fill: #059669; font-family: var(--font); font-weight: 700; pointer-events: none; }

/* Import-mode picker on the drop zone */
#ie-import-mode { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 14px; cursor: default; }
.ie-import-mode-label { font-size: 12px; color: var(--muted); }
.ie-import-mode-options { display: flex; gap: 8px; max-width: 440px; }
.ie-import-mode-options button {
    flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff;
    font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text); cursor: pointer; text-align: left;
}
.ie-import-mode-options button small { display: block; margin-top: 2px; font-size: 11px; font-weight: 400; line-height: 1.4; color: var(--muted); }
.ie-import-mode-options button:hover { border-color: var(--accent); color: var(--accent); }
.ie-import-mode-options button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.ie-import-mode-options button.active small { color: var(--accent); }
