*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --accent: #e94560;
  --accent2: #0f3460;
  --fg: #eee;
  --fg-dim: #999;
  --border: #2a2a4e;
  --radius: 8px;
  --radius-sm: 4px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
}

/* --- App bar --- */
#app-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  height: 52px;
}

#app-bar h1 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

#printer-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

#app-actions {
  display: flex;
  gap: 8px;
}

.status-text {
  font-size: 12px;
  color: var(--fg-dim);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Buttons --- */
.btn {
  font-family: var(--font);
  font-size: 13px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.btn-primary { background: var(--accent2); border-color: var(--accent2); }
.btn-primary:hover { background: #1a4a7a; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #d63850; }
.btn-small { font-size: 12px; padding: 3px 10px; }
.btn-tiny { font-size: 11px; padding: 2px 8px; }

/* --- Main layout --- */
#main-layout {
  display: flex;
  height: calc(100vh - 52px);
  gap: 0;
}

/* --- Editor panel --- */
#editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

#canvas-container {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  overflow: hidden;
  touch-action: none;
}

#label-canvas {
  display: block;
}

#canvas-toolbar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* --- Properties panel --- */
#properties-panel {
  width: 300px;
  padding: 16px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
fieldset:disabled { opacity: 0.4; }
legend {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--fg-dim);
  padding: 0 4px;
}

.dimension-row, .prop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.input-group label {
  font-size: 11px;
  color: var(--fg-dim);
}

input, select, textarea {
  font-family: var(--font);
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  width: 100%;
}

.position-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: 100%;
}
.position-inputs label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: var(--fg-dim);
  gap: 1px;
}
.position-inputs input {
  width: 100%;
}

.preset-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  flex-wrap: wrap;
}

textarea#field-content {
  resize: vertical;
  min-height: 36px;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  #main-layout {
    flex-direction: column;
  }
  #properties-panel {
    width: 100%;
    max-height: 35vh;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    gap: 10px;
  }
  #editor-panel {
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px 12px;
  }
  #app-bar {
    gap: 6px;
    padding: 6px 10px;
    height: 44px;
    flex-wrap: nowrap;
  }
  #app-bar h1 {
    font-size: 13px;
  }
  .btn {
    font-size: 11px;
    padding: 4px 8px;
  }
  .btn-small {
    font-size: 11px;
    padding: 2px 8px;
  }
  fieldset {
    padding: 8px;
  }
}

/* Medium screens: constrain panel width so editor has room */
@media (min-width: 641px) and (max-width: 1024px) {
  #properties-panel {
    width: 260px;
    padding: 12px;
  }
}

/* Small desktop: compact panel */
@media (min-width: 1025px) and (max-width: 1366px) {
  #properties-panel {
    width: 280px;
  }
}