:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e6e8ec;
  --text: #1b1f29;
  --muted: #6b7385;
  --accent: #2357e8;
  --accent-soft: #eaf0ff;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(20, 24, 40, 0.06);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }

/* top bar */
.topbar {
  height: 60px; display: flex; align-items: center; gap: 18px; padding: 0 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; flex-shrink: 0; }
.brand-logo { height: 38px; width: auto; display: block; object-fit: contain; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--text); color: #fff; display: grid; place-items: center; }
.title-block { min-width: 0; padding-left: 14px; border-left: 1px solid var(--line); }
.box-title { font-weight: 650; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }
.box-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.view-tabs { margin: 0 auto; display: flex; background: #f0f1f4; border-radius: 10px; padding: 3px; }
.tab { border: 0; background: transparent; padding: 7px 18px; border-radius: 8px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.tab.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.top-actions { display: flex; gap: 10px; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 13.5px; }
.btn:hover { border-color: #cfd3db; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.dropdown { position: relative; }
.menu { position: absolute; right: 0; top: 46px; width: 270px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 34px rgba(20,24,40,.14); padding: 6px; }
.menu-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px 4px; font-weight: 600; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; font-size: 13.5px; }
.menu button:hover { background: var(--accent-soft); color: var(--accent); }

/* layout */
.workspace { display: flex; height: calc(100% - 60px); }
.rail { width: 78px; background: var(--panel); border-right: 1px solid var(--line); padding: 10px 8px; display: flex; flex-direction: column; gap: 6px; }
.rail-btn { border: 0; background: none; border-radius: 12px; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.rail-btn svg { width: 22px; height: 22px; }
.rail-btn:hover { background: #f4f5f8; }
.rail-btn.active { background: var(--accent-soft); color: var(--accent); }
.side { width: 330px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 18px; }
.side h3 { margin: 0 0 4px; font-size: 15px; }
.side .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; line-height: 1.45; }
.stage { flex: 1; position: relative; min-width: 0;
  background: radial-gradient(ellipse at 50% 38%, #ffffff 0%, #eef0f3 55%, #e2e5ea 100%); }
.viewport { position: absolute; inset: 0; }
.viewer-canvas { width: 100%; height: 100%; display: block; outline: none; cursor: grab; }
.viewer-canvas:active { cursor: grabbing; }

/* model cards */
.group-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 8px; display: flex; justify-content: space-between; }
.group-title span { background: #f0f1f4; border-radius: 10px; padding: 0 8px; font-weight: 600; }
.search { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font-size: 13.5px; }
.search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.preset { display: block; width: 100%; text-align: left; border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.preset:hover:not([disabled]) { border-color: #c9cfdb; box-shadow: var(--shadow); }
.preset.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.preset.pending { opacity: .55; cursor: default; }
.preset-name { font-size: 13px; font-weight: 600; line-height: 1.35; }
.preset-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.preset-brands { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.preset-brands span { font-size: 11px; background: #f0f1f4; border-radius: 6px; padding: 1px 6px; color: #3a4153; }
.model-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.model-card { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 8px; text-align: left; transition: border-color .15s, box-shadow .15s; }
.model-card:hover { border-color: #c9cfdb; box-shadow: var(--shadow); }
.model-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.model-thumb { aspect-ratio: 1; border-radius: 8px; background: linear-gradient(180deg, #f7f8fa, #eceef2); display: grid; place-items: center; overflow: hidden; }
.model-thumb img { width: 100%; height: 100%; object-fit: contain; }
.model-name { font-size: 12.5px; font-weight: 600; margin-top: 7px; line-height: 1.3; }
.model-code { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* form */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: #3a4153; margin-bottom: 6px; }
.dims { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.num { position: relative; }
.num input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 14px 8px 2px 10px; font-size: 14px; font-weight: 600; }
.num input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.num span { position: absolute; left: 10px; top: 4px; font-size: 10.5px; color: var(--muted); font-weight: 600; }
select { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: #fff; font-size: 13.5px; }
.seg { display: flex; background: #f0f1f4; border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.dim-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 4px; }
.dim-table th, .dim-table td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.dim-table th:first-child, .dim-table td:first-child { text-align: left; color: var(--muted); font-weight: 600; }
.dim-table thead th { color: var(--muted); font-weight: 600; font-size: 11.5px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.swatch.active { box-shadow: 0 0 0 2px var(--accent); }
.error { color: #c0362c; font-size: 12px; margin-top: 6px; }

/* layers */
.layer { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.layer.active { border-color: var(--accent); }
.layer-head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.layer-head img { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; background: #f3f4f6; }
.layer-head .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-head button { border: 0; background: none; color: var(--muted); font-size: 16px; }
.layer-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.layer-row input[type=range] { flex: 1; }
.layer-row select { height: 32px; font-size: 12.5px; }
.layer-row input[type=text] { flex: 1; height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; }
.drop { border: 1.5px dashed #c9cfdb; border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }

/* floating bars */
.floatbar { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 14px; padding: 8px 12px; box-shadow: 0 6px 24px rgba(20,24,40,.12); white-space: nowrap; }
.floatbar .icon { width: 32px; height: 32px; border: 0; border-radius: 8px; background: #f3f4f7; display: grid; place-items: center; font-size: 17px; }
.floatbar .icon:hover { background: #e9ebf0; }
.floatbar .sep { width: 1px; height: 22px; background: var(--line); }
.floatbar .lbl { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.floatbar input[type=range] { width: 170px; accent-color: var(--accent); }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 8px; height: 32px; padding: 0 12px; font-size: 12.5px; font-weight: 600; }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.check { font-size: 12.5px; display: flex; align-items: center; gap: 5px; color: #3a4153; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 18px; height: 0; border-top: 2px solid; margin-left: 6px; }
.lg.cut { border-color: #1F2A44; }
.lg.crease { border-color: #E5484D; border-top-style: dashed; }
.lg.bleed { border-color: #2FB463; }

/* dieline */
.dieline-view { overflow: hidden; }
.dieline-canvas { position: absolute; inset: 24px 24px 86px 24px; }
.dieline-canvas svg { width: 100%; height: 100%; }
.dieline-canvas [data-layer] { cursor: move; }
.sel-box { fill: none; stroke: var(--accent); stroke-dasharray: 4 3; pointer-events: none; }

.toast { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); background: #1b1f29; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 30; }

/* Phase 8 controls: undo/redo, brand kits, alignment, imposition, modal */
.btn.icon-btn { width: 38px; padding: 0; justify-content: center; font-size: 17px; }
.btn[disabled] { opacity: .42; cursor: not-allowed; }
.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.tool-grid .btn { padding: 0 6px; font-size: 12px; height: 32px; justify-content: center; }
.align-bar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; width: 100%; }
.align-bar button { height: 28px; border: 1px solid var(--line); background: #f8f9fb; border-radius: 6px; font-size: 11.5px; font-weight: 600; color: #3a4153; padding: 0; }
.align-bar button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.brand-row { display: flex; gap: 6px; align-items: center; }
.brand-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.effect-pill { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: #fef3c7; color: #92400e; }
.imp-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fafbfc; margin-top: 6px; }
.imp-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 12px; margin-bottom: 8px; }
.imp-stats div { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.imp-stats b { display: block; font-size: 13.5px; color: var(--text); margin-top: 2px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.48); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { width: 100%; max-width: 560px; max-height: 86vh; background: #fff; border-radius: 16px; box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15.5px; }
.icon-close { border: 0; background: #f1f5f9; width: 30px; height: 30px; border-radius: 8px; font-size: 14px; }
.modal-body { padding: 16px 18px; overflow-y: auto; font-size: 13px; }
.share-box { display: flex; gap: 6px; margin-top: 6px; }
.share-box input { flex: 1; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; font-size: 12.5px; background: #f8fafc; }
.proj-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 7px; }
.proj-item-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Phase 9: 3D Studio Scenes, Offline AI Image Tools, Packaging Icons & Smart Recommender */
.scene-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.scene-card { display: flex; flex-direction: column; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer; text-align: left; transition: border-color 0.15s, box-shadow 0.15s; }
.scene-card:hover { border-color: #9ca3af; }
.scene-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.scene-swatch { width: 100%; height: 34px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.08); }
.scene-name { font-size: 12px; font-weight: 700; color: var(--text); }
.scene-sub { font-size: 10.5px; color: var(--muted); line-height: 1.25; }

.ai-tool-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.ai-tool-row button { height: 28px; border: 1px solid #c7d2fe; border-radius: 7px; background: #eef2ff; color: #1e3a8a; font-size: 11px; font-weight: 700; cursor: pointer; padding: 0 6px; }
.ai-tool-row button:hover:not(:disabled) { background: #e0e7ff; border-color: #818cf8; }
.ai-tool-row button:disabled { opacity: 0.55; cursor: wait; }

.ai-status-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; font-size: 11.5px; margin-bottom: 12px; }
.ai-badge { display: inline-block; padding: 1px 6px; border-radius: 99px; font-size: 10px; font-weight: 700; background: #dcfce7; color: #166534; }
.ai-badge.algo { background: #e0e7ff; color: #1e40af; }

.rec-box { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.rec-card { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; text-align: left; cursor: pointer; }
.rec-card:hover { border-color: var(--accent); background: #f8faff; }
.rec-title, .rec-card-title { font-size: 12px; font-weight: 700; color: var(--text); }
.rec-meta, .rec-card-meta { font-size: 11px; color: var(--accent); font-weight: 600; }
.rec-reason, .rec-card-reason { font-size: 11px; color: var(--muted); }

.icon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.icon-card { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 4px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; text-align: center; }
.icon-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.icon-card img, .icon-card svg { width: 32px; height: 32px; object-fit: contain; display: block; }
.icon-card span { font-size: 9.5px; font-weight: 600; color: var(--text); line-height: 1.15; }
