/* ============================================================
   MAIN STYLESHEET
   Social Media Content Creator — Gomathi & Mana Kodi
   ============================================================ */

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--surface-1);
  color: var(--ui-text);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  outline: none;
}

img { max-width: 100%; display: block; }

/* ---------- App Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--panel-width);
  grid-template-rows: var(--header-height) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Header ---------- */
.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface-0);
  border-bottom: 1px solid var(--ui-border);
  z-index: 100;
}

.app-header__left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-header__logo {
  font-weight: 800;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--brand-primary);
}

.app-header__logo svg {
  width: 24px;
  height: 24px;
}

.app-header__divider {
  width: 1px;
  height: 28px;
  background: var(--ui-border);
}

.app-header__center {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header__right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Brand selector */
.brand-selector {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}

.brand-selector__btn {
  padding: 6px 18px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all var(--transition-fast);
  color: var(--ui-text-secondary);
  white-space: nowrap;
}

.brand-selector__btn.active {
  background: var(--surface-0);
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

.brand-selector__btn:hover:not(.active) {
  color: var(--ui-text);
}

/* Platform selector */
.platform-select {
  padding: 6px 12px;
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  background: var(--surface-0);
  font-size: 0.85rem;
  color: var(--ui-text);
  cursor: pointer;
}

.platform-select:focus {
  border-color: var(--ui-border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

/* ---------- Sidebar (Template Gallery) ---------- */
.sidebar {
  grid-row: 2;
  grid-column: 1;
  background: var(--surface-0);
  border-right: 1px solid var(--ui-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar__header {
  padding: 16px;
  border-bottom: 1px solid var(--ui-border);
}

.sidebar__title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 10px;
}

/* Template filters */
.filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--ui-text-secondary);
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.filter-chip:hover {
  background: var(--surface-3);
  color: var(--ui-text);
}

.filter-chip.active {
  background: var(--brand-primary);
  color: white;
  border-color: var(--brand-primary);
}

/* Template gallery grid */
.template-gallery {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.template-gallery::-webkit-scrollbar {
  width: 6px;
}
.template-gallery::-webkit-scrollbar-track {
  background: transparent;
}
.template-gallery::-webkit-scrollbar-thumb {
  background: var(--ui-border);
  border-radius: var(--radius-full);
}

.template-card {
  border: 2px solid var(--ui-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--surface-1);
}

.template-card:hover {
  border-color: var(--brand-accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.template-card.active {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(139,105,20,0.15);
}

.template-card__preview {
  aspect-ratio: 1;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.template-card__preview canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.template-card__preview-placeholder {
  font-size: 2rem;
  opacity: 0.3;
}

.template-card__badge {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.template-card__badge--poster {
  background: #dbeafe;
  color: #1d4ed8;
}

.template-card__badge--video {
  background: #fce7f3;
  color: #be185d;
}

.template-card__info {
  padding: 8px 10px;
}

.template-card__name {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ui-text);
}

.template-card__category {
  font-size: 0.68rem;
  color: var(--ui-text-tertiary);
  margin-top: 2px;
}

/* ---------- Main Canvas Area ---------- */
.canvas-area {
  grid-row: 2;
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface-1);
  padding: 20px;
  position: relative;
  overflow: auto;
}

.canvas-container {
  position: relative;
  background: white;
  box-shadow: var(--shadow-xl);
  border-radius: 4px;
  overflow: hidden;
  /* Will be scaled to fit */
}

.canvas-container canvas {
  display: block;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-0);
  padding: 8px 16px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--ui-border);
  z-index: 50;
}

.canvas-toolbar__btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  color: var(--ui-text-secondary);
  font-size: 1.1rem;
}

.canvas-toolbar__btn:hover {
  background: var(--surface-2);
  color: var(--ui-text);
}

.canvas-toolbar__btn.active {
  background: var(--brand-primary);
  color: white;
}

.canvas-toolbar__divider {
  width: 1px;
  height: 24px;
  background: var(--ui-border);
}

.canvas-size-label {
  font-size: 0.75rem;
  color: var(--ui-text-tertiary);
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-0);
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ui-border);
}

/* ---------- Video Controls ---------- */
.video-controls {
  display: none;
  align-items: center;
  gap: 8px;
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-0);
  padding: 8px 16px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--ui-border);
  z-index: 50;
}

.video-controls.visible {
  display: flex;
}

.video-controls__btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all var(--transition-fast);
  font-size: 1.1rem;
}

.video-controls__btn--play {
  background: var(--brand-primary);
  color: white;
}

.video-controls__btn--play:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.video-controls__btn--record {
  background: var(--ui-error);
  color: white;
}

.video-controls__btn--record:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.video-controls__btn--record.recording {
  animation: pulse-record 1s ease-in-out infinite;
}

@keyframes pulse-record {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.video-progress {
  width: 120px;
  height: 4px;
  background: var(--surface-3);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.video-progress__bar {
  height: 100%;
  background: var(--brand-primary);
  border-radius: var(--radius-full);
  width: 0%;
  transition: width 100ms linear;
}

/* ---------- Right Panel (Properties) ---------- */
.property-panel {
  grid-row: 2;
  grid-column: 3;
  background: var(--surface-0);
  border-left: 1px solid var(--ui-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.panel-section__title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ui-text-secondary);
  margin-bottom: 12px;
}

.panel-section__content {
  overflow-y: auto;
  flex: 1;
  padding: 16px;
}

/* Product selector */
.product-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  background: var(--surface-0);
  font-size: 0.85rem;
  cursor: pointer;
}

.product-select:focus {
  border-color: var(--ui-border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

/* Form controls */
.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ui-text-secondary);
  margin-bottom: 4px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  background: var(--surface-0);
  transition: border-color var(--transition-fast);
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--ui-border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.form-group input[type="range"] {
  width: 100%;
  accent-color: var(--brand-primary);
}

.form-group input[type="color"] {
  width: 40px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  background: var(--surface-0);
  cursor: pointer;
}

.form-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.form-row .form-group {
  flex: 1;
}

/* Text align buttons */
.text-align-group {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.text-align-btn {
  width: 32px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--ui-text-secondary);
  transition: all var(--transition-fast);
}

.text-align-btn:hover { background: var(--surface-3); }
.text-align-btn.active {
  background: var(--surface-0);
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- Export Panel ---------- */
.export-section {
  padding: 16px;
  border-top: 1px solid var(--ui-border);
  margin-top: auto;
}

.export-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--brand-primary);
  color: white;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
}
.btn-secondary:hover {
  background: var(--surface-3);
}

.btn-success {
  background: var(--ui-success);
  color: white;
}
.btn-success:hover { opacity: 0.9; }

.btn-danger {
  background: var(--ui-error);
  color: white;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.78rem;
}

.btn-block {
  width: 100%;
}

/* Bulk export checkboxes */
.bulk-platforms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.bulk-platform-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--ui-text-secondary);
  cursor: pointer;
}

.bulk-platform-check input {
  accent-color: var(--brand-primary);
}

/* ---------- Custom Text Inputs ---------- */
.custom-texts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- Notification Toast ---------- */
.notification {
  position: fixed;
  top: 70px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 10000;
  transform: translateX(120%);
  transition: transform var(--transition-normal);
  box-shadow: var(--shadow-lg);
  max-width: 360px;
}

.notification.show {
  transform: translateX(0);
}

.notification--success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.notification--error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.notification--info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* ---------- Loading Overlay ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  flex-direction: column;
  gap: 16px;
}

.loading-overlay.visible {
  display: flex;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--surface-3);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ui-text-secondary);
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--ui-text-tertiary);
}

.empty-state__icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state__text {
  font-size: 0.9rem;
  font-weight: 500;
}

.empty-state__sub {
  font-size: 0.78rem;
  margin-top: 4px;
}

/* ---------- Scrollbar Styles ---------- */
.property-panel::-webkit-scrollbar,
.panel-section__content::-webkit-scrollbar {
  width: 6px;
}
.property-panel::-webkit-scrollbar-track,
.panel-section__content::-webkit-scrollbar-track {
  background: transparent;
}
.property-panel::-webkit-scrollbar-thumb,
.panel-section__content::-webkit-scrollbar-thumb {
  background: var(--ui-border);
  border-radius: var(--radius-full);
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .app {
    grid-template-columns: 260px 1fr 260px;
  }
  :root {
    --sidebar-width: 260px;
    --panel-width: 260px;
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-height) auto 1fr auto;
  }
  .sidebar {
    grid-column: 1;
    grid-row: 2;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--ui-border);
  }
  .template-gallery {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
  .canvas-area {
    grid-column: 1;
    grid-row: 3;
  }
  .property-panel {
    grid-column: 1;
    grid-row: 4;
    border-left: none;
    border-top: 1px solid var(--ui-border);
    max-height: 280px;
    overflow-y: auto;
  }
}

/* ---------- Element selected state in property panel ---------- */
.element-props-active .panel-section__title::after {
  content: ' • Editing';
  color: var(--brand-primary);
  font-weight: 600;
  text-transform: none;
}

/* ---------- No-select utility ---------- */
.no-select {
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Canvas cursor states ---------- */
.canvas-container.grabbing { cursor: grabbing; }
.canvas-container.grab { cursor: grab; }
.canvas-container canvas { cursor: crosshair; }
.canvas-container.dragging canvas { cursor: grabbing; }
