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

:root {
  --bg: #f5f5f7;
  --surface: #fff;
  --border: #e0e0e0;
  --text: #1d1d1f;
  --text-secondary: #86868b;
  --primary: #007aff;
  --primary-hover: #0056cc;
  --danger: #ff3b30;
  --danger-hover: #cc2f26;
  --success: #34c759;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Auth Gate */
#auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-card h1 {
  font-size: 24px;
  margin-bottom: 24px;
  text-align: center;
}

.auth-card label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.auth-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.15s;
}

.auth-card input:focus {
  border-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

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

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

.btn-cancel {
  background: var(--bg);
  color: var(--text);
}

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

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

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.btn-icon:hover { opacity: 1; }
.btn-icon-danger:hover { color: var(--danger); }

/* Layout */
#main-app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

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

.sidebar-header h2 {
  font-size: 16px;
}

.sidebar-header .btn {
  font-size: 20px;
  padding: 4px 10px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  line-height: 1;
}

#pack-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Pack items */
.pack-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.pack-item:hover { background: var(--bg); }
.pack-item.selected { background: #e8f0fe; }
.pack-item.dragging { opacity: 0.4; }

.pack-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pack-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pack-icon-placeholder {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
}

.pack-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pack-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pack-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  width: fit-content;
}

.pack-badge.free { background: #e8f5e9; color: #2e7d32; }
.pack-badge.paid { background: #fff3e0; color: #e65100; }

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

.pack-item:hover .pack-actions { opacity: 1; }

/* Main panel */
.main-panel {
  padding: 24px;
  overflow-y: auto;
}

.sticker-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.sticker-header h2 { font-size: 20px; }

.sticker-count {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 12px;
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 20px;
  color: var(--text-secondary);
}

.drop-zone:hover,
.drop-zone.drag-active {
  border-color: var(--primary);
  background: #f0f7ff;
}

/* Sticker grid */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.sticker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: grab;
  transition: box-shadow 0.15s;
}

.sticker-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.sticker-card.dragging { opacity: 0.4; }

.sticker-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #fafafa;
  padding: 8px;
}

.sticker-card-info {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
}

.sticker-name {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sticker-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

/* Empty state */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-secondary);
  font-size: 15px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.15s;
}

.modal-overlay.show { opacity: 1; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

.modal p {
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-form label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.modal-form input[type="text"],
.modal-form input:not([type]) {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  margin-top: 4px;
  outline: none;
}

.modal-form input:focus {
  border-color: var(--primary);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  flex-direction: row !important;
}

.checkbox-label input[type="checkbox"] {
  width: auto !important;
  margin: 0 !important;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Toast */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  transform: translateX(120%);
  transition: transform 0.3s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.toast.show { transform: translateX(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
