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

:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-alt: #FAFAFA;
  --accent: #1D1D1F;
  --accent-hover: #000000;
  --accent-light: #F0F0F2;
  --text: #1D1D1F;
  --text-secondary: #6E6E73;
  --text-muted: #AEAEB2;
  --border: #D2D2D7;
  --border-light: #E8E8ED;
  --danger: #FF3B30;
  --danger-light: #FFF0EF;
  --success: #34C759;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 6px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.08);
  --sidebar-w: 380px;
  --topbar-h: 56px;
  --font-display: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-h);
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 100;
}

.topbar-row-top {
  display: contents;
}

.topbar-right {
  display: contents;
}

.logo {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--text);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-icon svg { width: 15px; height: 15px; }

.logo-text { display: flex; flex-direction: column; line-height: 1; }

.logo-byline {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.lang-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--accent-light);
  border: none;
  border-radius: 7px;
  padding: 6px 28px 6px 10px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236E6E73' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: background-color 0.15s;
}

.lang-select:hover { background: var(--border-light); }

.topbar-actions { display: flex; gap: 8px; align-items: center; }

.view-toggle {
  display: flex;
  background: var(--accent-light);
  border: none;
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}

.view-btn {
  padding: 6px 16px;
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 7px;
}

.view-btn:hover { color: var(--text); }

.view-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

.btn {
  padding: 6px 14px;
  border: none;
  background: var(--accent-light);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  gap: 6px;
}

.btn:hover { background: var(--border-light); }

.btn-danger {
  color: var(--danger);
  border-color: transparent;
  background: none;
  padding: 4px 8px;
  border: none;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  border-radius: 4px;
}

.btn-danger:hover { background: var(--danger-light); }

.btn-action {
  color: var(--text-muted);
  background: none;
  padding: 4px 6px;
  border: none;
  cursor: pointer;
  line-height: 1;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

.btn-action:hover { background: var(--accent-light); color: var(--text); }

.field-row-swap { align-items: flex-end; }

.btn-swap {
  width: 28px;
  height: 34px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}

.btn-swap:hover { background: var(--accent-light); color: var(--text); border-color: var(--border); }

/* ── LAYOUT ── */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sidebar-section {
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-section:last-child { border-bottom: none; }

.section-title {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title svg { width: 14px; height: 14px; color: var(--text-muted); }

/* ── FORM FIELDS ── */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.field-row .field { flex: 1; margin-bottom: 0; }

input[type="number"], input[type="text"], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: all 0.15s;
  outline: none;
}

input[type="number"]:focus, input[type="text"]:focus, select:focus {
  border-color: #007AFF;
  box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.color-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.color-swatch input[type="color"] {
  position: absolute;
  inset: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  border: none;
  cursor: pointer;
  padding: 0;
}

.color-hex {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

.color-hex:focus { border-color: var(--accent); }

/* ── FRAME CARDS ── */
.frame-card {
  background: var(--surface-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.frame-card:hover { border-color: var(--border); }

.frame-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}

.frame-card-title {
  font-weight: 500;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.frame-card-title .frame-num {
  width: 20px;
  height: 20px;
  background: var(--text);
  color: white;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
}

.frame-card-dims {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.frame-total-size {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  padding: 6px 8px;
  background: var(--accent-light);
  border-radius: 6px;
  text-align: center;
  font-weight: 500;
}

.frame-card-actions { display: flex; gap: 4px; align-items: center; }

.frame-card-toggle {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: transform 0.2s;
}

.frame-card-toggle.open { transform: rotate(180deg); }

.frame-card-body {
  padding: 0 14px 14px;
  display: none;
}

.frame-card-body.open { display: block; }

/* ── TOGGLE SWITCH ── */
.toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.toggle-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.toggle {
  width: 42px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.25s ease;
  border: none;
  padding: 0;
}

.toggle.active { background: #34C759; }

.toggle::after {
  content: '';
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.25s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 1px rgba(0,0,0,0.06);
}

.toggle.active::after { transform: translateX(18px); }

.sub-fields {
  padding: 10px 0 0;
  display: none;
}

.sub-fields.open { display: block; }

/* ── IMAGE UPLOAD ── */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.image-upload-area:hover { border-color: var(--border); background: var(--accent-light); }

.image-upload-area.has-image { border-style: solid; padding: 0; }

.image-upload-area img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  display: block;
}

.image-upload-area .upload-text {
  font-size: 12px;
  color: var(--text-muted);
}

.image-upload-area .upload-text strong {
  color: #007AFF;
  font-weight: 500;
}

.image-upload-area input { display: none; }

.upload-progress {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.upload-progress-track {
  width: 100%;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  background: #007AFF;
  border-radius: 2px;
  width: 0%;
  transition: width 0.2s ease;
}

.upload-progress-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.upload-error {
  font-size: 11px;
  color: var(--danger);
  font-weight: 500;
  padding: 8px 12px;
  background: var(--danger-light);
  border-radius: 6px;
  margin-top: 6px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.image-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.add-frame-btn {
  width: 100%;
  padding: 12px;
  border: 2px dashed var(--border);
  background: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.add-frame-btn:hover {
  border-color: var(--border);
  color: var(--text);
  background: var(--accent-light);
}

/* ── MAIN AREA ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  position: relative;
}

#mockupCanvas { display: block; max-width: 100%; max-height: 100%; }

.blueprint-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
}

#blueprintSvg { display: block; max-width: 100%; max-height: 100%; }

.info-bar {
  padding: 10px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 24px;
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.info-item { display: flex; align-items: center; gap: 6px; }
.info-item strong { color: var(--text); font-weight: 600; }
.info-item.warning { color: var(--danger); }
.info-item.warning strong { color: var(--danger); }

.hidden { display: none !important; }

/* ── PRINT ── */
@media print {
  .topbar, .sidebar, .info-bar, .canvas-container { display: none !important; }
  .app-body { display: block !important; overflow: visible !important; }
  .main { overflow: visible !important; height: auto !important; }
  .blueprint-container {
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
    height: 100vh !important;
    page-break-inside: avoid;
  }
  .blueprint-container.hidden { display: flex !important; }
  #blueprintSvg {
    max-width: 100vw !important;
    max-height: 100vh !important;
    width: auto !important;
    height: auto !important;
  }
  body { background: white !important; overflow: visible !important; }
  html { overflow: visible !important; }
  @page { size: landscape; margin: 1cm; }
}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  html {
    height: auto;
    overflow: visible;
    overflow-y: scroll;
  }

  body {
    height: auto;
    overflow: visible;
    display: block;
  }

  /* ── TOPBAR: sticky, two rows ── */
  .topbar {
    height: auto;
    flex-direction: column;
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 200;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .topbar-row-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 14px;
  }

  .topbar-right {
    display: flex;
    align-items: center;
  }

  .logo { font-size: 15px; gap: 7px; }
  .logo-icon { width: 24px; height: 24px; }
  .logo-icon svg { width: 13px; height: 13px; }
  .logo-byline { font-size: 9px; }

  .topbar-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0 14px 8px;
    gap: 6px;
  }

  /* Hide print/save in topbar on mobile — they move to the action bar */
  .topbar-actions #printBtn,
  .topbar-actions #saveImgBtn { display: none !important; }

  .view-btn { padding: 6px 12px; font-size: 12px; }
  .lang-select { font-size: 11px; padding: 5px 24px 5px 8px; }

  /* ── LAYOUT ── */
  .app-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .sidebar {
    width: 100%;
    max-height: none;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  :root { --sidebar-w: 100%; }
  .sidebar-section { padding: 16px; }

  /* ── MOBILE ACTION BAR (print/save, not sticky — just a divider bar) ── */
  .mobile-action-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px;
    margin-bottom: 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    border-top: 1px solid var(--border-light);
  }

  /* ── MAIN AREA ── */
  .main {
    overflow: visible;
    min-height: 60vh;
  }

  .canvas-container {
    padding: 8px;
    min-height: calc(100vh - 70px);
    min-height: calc(100dvh - 70px);
  }

  .blueprint-container {
    padding: 4px;
    overflow: visible;
    min-height: auto;
    align-items: flex-start;
    justify-content: center;
  }

  #blueprintSvg {
    max-width: 100%;
    max-height: none;
    min-width: 0;
    width: 100% !important;
    height: auto !important;
  }

  .info-bar {
    flex-wrap: wrap;
    gap: 12px 20px;
    padding: 10px 14px;
    font-size: 11px;
  }

  .field-row { flex-wrap: wrap; }
  .field-row .field { min-width: 0; }
  .field-row-swap { flex-wrap: nowrap; }
}

/* Hide mobile action bar on desktop */
@media (min-width: 901px) {
  .mobile-action-bar { display: none; }
}
