
  * { box-sizing: border-box; }
  :host {
    display: block;
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    overflow: hidden;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    font-size: 12px;
    background: #eef2f7;
    color: #333;
    user-select: none;
  }

  #app {
    width: 100%; max-width: 1200px; height: 100%;
    margin: 0 auto;
    background: #fff;
    display: flex; flex-direction: column;
    border: 1px solid #eee;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
  }

  .topbar {
    height: 34px; flex: 0 0 34px;
    background: #fff; border-bottom: 1px solid #eee;
    display: flex; align-items: center;
    padding: 0 8px; gap: 6px;
  }
  .topbar .title {
    font-weight: bold; color: #4158d0; margin-right: auto; font-size: 13px;
  }
  .topbar button, .topbar .file-btn {
    background: #e8e8ff; color: #667eea; border: 1px solid #667eea;
    padding: 4px 9px; border-radius: 4px; cursor: pointer;
    font-size: 11px; font-weight: bold;
    font-family: inherit;
  }
  .topbar button:hover, .topbar .file-btn:hover { background: #d4d4ff; }
  .topbar button:disabled { opacity: 0.5; cursor: not-allowed; }
  .topbar .btn-download { background: #51cf66; color: #fff; border-color: #40c057; }
  .topbar .btn-download:hover:not(:disabled) { background: #40c057; }
  .topbar .btn-use { background: #4158d0; color: #fff; border-color: #4158d0; }
  .topbar .btn-use:hover:not(:disabled) { background: #5268e0; }

  /* Label upload — cara andal */
  .file-btn {
    display: inline-block;
  }
  #fileInput {
    display: none;
  }

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

  .sidebar {
    width: 240px; flex: 0 0 240px;
    background: #fff; border-right: 1px solid #eee;
    overflow-y: auto; padding: 4px;
  }
  .sidebar::-webkit-scrollbar { width: 8px; }
  .sidebar::-webkit-scrollbar-thumb { background: #667eea; border-radius: 4px; }
  .sidebar::-webkit-scrollbar-track { background: #f1f1f1; }

  .panel {
    background: #fff; border: 1px solid #eee; border-radius: 5px;
    margin-bottom: 4px; overflow: hidden;
  }
  .panel-header {
    padding: 4px 8px; background: #f0f0f0;
    font-weight: bold; font-size: 10px; color: #4158d0;
    cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
  }
  .panel-header:hover { background: #e8e8ff; }
  .panel-header .arrow { font-size: 10px; transition: transform 0.15s; }
  .panel.collapsed .panel-header .arrow { transform: rotate(-90deg); }
  .panel-body { padding: 5px 8px 6px; }
  .panel.collapsed .panel-body { display: none; }
  .panel.disabled { opacity: 0.4; pointer-events: none; }

  .row { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; }
  .row:last-child { margin-bottom: 0; }
  .row label { flex: 0 0 78px; font-size: 10px; color: #666; }
  .row input[type="range"] {
    flex: 1; min-width: 0; height: 4px;
    -webkit-appearance: none; background: #ddd;
    border-radius: 2px; outline: none;
  }
  .row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 12px; height: 12px;
    background: #667eea; border-radius: 50%; cursor: pointer;
    border: 1px solid #4158d0;
  }
  .row input[type="range"]::-moz-range-thumb {
    width: 12px; height: 12px; background: #667eea;
    border-radius: 50%; cursor: pointer; border: 1px solid #4158d0;
  }
  .row .val {
    flex: 0 0 30px; text-align: right;
    font-size: 10px; color: #333;
    font-variant-numeric: tabular-nums;
  }

  .radios { display: flex; flex-direction: column; gap: 2px; }
  .radios label {
    display: flex; align-items: center; gap: 5px;
    font-size: 10px; cursor: pointer; color: #555;
    padding: 2px 4px; border-radius: 3px;
  }
  .radios label:hover { background: #f4f4ff; }
  .radios label.active-radio {
    background: #e8e8ff; color: #4158d0; font-weight: bold;
  }
  .radios input[type="radio"] { margin: 0; accent-color: #667eea; }
  .radios input[type="color"] {
    width: 30px; height: 22px; border: 1px solid #ddd;
    border-radius: 3px; cursor: pointer; padding: 1px; background: #fff;
  }

  .swatches { display: flex; gap: 5px; margin-bottom: 6px; }
  .swatch {
    flex: 1; height: 22px; border-radius: 4px;
    border: 2px solid #ddd; cursor: pointer; position: relative;
  }
  .swatch.active { border-color: #fff; box-shadow: 0 0 0 2px #667eea; }
  .swatch.checker { background: repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 50% / 8px 8px; }
  .swatch.white   { background: #fff; }
  .swatch.red     { background: #e53935; }
  .swatch.green   { background: #43a047; }
  .swatch.blue    { background: #4158d0; }

  .btn-group {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 3px; margin-bottom: 4px;
  }
  .btn-group button {
    padding: 4px; background: #e8e8ff; color: #667eea;
    border: 1px solid #667eea; border-radius: 4px;
    cursor: pointer; font-size: 10px; font-weight: bold;
    font-family: inherit;
  }
  .btn-group button:hover:not(:disabled) { background: #d4d4ff; }
  .btn-group button:disabled { opacity: 0.5; cursor: not-allowed; }
  .btn-group .full { grid-column: 1 / -1; }
  .btn-group .btn-success { background: #51cf66; color: #fff; border-color: #40c057; }
  .btn-group .btn-warn    { background: #ffa94d; color: #fff; border-color: #ff9800; }
  .btn-group .btn-danger  { background: #ff6b6b; color: #fff; border-color: #ee5a52; }

  .info-line {
    font-size: 10px; color: #777; line-height: 1.3; margin-top: 4px;
  }

  .stage {
    flex: 1; background: #eef2f7;
    display: flex; flex-direction: column;
    min-width: 0; position: relative;
  }
  .tabbar {
    height: 24px; flex: 0 0 24px;
    background: #f8f9fc; border-bottom: 1px solid #eee;
    display: flex; align-items: stretch;
  }
  .tab {
    padding: 0 12px; display: flex; align-items: center;
    font-size: 10px; color: #666; cursor: pointer;
    border-right: 1px solid #eee; background: #f8f9fc;
  }
  .tab:hover { color: #4158d0; }
  .tab.active {
    background: #fff; color: #4158d0;
    font-weight: bold; border-bottom: 2px solid #4158d0;
  }

  .canvas-container {
    flex: 1; overflow: auto;
    display: flex; align-items: center; justify-content: center;
    padding: 6px; position: relative; min-height: 0;
  }
  .canvas-container::-webkit-scrollbar { width: 10px; height: 10px; }
  .canvas-container::-webkit-scrollbar-thumb { background: #667eea; border-radius: 5px; }
  .canvas-container::-webkit-scrollbar-track { background: #f1f1f1; }

  .canvas-stack {
    position: relative; display: inline-block;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  }
  .canvas-stack canvas {
    display: block; max-width: 100%; max-height: 100%;
  }

  #resultBgWrap {
    display: inline-block; position: relative;
    background: repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 50% / 20px 20px;
  }

  .empty-state {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: #999; font-size: 14px; pointer-events: none;
  }
  .empty-state .big { font-size: 40px; margin-bottom: 10px; opacity: 0.5; }
  .hidden { display: none !important; }

  .detect-badge {
    font-size: 10px; padding: 4px 8px; border-radius: 3px;
    font-weight: bold; text-align: center; margin-bottom: 6px;
  }
  .detect-black { background: #333; color: #fff; border: 1px solid #333; }
  .detect-color { background: #ff9800; color: #000; }
  .detect-none  { background: #f0f0f0; color: #666; }

  .statusbar {
    height: 18px; flex: 0 0 18px;
    background: #fff; border-top: 1px solid #eee;
    display: flex; align-items: center;
    padding: 0 8px; font-size: 9px; color: #666;
    gap: 10px;
  }
  .statusbar .right { margin-left: auto; }

  @media (max-width: 700px) {
    .topbar { height: auto; min-height: 40px; flex-wrap: wrap; padding: 6px; }
    .topbar .title { flex: 1 0 100%; }
    .topbar button, .topbar .file-btn { padding: 5px 8px; }
    .main { min-height: 0; }
    .sidebar { width: 210px; flex-basis: 210px; }
    .panel-body { padding: 6px; }
    .row label { flex-basis: 70px; }
    .tab { padding: 0 8px; }
  }
