/* ── Custom Properties ────────────────────────────────────────────── */
:root {
  --bg:          #0f0f17;
  --surface:     #1a1a2e;
  --surface2:    #23233a;
  --surface3:    #2d2d47;
  --border:      #3a3a5c;
  --accent:      #e8b86d;
  --accent-dim:  #c49a4e;
  --accent-glow: rgba(232, 184, 109, 0.15);
  --text:        #e8e8f0;
  --text-muted:  #8888aa;
  --text-dim:    #5a5a7a;
  --success:     #4caf82;
  --error:       #e05c5c;
  --warning:     #e8b86d;
  --info:        #5b9cf6;

  --radius:      8px;
  --radius-lg:   14px;
  --shadow:      0 2px 12px rgba(0,0,0,0.4);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.6);

  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:   'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

  --nav-height:  56px;
  --sidebar-w:   220px;
}

/* ── Reset ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 15px; }
body {
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ── Loader ───────────────────────────────────────────────────────── */
.loader-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  background: var(--bg);
  z-index: 9999;
}
.loader-logo {
  display: flex; align-items: center; gap: 12px;
  font-size: 1.3rem; font-weight: 600; color: var(--text);
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Layout: Shell ────────────────────────────────────────────────── */
#app { min-height: 100vh; display: flex; flex-direction: column; }

.nav {
  position: fixed; top: 0; left: 0; right: 0; height: var(--nav-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 16px;
  z-index: 100;
}
.nav-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1rem; color: var(--text);
}
.nav-brand svg { flex-shrink: 0; }
.nav-spacer { flex: 1; }
.nav-role-badge {
  padding: 3px 10px; border-radius: 20px; font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.nav-role-badge.admin { background: rgba(232,184,109,0.15); color: var(--accent); }
.nav-role-badge.user  { background: rgba(91,156,246,0.15); color: var(--info); }
.nav-label { font-size: 0.85rem; color: var(--text-muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shell {
  display: flex;
  margin-top: var(--nav-height);
  min-height: calc(100vh - var(--nav-height));
}
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  position: fixed;
  top: var(--nav-height);
  bottom: 0;
  overflow-y: auto;
}
.sidebar-nav { list-style: none; }
.sidebar-nav li a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: var(--text-muted); font-size: 0.9rem;
  transition: color 0.15s, background 0.15s;
}
.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  color: var(--text); background: var(--surface3); text-decoration: none;
}
.sidebar-nav li a.active { border-left: 3px solid var(--accent); padding-left: 17px; color: var(--accent); }
.sidebar-nav .nav-icon { width: 16px; text-align: center; }
.sidebar-section { padding: 14px 20px 6px; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 28px 32px;
  min-width: 0;
}

/* ── Forms ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; margin-bottom: 6px; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238888aa' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { margin-top: 5px; font-size: 0.78rem; color: var(--text-dim); }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius); font-size: 0.875rem; font-weight: 500;
  border: 1px solid transparent; transition: all 0.15s; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #1a1a2e; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }
.btn-secondary { background: var(--surface3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface2); border-color: var(--text-dim); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface2); }
.btn-danger { background: transparent; color: var(--error); border-color: var(--error); }
.btn-danger:hover:not(:disabled) { background: rgba(224,92,92,0.1); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-icon { padding: 8px; border-radius: var(--radius); }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.card-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ── Page Header ──────────────────────────────────────────────────── */
.page-header { margin-bottom: 24px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.page-subtitle { margin-top: 4px; font-size: 0.875rem; color: var(--text-muted); }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Tables ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 14px; text-align: left; font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim);
  background: var(--surface2); border-bottom: 1px solid var(--border);
}
td {
  padding: 11px 14px; font-size: 0.875rem; color: var(--text-muted);
  border-bottom: 1px solid rgba(58,58,92,0.5);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); color: var(--text); }
td .text-main { color: var(--text); font-weight: 500; }
td .text-sub  { color: var(--text-dim); font-size: 0.78rem; }

/* ── Badges / Status ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 20px; font-size: 0.72rem; font-weight: 600;
}
.badge-draft  { background: rgba(88,88,140,0.25); color: #9898c8; }
.badge-final  { background: rgba(76,175,130,0.2); color: var(--success); }
.badge-active { background: rgba(76,175,130,0.2); color: var(--success); }
.badge-inactive { background: rgba(224,92,92,0.15); color: var(--error); }

/* ── Grids ────────────────────────────────────────────────────────── */
.design-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}
.design-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.design-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
  transform: translateY(-2px);
}
.design-card-thumb {
  width: 100%; aspect-ratio: 4/3;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.design-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.design-card-thumb .thumb-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text-dim); font-size: 0.78rem;
}
.design-card-body { padding: 12px 14px; }
.design-card-name { font-weight: 600; color: var(--text); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.design-card-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }
.design-card-footer {
  padding: 8px 14px 12px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ── File Upload Drop Zone ────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.dropzone-icon { font-size: 2.5rem; margin-bottom: 10px; }
.dropzone-title { font-size: 0.95rem; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.dropzone-sub { font-size: 0.8rem; color: var(--text-muted); }
.dropzone-preview { margin-top: 12px; }
.dropzone-preview img { max-height: 120px; margin: 0 auto; border-radius: var(--radius); border: 1px solid var(--border); }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; line-height: 1; padding: 4px; border-radius: 4px; }
.modal-close:hover { color: var(--text); background: var(--surface2); }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-lg { max-width: 820px; }
.modal-xl { max-width: 1100px; }

/* ── Toast Notifications ──────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 9000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius);
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 0.875rem; color: var(--text);
  box-shadow: var(--shadow);
  animation: slideInRight 0.25s ease, fadeOut 0.3s ease 3.7s forwards;
  display: flex; align-items: center; gap: 10px; max-width: 360px;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--error); }
.toast.warning { border-color: var(--warning); }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(100%); } }

/* ── Alert / Empty State ──────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 0.875rem; margin-bottom: 16px; }
.alert-error   { background: rgba(224,92,92,0.12); border: 1px solid rgba(224,92,92,0.3); color: #f08080; }
.alert-success { background: rgba(76,175,130,0.12); border: 1px solid rgba(76,175,130,0.3); color: #6dcc9e; }
.alert-info    { background: rgba(91,156,246,0.12); border: 1px solid rgba(91,156,246,0.3); color: #7ab4f8; }

.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state-sub { font-size: 0.875rem; }

/* ── Login Page ───────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-bottom: 28px;
  font-size: 1.2rem; font-weight: 700;
}
.login-title { font-size: 1.3rem; font-weight: 700; text-align: center; margin-bottom: 4px; }
.login-sub { font-size: 0.875rem; color: var(--text-muted); text-align: center; margin-bottom: 24px; }

/* ── Canvas Studio Layout ─────────────────────────────────────────── */
.studio-layout {
  display: flex; gap: 0;
  min-height: calc(100vh - var(--nav-height));
  margin-top: var(--nav-height);
}
.studio-canvas-area {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: #090910;
  padding: 20px;
  align-items: center;
  justify-content: flex-start;
  min-height: calc(100vh - var(--nav-height));
}
.studio-panel {
  width: 320px; flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.studio-panel-section { padding: 16px 18px; border-bottom: 1px solid var(--border); }
.studio-panel-section:last-child { border-bottom: none; }
.studio-section-title { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); margin-bottom: 12px; }

.canvas-container {
  position: relative;
  background: var(--surface2);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.canvas-container canvas { display: block; }

/* ── Sliders ──────────────────────────────────────────────────────── */
.slider-group { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.slider-label { font-size: 0.8rem; color: var(--text-muted); min-width: 60px; }
.slider-value { font-size: 0.8rem; color: var(--accent); min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] {
  flex: 1; appearance: none; height: 4px;
  background: var(--surface3); border-radius: 2px; outline: none;
}
input[type=range]::-webkit-slider-thumb {
  appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border: none;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}

/* ── Zone Editor ──────────────────────────────────────────────────── */
.zone-editor-wrap {
  position: relative; display: inline-block;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--surface2);
}
.zone-editor-wrap img { display: block; max-width: 100%; }
.zone-editor-overlay {
  position: absolute; inset: 0; cursor: crosshair;
}
.zone-rect {
  position: absolute; border: 2px solid var(--accent);
  background: var(--accent-glow);
  border-radius: 2px; cursor: move;
}
.zone-rect .zone-label {
  position: absolute; top: -22px; left: 0;
  background: var(--accent); color: #1a1a2e;
  font-size: 0.68rem; font-weight: 700; padding: 1px 6px; border-radius: 3px;
  white-space: nowrap;
}
.zone-rect .zone-handle {
  position: absolute; right: -6px; bottom: -6px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); cursor: nwse-resize;
}

/* ── Export Panel ─────────────────────────────────────────────────── */
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.export-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 10px; border-radius: var(--radius);
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.8rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.export-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }
.export-btn-icon { font-size: 1.6rem; }

/* ── Misc Utilities ───────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.w-full { width: 100%; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.25s; z-index: 200; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 20px 16px; }
  .studio-panel { width: 100%; max-width: none; border-left: none; border-top: 1px solid var(--border); }
  .studio-layout { flex-direction: column; }
}
