/* ============================================================
   Studio HQ - styles
   Earthy palette nods to clay/glaze without going kitschy.
   ============================================================ */
:root {
  --bg:        #f7f3ee;
  --surface:   #ffffff;
  --ink:       #2b2622;
  --muted:     #7a6f66;
  --line:      #e3d9cd;
  --accent:    #8b5e3c;   /* terracotta */
  --accent-2:  #5b7355;   /* sage */
  --warn:      #b9591f;
  --danger:    #a02828;
  --ok:        #3e7a4e;
  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; font-weight: 600; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: .6rem 1.25rem;
}
.topbar .brand { font-weight: 700; color: var(--accent); }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--ink); padding: .25rem .5rem; border-radius: 4px; }
.topbar nav a.active { background: var(--bg); color: var(--accent); }
.user-chip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.user-chip span { font-weight: 500; }

main.wrap { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.25rem; }
main.blueprint-main { padding: 0; max-width: none; margin: 0; }

.layout-2col { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 800px) { .layout-2col { grid-template-columns: 1fr; } }

/* Cards & forms */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card.narrow { max-width: 420px; margin: 4rem auto; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .75rem; }
.auth-page { display: flex; align-items: center; min-height: 100vh; background: var(--bg); }
.flash { padding: .5rem .75rem; border-radius: 6px; margin-bottom: .75rem; }
.flash.error { background: #fbe9e7; color: var(--danger); border: 1px solid #f5cfca; }
.flash.success { background: #e8f1e8; color: var(--ok); border: 1px solid #cee0d0; }

label { display: block; margin-bottom: .75rem; font-size: .9rem; color: var(--muted); }
label > input, label > select, label > textarea {
  display: block; width: 100%; margin-top: .25rem;
  font: inherit; color: var(--ink);
  padding: .55rem .65rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff;
}
label > input:focus, label > select:focus, label > textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-color: var(--accent);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
button, .btn {
  display: inline-block; cursor: pointer;
  font: inherit; font-weight: 500;
  padding: .55rem .9rem; border-radius: 6px;
  background: var(--accent); color: #fff; border: 1px solid transparent;
}
button:hover, .btn:hover { filter: brightness(1.05); text-decoration: none; }
button.ghost, .btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { background: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  display: block; padding: 1rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; color: var(--ink);
  box-shadow: var(--shadow);
}
.stat-card:hover { text-decoration: none; transform: translateY(-1px); transition: .15s; }
.stat-card.warn { border-left: 4px solid var(--warn); }
.stat-num { font-size: 2rem; font-weight: 700; line-height: 1; color: var(--accent); }
.stat-label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }

/* Request list */
.req-list { list-style: none; padding: 0; margin: 0; }
.req-list.big .req-row { padding: .75rem; }
.req-row {
  display: grid;
  grid-template-columns: 80px 1fr auto auto;
  gap: .75rem; align-items: center;
  padding: .5rem 0;
  border-bottom: 1px solid var(--line);
}
.req-row:last-child { border-bottom: none; }
.req-row .req-title { font-weight: 500; color: var(--ink); }
.req-row .req-title:hover { color: var(--accent); text-decoration: none; }
.prio { display: inline-block; text-align: center; padding: .15rem .5rem; border-radius: 999px; font-size: .75rem; text-transform: uppercase; font-weight: 600; }
.prio-low      { background: #eef0ee; color: #5b6657; }
.prio-normal   { background: #e7eef0; color: #3a606a; }
.prio-high     { background: #fbeede; color: #8a5a16; }
.prio-urgent   { background: #fbdcd6; color: var(--danger); }
.status { font-size: .8rem; color: var(--muted); }
.status-open        { color: var(--warn); }
.status-in_progress { color: #3a606a; }
.status-resolved    { color: var(--ok); text-decoration: line-through; }

.req-detail { margin-top: .5rem; padding: .75rem 1rem; background: var(--bg); border-radius: 6px; }
.req-detail h4 { margin: 0 0 .25rem; }
.req-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.req-actions select, .req-actions button { padding: .3rem .6rem; font-size: .85rem; }
.req-comments { margin-top: .75rem; }
.req-comment { padding: .4rem 0; border-top: 1px solid var(--line); }
.req-comment:first-child { border-top: none; }

/* ============================================================
   Blueprint editor
   ============================================================ */
.bp-shell { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 50px); }
@media (max-width: 800px) { .bp-shell { grid-template-columns: 1fr; height: auto; } .bp-palette { max-height: 40vh; overflow: auto; } }
.bp-palette {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 1rem; overflow-y: auto;
}
.palette-heading { margin: .75rem 0 .35rem; font-size: .7rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.palette-heading:first-child { margin-top: 0; }
.palette-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; margin-bottom: .25rem; }
.palette-item {
  cursor: grab; user-select: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: .35rem; text-align: center; font-size: .75rem;
}
.palette-item:hover { border-color: var(--accent); }
.palette-item:active { cursor: grabbing; }
.palette-item .swatch { display: block; height: 28px; border-radius: 3px; margin-bottom: .25rem; }

.bp-canvas-wrap { position: relative; display: flex; flex-direction: column; background: #f1ece3; }
.bp-toolbar {
  display: flex; align-items: center; gap: .5rem;
  padding: .4rem .75rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.bp-toolbar .bp-spacer { flex: 1; }
.bp-toolbar button { padding: .25rem .55rem; font-size: .9rem; }
.bp-viewport { flex: 1; overflow: auto; position: relative; }
.bp-canvas {
  position: relative;
  background: #fdfbf7;
  background-image:
    linear-gradient(to right, #e9e1d2 1px, transparent 1px),
    linear-gradient(to bottom, #e9e1d2 1px, transparent 1px);
  background-size: 20px 20px;
  border: 1px solid var(--line);
  margin: 1rem;
  transform-origin: top left;
}
/* Background image layers - sit behind items, above the grid pattern */
.bp-bg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  object-position: top left;
  pointer-events: none;
  z-index: 0;
  user-select: none;
}
.bp-item { z-index: 1; }
.bp-item.is-note {
  color: #443c12;
  font-style: italic;
  border-radius: 4px;
  box-shadow: 1px 2px 4px rgba(0,0,0,.15);
  font-size: 13px;
}

/* Background-management panel */
#bp-bg-panel { display: flex; flex-direction: column; gap: .75rem; margin-bottom: .25rem; }
.bg-row { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .55rem .65rem; }
.bg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .35rem; }
.bg-head strong { font-size: .85rem; }
.bg-thumb {
  height: 70px; background: #fff; border: 1px solid var(--line);
  border-radius: 4px; margin-bottom: .35rem; overflow: hidden;
}
.bg-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.bg-empty { padding: .65rem; text-align: center; background: #fff; border: 1px dashed var(--line); border-radius: 4px; margin-bottom: .35rem; }
.bg-row label { display: block; margin-bottom: .25rem; }
.bg-row input[type="range"] { width: 100%; }
.bg-row input[type="text"] { width: 100%; padding: .25rem .35rem; font-size: .8rem; border: 1px solid var(--line); border-radius: 4px; }
.bg-admin { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .35rem; }
.bg-admin button { padding: .25rem .55rem; font-size: .8rem; }
.bg-admin button.danger { background: var(--danger); color: #fff; border-color: transparent; }
.bg-admin button.danger:hover { filter: brightness(1.1); }

/* Calibration overlay & banner */
.bp-banner {
  background: #fff8d6;
  border-bottom: 1px solid #e5d68f;
  color: #5a4a18;
  padding: .55rem .85rem;
  display: flex; gap: .75rem; align-items: center; justify-content: space-between;
  font-size: .9rem;
}
.bp-banner.success { background: #e7f1e8; border-color: #b9d4be; color: #2e6a3a; }
.bp-banner button { padding: .2rem .55rem; font-size: .8rem; }
.bp-canvas.bp-calibrating { cursor: crosshair; }
.bp-canvas.bp-calibrating .bp-item { pointer-events: none; }
.bp-cal-mark {
  position: absolute;
  width: 12px; height: 12px;
  margin-left: -6px; margin-top: -6px;
  background: #1f6dba;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #1f6dba;
  z-index: 100;
  pointer-events: none;
}
.bp-cal-line {
  position: absolute;
  height: 2px;
  background: #1f6dba;
  transform-origin: 0 50%;
  z-index: 99;
  pointer-events: none;
}
#bp-calibrate { background: var(--accent-2); color: #fff; border-color: transparent; }
#bp-calibrate:disabled { background: var(--bg); color: var(--muted); border-color: var(--line); }
#bp-scale-display { font-variant-numeric: tabular-nums; padding: 0 .5rem; }
.bp-help { padding: .35rem .75rem; background: var(--surface); border-top: 1px solid var(--line); }

/* Items on the canvas */
.bp-item {
  position: absolute;
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; text-align: center;
  cursor: move;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
  border: 2px solid transparent;
  transition: border-color .1s;
}
.bp-item .label { padding: 2px 4px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.bp-item.selected { border-color: #1f6dba; box-shadow: 0 0 0 2px #fff, 0 0 0 4px #1f6dba; z-index: 10; }
.bp-item.has-issue::after {
  content: "!"; position: absolute; top: -8px; right: -8px;
  width: 18px; height: 18px; line-height: 18px; text-align: center;
  background: var(--danger); color: #fff; border-radius: 50%; font-weight: 700;
  border: 2px solid #fff; font-size: 11px;
}
.bp-resize {
  position: absolute; right: -5px; bottom: -5px; width: 12px; height: 12px;
  background: #fff; border: 1px solid #1f6dba; cursor: nwse-resize;
}

#bp-inspector .field { margin-bottom: .5rem; }
#bp-inspector input, #bp-inspector textarea, #bp-inspector select {
  width: 100%; font: inherit; padding: .35rem .5rem;
  border: 1px solid var(--line); border-radius: 4px; background: #fff;
}
#bp-inspector .swatches { display: flex; gap: .25rem; flex-wrap: wrap; }
#bp-inspector .swatches button {
  width: 22px; height: 22px; padding: 0; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
}
#bp-inspector .swatches button.active { border-color: #1f6dba; }

/* Filters & toolbar bits */
.filters { display: flex; gap: .5rem; }
.filters select { padding: .3rem .5rem; }
kbd {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 3px; padding: 0 .3rem; font: 12px monospace;
}
