/* ===== Reset & Variables ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --radius: 8px;
  --panel-width: 320px;
  --accent: #667eea;
  --accent-hover: #7c93f0;
  --danger: #e74c3c;
}

/* Dark theme (default) */
[data-theme="dark"],
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-panel: #16213e;
  --bg-input: #0f3460;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b0;
  --border: #2a2a4a;
  --canvas-dot: #1a1a2e;
  --shadow-alpha: 0.4;
  --zoom-bg: rgba(0, 0, 0, 0.5);
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-panel: #ffffff;
  --bg-input: #e8ecf1;
  --text-primary: #1a1a2e;
  --text-secondary: #5a5a7a;
  --border: #d0d5dd;
  --canvas-dot: #d8dce3;
  --shadow-alpha: 0.15;
  --zoom-bg: rgba(0, 0, 0, 0.3);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.app-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

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

.theme-select {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 4px 8px;
  font-size: 12px;
  border-radius: var(--radius);
  cursor: pointer;
}

/* ===== Main Layout ===== */
.app-main {
  display: flex;
  height: calc(100vh - 48px);
}

/* ===== Canvas Area ===== */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 20px 20px, var(--canvas-dot) 1px, transparent 1px);
  background-size: 40px 40px;
}

.canvas-wrapper {
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, var(--shadow-alpha));
  border-radius: 4px;
  overflow: hidden;
}

.canvas-wrapper canvas {
  display: block;
}

.canvas-zoom-info {
  position: absolute;
  bottom: 12px;
  left: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--zoom-bg);
  padding: 4px 8px;
  border-radius: 4px;
}

/* ===== Panel ===== */
.panel {
  width: var(--panel-width);
  height: 100%;
  overflow-y: auto;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  padding: 16px;
}

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

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

.panel-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-export {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  width: 100%;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
}

.btn-export + .btn-export {
  margin-top: 8px;
}

.btn-export:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  width: 100%;
  margin-top: 8px;
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-row .btn {
  flex: 1;
}

.btn-device {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 10px 8px;
  font-size: 12px;
}

.btn-device.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.device-buttons {
  display: flex;
  gap: 8px;
}

/* ===== Color Buttons ===== */
.color-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.btn-color {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-input);
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.btn-color.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-color:hover:not(.active) {
  border-color: var(--text-secondary);
}

/* ===== Orientation Buttons ===== */
.orient-buttons {
  display: flex;
  gap: 8px;
}

.btn-orient {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 10px 8px;
  font-size: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-orient.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ===== Drop Zone ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(102, 126, 234, 0.05);
  color: var(--text-primary);
}

/* ===== Controls ===== */
.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.control-row span:first-child {
  min-width: 48px;
}

.control-row input[type="color"] {
  -webkit-appearance: none;
  width: 36px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  cursor: pointer;
  padding: 0;
}

.control-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.control-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.control-row select {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
}

.control-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

/* ===== Gradient Presets ===== */
.gradient-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.gradient-preset {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
}

.gradient-preset:hover,
.gradient-preset.active {
  border-color: var(--accent);
}

/* ===== HEX Input ===== */
.hex-input {
  width: 72px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
  font-family: monospace;
}

/* ===== Layout Presets ===== */
.layout-presets {
  display: flex;
  gap: 6px;
}

.btn-layout {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 4px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.btn-layout:hover,
.btn-layout.active {
  border-color: var(--accent);
}

/* ===== Drop Zone Small ===== */
.drop-zone-small {
  padding: 12px;
  font-size: 12px;
  margin-bottom: 8px;
}

/* ===== Export Info ===== */
.export-info {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.5;
}

/* ===== Export Sidebar ===== */
.export-sidebar {
  width: 200px;
  height: 100%;
  overflow-y: auto;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.export-sidebar-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.export-count {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.export-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.export-item {
  position: relative;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
  flex-shrink: 0;
}

.export-item.active {
  border-color: var(--accent);
}

.export-item:hover {
  border-color: var(--text-secondary);
}

.export-item.active:hover {
  border-color: var(--accent);
}

.export-item.drag-over {
  border-color: var(--accent);
  border-style: dashed;
}

.export-item.dragging {
  opacity: 0.4;
}

.export-thumb {
  width: 100%;
  display: block;
  border-radius: calc(var(--radius) - 2px);
}

.export-item-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
}

.export-item-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.export-item:hover .export-item-delete {
  opacity: 1;
}

.export-sidebar::-webkit-scrollbar {
  width: 6px;
}

.export-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.export-sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ===== Scrollbar ===== */
.panel::-webkit-scrollbar {
  width: 6px;
}

.panel::-webkit-scrollbar-track {
  background: transparent;
}

.panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ===== Project Indicator ===== */
.project-indicator {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color 0.15s;
  white-space: nowrap;
}

.project-indicator:hover {
  color: var(--text-primary);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90vw;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.modal-split {
  display: flex;
  min-height: 300px;
}

.modal-left {
  width: 180px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
}

.modal-right {
  flex: 1;
  padding: 12px 16px;
  overflow-y: auto;
}

.modal-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.storage-info {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== App List (Modal) ===== */
.project-app-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.project-app-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background 0.15s;
}

.project-app-item:hover {
  background: var(--bg-input);
}

.project-app-item.active {
  background: var(--accent);
  color: #fff;
}

.project-app-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.project-app-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.project-app-item:hover .project-app-actions {
  opacity: 1;
}

.project-action-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}

.project-action-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
}

.project-action-danger:hover {
  color: var(--danger);
}

.project-app-item.active .project-action-btn {
  color: rgba(255, 255, 255, 0.7);
}

.project-app-item.active .project-action-btn:hover {
  color: #fff;
}

/* ===== Version Grid (Modal) ===== */
.version-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.version-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
  overflow: hidden;
  position: relative;
}

.version-card:hover {
  border-color: var(--text-secondary);
}

.version-card.active {
  border-color: var(--accent);
}

.version-card-thumb {
  width: 100%;
  aspect-ratio: 9 / 16;
  background: var(--bg-input);
  overflow: hidden;
}

.version-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.version-card-info {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.version-card-name {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.version-card-count {
  font-size: 11px;
  color: var(--text-secondary);
}

.version-card-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.version-card:hover .version-card-actions {
  opacity: 1;
}

.version-card-actions .project-action-btn {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border-radius: 4px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Pro Badge ===== */
.pro-badge {
  display: inline-flex;
  align-items: center;
  background: linear-gradient(135deg, #f5af19, #f12711);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

/* ===== Upgrade Button ===== */
.btn-upgrade {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  border: none;
  font-weight: 600;
}

.btn-upgrade:hover {
  opacity: 0.9;
}

/* ===== Header Avatar ===== */
.header-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--border);
  transition: border-color 0.15s;
}

.header-avatar:hover {
  border-color: var(--accent);
}

/* ===== User Menu Dropdown ===== */
.user-menu-dropdown {
  position: fixed;
  top: 44px;
  right: 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  min-width: 200px;
  padding: 8px 0;
}

.user-menu-info {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-menu-info span:first-child {
  font-size: 13px;
  font-weight: 600;
}

.user-menu-email {
  font-size: 12px;
  color: var(--text-secondary);
}

.user-menu-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.user-menu-item:hover {
  background: var(--bg-input);
}

.user-menu-signout {
  color: var(--danger);
}

/* ===== Sign In Modal ===== */
.signin-modal {
  max-width: 360px;
}

.signin-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.google-signin-container {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

/* ===== Upgrade Modal ===== */
.upgrade-modal {
  max-width: 420px;
}

.upgrade-message {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.upgrade-features {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.upgrade-feature-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.upgrade-check {
  color: #43e97b;
  font-weight: 700;
  font-size: 16px;
}

.upgrade-price {
  text-align: center;
  margin-bottom: 20px;
}

.upgrade-price-amount {
  font-size: 36px;
  font-weight: 700;
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.upgrade-price-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.upgrade-signin-section {
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.upgrade-signin-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.btn-upgrade-cta {
  display: block;
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.btn-upgrade-cta:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.upgrade-license-link {
  text-align: center;
  margin-top: 12px;
  font-size: 12px;
}

.upgrade-license-link a {
  color: var(--text-secondary);
  text-decoration: underline;
}

.upgrade-license-link a:hover {
  color: var(--text-primary);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app-main {
    flex-direction: column;
    overflow-y: auto;
  }
  .export-sidebar {
    width: 100%;
    height: auto;
    max-height: 140px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
  }
  .export-sidebar-header {
    writing-mode: vertical-lr;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 8px;
  }
  .export-list {
    flex-direction: row;
    padding: 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .export-item {
    width: 80px;
    flex-shrink: 0;
  }
  .canvas-area {
    min-height: 50vh;
    padding: 16px;
  }
  .panel {
    width: 100%;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  :root {
    --panel-width: 100%;
  }
  .modal-split {
    flex-direction: column;
    min-height: auto;
  }
  .modal-left {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 120px;
    overflow-y: auto;
  }
  .project-indicator {
    font-size: 11px;
    padding: 2px 4px;
  }
}
