:root {
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #eff6ff;
  --success:      #22c55e;
  --offline:      #94a3b8;
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text2:        #64748b;
  --text3:        #94a3b8;
  --radius:       8px;
  --radius-sm:    4px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --sidebar-w:    200px;
  --topbar-h:     52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font: 13px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--topbar-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; box-shadow: var(--shadow);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 28px; height: 28px; background: var(--accent); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.brand-name { font-size: 15px; font-weight: 700; }
.brand-sub  { font-size: 11px; color: var(--text3); }
.topbar-log {
  font-size: 12px; color: var(--text2); font-family: monospace;
  max-width: 50%; text-align: right; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* ── Root layout ────────────────────────────────────────── */
.app-layout {
  display: flex;
  padding-top: var(--topbar-h);
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 10px; overflow-y: auto; height: 100%;
}

/* ── Main scroll area ───────────────────────────────────── */
.main-area {
  flex: 1; min-width: 0; overflow-y: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 10px;
}

/* ── Panel ──────────────────────────────────────────────── */
.panel {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-header {
  padding: 8px 12px; font-size: 12px; font-weight: 600;
  border-bottom: 1px solid var(--border); background: var(--bg);
  color: var(--text2); display: flex; align-items: center;
  justify-content: space-between; gap: 8px; flex-shrink: 0;
}
.panel-body { padding: 10px 12px; flex: 1; }

/* ── Sidebar buttons ────────────────────────────────────── */
.menu_button {
  display: block; width: 100%; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 12px; cursor: pointer; text-align: left; line-height: 1.4;
  transition: background .12s, border-color .12s, color .12s;
  margin-bottom: 3px;
}
.menu_button:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.hidden_input { width: .1px; height: .1px; opacity: 0; overflow: hidden; position: absolute; z-index: -1; }
.btn_group { margin-bottom: 2px; }
.section_label {
  font-size: 10px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 12px 0 5px; padding-bottom: 3px; border-bottom: 1px solid var(--border);
}

/* ── Images row ─────────────────────────────────────────── */
.images-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  /* equal height guaranteed by grid */
}
.images-row .panel { min-height: 220px; max-height: 420px; overflow: hidden; }
.images-row .panel-body { overflow: auto; }

/* URL input strip inside src panel */
.url-strip {
  display: flex; gap: 6px; padding: 6px 12px;
  border-bottom: 1px solid var(--border); background: var(--bg); flex-shrink: 0;
}
.url-input {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 4px 8px; font-size: 12px;
}
.url-input:focus { outline: none; border-color: var(--accent); }
.url-btn {
  padding: 4px 12px; font-size: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--accent); background: var(--accent);
  color: #fff; cursor: pointer; white-space: nowrap;
  transition: background .12s;
}
.url-btn:hover { background: var(--accent-hover); }

.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--bg); text-align: center;
  padding: 40px 16px; color: var(--text3); font-size: 13px;
  transition: border-color .15s, background .15s, color .15s; cursor: pointer;
}
.drop-zone:hover { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }

.dst-placeholder {
  display: flex; align-items: center; justify-content: center;
  height: 100%; min-height: 180px; color: var(--text3); font-size: 13px;
}
.sourceImage { max-width: 100%; max-height: 340px; display: block; margin: 0 auto; border-radius: var(--radius-sm); }
#canvas { max-width: 100%; display: block; margin: 0 auto; border-radius: var(--radius-sm); }

/* ── Settings row ───────────────────────────────────────── */
.settings-row {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
.settings-table { width: 100%; border-collapse: collapse; }
.settings-table td { padding: 3px 4px; font-size: 12px; vertical-align: middle; white-space: nowrap; }
.comment { color: var(--text2); }
.nud { width: 68px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px 5px; font-size: 12px; }
.nud:focus { outline: none; border-color: var(--accent); }
.full-input {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 8px; font-size: 12px; margin-bottom: 6px;
}
.full-input:focus { outline: none; border-color: var(--accent); }

input[type=number], input[type=text], select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 3px 5px; font-size: 12px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[type=radio] { accent-color: var(--accent); }
.rm-label { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: 12px; cursor: pointer; }
.rm-label input { margin: 0; }

/* ── Device selector ────────────────────────────────────── */
.device-toolbar { display: flex; gap: 5px; }
.chip-btn {
  padding: 3px 9px; font-size: 11px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; color: var(--text2); transition: all .12s;
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.chip-btn--active { border-color: var(--accent); background: var(--accent); color: #fff; }
.chip-btn--active:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.device-panel-body { padding: 10px 12px; max-height: 160px; overflow-y: auto; }

/* Device panel and images-row never grow/shrink — only settings-row is flexible */
.main-area > .panel:first-child { flex: 0 0 auto; }
.images-row { flex: 0 0 auto; }
.settings-row { flex: 0 0 auto; }
.device-group + .device-group { margin-top: 10px; }
.device-group-label {
  font-size: 10px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.device-group-label::before {
  content: ''; display: block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--success);
}
.device-group-label.offline-label::before { background: var(--offline); }
.device-cards { display: flex; flex-wrap: wrap; gap: 7px; }

.device-card {
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; cursor: pointer; user-select: none;
  display: flex; align-items: flex-start; gap: 7px;
  min-width: 150px; max-width: 195px; background: var(--surface);
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.device-card:hover { border-color: var(--accent); background: var(--accent-light); }
.device-card.selected {
  border-color: var(--accent); background: var(--accent-light);
  box-shadow: 0 0 0 2px rgba(59,130,246,.15);
}
.device-check { margin-top: 1px; accent-color: var(--accent); }
.device-info  { flex: 1; min-width: 0; }
.device-name  { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-meta  { font-size: 11px; color: var(--text3); margin-top: 1px; }
.status-dot   { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; margin-top: 3px; }
.status-dot.online  { background: var(--success); box-shadow: 0 0 0 2px rgba(34,197,94,.2); }
.status-dot.offline { background: var(--offline); }
.no-devices { color: var(--text3); font-size: 12px; }

/* ── Primary button variant (upload etc.) ───────────────── */
.menu_button--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
}
.menu_button--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* ── Mobile (≤700px) ────────────────────────────────────── */
@media (max-width: 700px) {
  body { overflow-y: auto; }

  .app-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  /* Sidebar → full-width block; grid lives on #BT, not .sidebar */
  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 2px solid var(--border);
    padding: 8px;
    overflow: visible;
  }
  .sidebar #BT {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .sidebar .section_label {
    grid-column: 1 / -1;
    margin: 6px 0 2px;
    width: auto;
  }
  .sidebar .btn_group { margin-bottom: 0; }
  .sidebar .menu_button {
    font-size: 11px;
    padding: 5px 6px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
  }

  .main-area {
    overflow: visible;
    padding: 8px;
  }

  /* Stack image and settings panels to single column */
  .images-row       { grid-template-columns: 1fr; }
  .settings-row     { grid-template-columns: 1fr; }

  .images-row .panel { max-height: 320px; }

  .drop-zone { padding: 24px 16px; }

  /* Devices wrap freely */
  .device-card { min-width: 120px; max-width: 100%; }

  /* More room for device list on mobile */
  .device-panel-body { max-height: 180px; }

  .brand-sub { display: none; }
}
