/* Autofill Studio — design tokens
   Graphite surfaces, one amber "on-air" accent, mono micro-labels. */
* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #141519;
  --panel: #1b1d22;
  --panel-2: #22252b;
  --panel-3: #2a2d34;
  --border: #2e3138;
  --hairline: #26292f;
  --text: #e8e9ed;
  --muted: #8b909c;
  --faint: #5d626e;
  --accent: #e8a33d;
  --accent-hover: #f2b458;
  --accent-ink: #1a1408;
  --danger: #e5584f;
  --ok: #6fbf73;
  --radius: 6px;
  --radius-lg: 10px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 8px 32px rgba(0, 0, 0, .45);
  --t: 120ms ease;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.5 var(--font-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
::selection { background: rgba(232, 163, 61, .35); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- primitives ---- */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 14px; cursor: pointer;
  transition: border-color var(--t), background var(--t);
}
.btn:hover { border-color: var(--faint); background: var(--panel-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 4px 8px; font-size: 13px; line-height: 1; }
.btn:disabled { opacity: .45; cursor: default; }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 9px;
  transition: border-color var(--t);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="number"] { font-family: var(--font-mono); font-size: 12px; }
input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }
input[type="color"] { padding: 2px; height: 28px; width: 36px; cursor: pointer; }
code, .mono { font-family: var(--font-mono); font-size: 12px; }

/* mono micro-label: the panel vernacular */
.microlabel {
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase; color: var(--faint);
}
.error { color: var(--danger); min-height: 1.2em; font-size: 12px; }
.muted { color: var(--muted); }

/* =========================== auth screen =========================== */
.auth { position: fixed; inset: 0; display: flex; }
.auth-brand {
  flex: 1.1; display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px; border-right: 1px solid var(--hairline);
  background:
    radial-gradient(1200px 600px at -10% 110%, rgba(232, 163, 61, .07), transparent 60%),
    var(--panel);
}
.wordmark { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: .02em; }
.wordmark .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px rgba(232,163,61,.8); }
.auth-brand h1 { font-size: 34px; line-height: 1.2; font-weight: 700; max-width: 420px; letter-spacing: -.015em; }
.auth-brand h1 em { color: var(--accent); font-style: normal; }
.auth-brand .sub { color: var(--muted); max-width: 400px; margin-top: 14px; font-size: 14px; }
.auth-brand .meta { display: flex; gap: 28px; }
.auth-brand .meta div span { display: block; }
.auth-form {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px;
}
.auth-card { width: 340px; display: flex; flex-direction: column; gap: 12px; }
.auth-card .tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.auth-card .tabs button {
  background: none; border: none; padding: 10px 2px; margin-right: 22px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-size: 14px;
}
.auth-card .tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.auth-card input { padding: 9px 11px; }
.auth-card .btn { padding: 10px; margin-top: 6px; }

/* =========================== app shell =========================== */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  height: 48px; flex: none; display: flex; align-items: center; gap: 14px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--hairline);
}
.topbar .tpl-name {
  background: transparent; border-color: transparent; font-weight: 600; font-size: 14px;
  width: 240px; padding: 5px 8px;
}
.topbar .tpl-name:hover { border-color: var(--border); }
.topbar .tpl-name:focus { border-color: var(--accent); background: var(--bg); }
.dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.dirty-dot.clean { background: transparent; border: 1px solid var(--faint); }
.topbar .grow { flex: 1; }
.topbar .divider { width: 1px; height: 22px; background: var(--border); }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }

.shell { flex: 1; display: flex; min-height: 0; }

/* ---- left: templates + layers ---- */
.left {
  width: 248px; flex: none; background: var(--panel); border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 6px;
}
.panel-head .actions { display: flex; gap: 4px; }
.tpl-list { list-style: none; padding: 2px 8px 10px; overflow-y: auto; flex: none; max-height: 34%; }
.tpl-list li {
  padding: 6px 9px; border-radius: var(--radius); cursor: pointer; color: var(--muted);
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  transition: background var(--t), color var(--t);
}
.tpl-list li:hover { background: var(--panel-2); }
.tpl-list li.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.tpl-list li .dim { font-family: var(--font-mono); font-size: 10px; color: var(--faint); flex: none; }
.tpl-list li.inactive { opacity: .5; }

.layers-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--hairline); }
.layer-list { list-style: none; padding: 2px 8px; overflow-y: auto; flex: 1; }
.layer-list li {
  display: flex; align-items: center; gap: 8px; padding: 6px 9px;
  border-radius: var(--radius); cursor: pointer; color: var(--muted);
  transition: background var(--t), color var(--t);
}
.layer-list li:hover { background: var(--panel-2); }
.layer-list li.selected { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.layer-list .glyph {
  font-family: var(--font-mono); font-size: 10px; width: 20px; height: 20px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 4px; color: var(--faint);
}
.layer-list li.selected .glyph { border-color: var(--accent); color: var(--accent); }
.layer-list .lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-empty { padding: 14px 12px; color: var(--faint); font-size: 12px; }

/* ---- center: canvas ---- */
.center { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.canvas-wrap {
  flex: 1; overflow: auto; position: relative;
  display: grid; place-items: center; padding: 32px;
  background:
    radial-gradient(800px 400px at 50% -10%, rgba(255,255,255,.02), transparent),
    var(--bg);
}
.canvas {
  position: relative; flex: none;
  background: repeating-conic-gradient(#3a3d44 0 25%, #44474f 0 50%) 0 0/20px 20px;
  box-shadow: var(--shadow); outline: 1px solid var(--border);
}
.layer-box { position: absolute; border: 1px dashed rgba(255,255,255,.35); cursor: move; overflow: hidden; user-select: none; }
.layer-box:hover { border-color: rgba(255,255,255,.65); }
.layer-box.selected { border: 1.5px solid var(--accent); z-index: 50; }
.layer-box .txt { width: 100%; height: 100%; display: flex; padding: 2px; word-break: break-word; }
.layer-box .anchor-flag {
  position: absolute; left: 2px; top: 2px; font-size: 10px; line-height: 1;
  color: var(--accent); background: rgba(20, 21, 25, .75);
  padding: 2px 4px; border-radius: 3px; pointer-events: none;
}
.layer-box .handle {
  position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px;
  background: var(--accent); cursor: nwse-resize; border-radius: 3px 0 0 0;
}
.layer-box img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }

.statusbar {
  height: 30px; flex: none; display: flex; align-items: center; gap: 14px;
  padding: 0 14px; background: var(--panel); border-top: 1px solid var(--hairline);
  font-family: var(--font-mono); font-size: 11px; color: var(--faint);
}
.statusbar .msg { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-ui); font-size: 12px; color: var(--muted); }
.statusbar .msg.err { color: var(--danger); }
.statusbar .zoom { display: flex; align-items: center; gap: 4px; }
.statusbar .zoom button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.statusbar .zoom button:hover { background: var(--panel-2); color: var(--text); }

/* ---- right: properties ---- */
.right {
  width: 292px; flex: none; background: var(--panel); border-left: 1px solid var(--hairline);
  overflow-y: auto; padding-bottom: 30px;
}
.prop-section { padding: 10px 14px 4px; }
.prop-section + .prop-section { border-top: 1px solid var(--hairline); }
.prop-section .microlabel { display: block; margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.row > label { flex: 0 0 96px; color: var(--muted); font-size: 12px; }
.row input, .row select { flex: 1; min-width: 0; }
.row input[type="checkbox"] { flex: none; }
.row .pair { display: flex; gap: 6px; flex: 1; min-width: 0; }
.row .pair input { width: 50%; min-width: 0; }
.seg { display: flex; flex: 1; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg button { flex: 1; background: transparent; border: none; padding: 5px 0; cursor: pointer; color: var(--muted); font-size: 12px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--panel-3); color: var(--accent); }
.layer-actions { display: flex; gap: 6px; padding: 10px 14px; }
.empty-props { padding: 18px 14px; color: var(--faint); font-size: 12px; }

.empty-state { flex: 1; display: grid; place-items: center; color: var(--faint); }
.empty-state .inner { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* ---- preview overlay ---- */
.preview-overlay {
  position: absolute; inset: 0; background: rgba(12, 13, 16, .93); backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; z-index: 100; padding: 30px;
}
.preview-overlay img { max-width: min(88%, 720px); max-height: 72vh; box-shadow: var(--shadow); outline: 1px solid var(--border); }
.preview-bar { display: flex; gap: 8px; align-items: center; width: min(88%, 720px); }
.preview-bar input { flex: 1; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  width: 600px; max-height: 82vh; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--hairline); }
.modal-head h3 { font-size: 14px; font-weight: 600; }
#modal-body { padding: 18px; overflow-y: auto; }
#modal-body table { width: 100%; border-collapse: collapse; font-size: 12px; }
#modal-body th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); font-weight: 500; }
#modal-body td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--hairline); }
#modal-body .form-row { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }
.asset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.asset-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; align-items: center;
  transition: border-color var(--t);
}
.asset-card:hover { border-color: var(--accent); }
.asset-card .tname { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb {
  width: 100%; aspect-ratio: 1; border-radius: 4px; display: block;
  background: repeating-conic-gradient(#33363d 0 25%, #3d4149 0 50%) 0 0/12px 12px;
  background-size: cover; background-position: center;
}
.thumb.sm { width: 30px; height: 30px; aspect-ratio: auto; display: inline-flex; align-items: center; justify-content: center; }
.thumb.font-thumb { background: var(--panel-3); color: var(--muted); font-size: 13px; font-weight: 600; }
.key-reveal {
  background: var(--bg); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 10px 12px; font-family: var(--font-mono); font-size: 12px; word-break: break-all; margin: 12px 0 4px;
}
