:root {
  --bg: #f7f6f3;
  --bg-2: #efeee9;
  --panel: #ffffff;
  --border: #d8d6d2;
  --text: #1a1a1a;
  --text-2: #4b4b4b;
  --text-3: #8a8a8a;
  --accent: #c96442;
  --accent-tint: #f1d3a8;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
}

.header-actions { display: flex; gap: 8px; }

.file-btn, .primary-btn, button {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  cursor: pointer;
}

.file-btn { display: inline-block; }

.primary-btn {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.ghost-btn {
  background: white;
  border: 1px solid var(--border);
  width: 30px; height: 30px;
  padding: 0;
  font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}

.app-main {
  display: grid;
  grid-template-columns: 320px 1fr;
  flex: 1;
  min-height: 0;
}

.controls {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  min-height: 0;
}

.control-group {
  margin-bottom: 18px;
}
.control-group h3 {
  font-size: 11px;
  font-weight: 600;
  margin: 0 0 10px;
  letter-spacing: 0.05em;
  color: var(--text-3);
  text-transform: uppercase;
}

.control-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  gap: 10px;
}
.control-row label {
  flex: 0 0 110px;
  font-size: 12px;
  color: var(--text-2);
}
.control-row input[type=range] {
  flex: 1;
  min-width: 0;
}
.control-row .value {
  flex: 0 0 50px;
  text-align: right;
  font: 12px ui-monospace, Menlo, monospace;
  color: var(--text);
}
.control-row.toggle label { flex: 1; }
.control-row.toggle input { flex: 0 0 auto; }

.preview-wrap {
  position: relative;
  background: var(--bg-2);
  min-height: 0;
  min-width: 0;
}
.preview-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.preview-canvas canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  z-index: 1;
}
.preview-empty small {
  font-size: 11px;
  margin-top: 6px;
}

.preview-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 2;
}
.btn-group {
  display: inline-flex;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.btn-group button {
  border: none;
  border-radius: 0;
  padding: 5px 10px;
  font-size: 12px;
  background: white;
}
.btn-group button + button { border-left: 1px solid var(--border); }
.btn-group button.active {
  background: var(--accent);
  color: white;
}

.status-pill {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(0,0,0,0.7);
  color: white;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.2s, bottom 0.2s, left 0.2s, transform 0.2s, font-size 0.2s, padding 0.2s;
  pointer-events: none;
  z-index: 2;
}
.status-pill.show { opacity: 1; }

/* Centered error state */
.status-pill.error {
  bottom: 50%;
  left: 50%;
  transform: translate(-50%, 50%);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 24px;
  background: rgba(180, 30, 30, 0.92);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  max-width: 60%;
  text-align: center;
  white-space: normal;
}

/* Prominent centered state for long-running operations */
.status-pill.loading {
  bottom: 50%;
  left: 50%;
  transform: translate(-50%, 50%);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 20px 10px 44px;
  border-radius: 24px;
  background: rgba(0, 0, 0, 0.82);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.status-pill.loading::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: white;
  border-radius: 50%;
  animation: status-spin 0.7s linear infinite;
  will-change: transform;
}

@keyframes status-spin {
  to { transform: rotate(360deg); }
}

.preview-dims {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0,0,0,0.55);
  color: white;
  font: 11px ui-monospace, Menlo, monospace;
  padding: 4px 10px;
  border-radius: 12px;
  pointer-events: none;
  z-index: 2;
  display: none;
}

.scale-label {
  color: white;
  font: 10px ui-monospace, Menlo, monospace;
  background: rgba(0,0,0,0.6);
  padding: 2px 7px;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}

#depth-ai-btn {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
#depth-ai-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.depth-ai-note {
  font-size: 11px;
  color: var(--text-3);
  margin: 6px 0 0;
  line-height: 1.4;
}

/* ── Crop modal ─────────────────────────────────────────────────────────── */

.crop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.crop-modal {
  background: var(--panel);
  border-radius: 10px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.crop-header {
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.crop-header h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
}
.crop-hint {
  font-size: 11px;
  color: var(--text-3);
  margin: 0;
}

.crop-canvas {
  display: block;
  cursor: crosshair;
  flex-shrink: 0;
}

.crop-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.crop-skip-btn {
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  cursor: pointer;
}
.crop-skip-btn:hover { background: var(--bg-2); }

.crop-footer-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

@media (max-width: 700px) {
  .app-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .controls {
    max-height: 42vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
