/* ============================================
   SHARE LINKS — Main Stylesheet
   Centralized, Mobile-first, Premium UI
   ============================================ */

/* ---- 1. CSS RESET & BASE ---- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

img, svg, canvas {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---- 2. CUSTOM PROPERTIES (THEMING) ---- */
:root,
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-tertiary: #efefef;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-input: #f3f4f6;
  --bg-hover: #f0f0f0;
  --bg-overlay: rgba(0, 0, 0, 0.5);

  --text-primary: #0a0a0a;
  --text-secondary: #52525b;
  --text-tertiary: #a1a1aa;
  --text-inverse: #ffffff;
  --text-on-accent: #ffffff;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --accent-subtle: #eff6ff;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fee2e2;

  --success: #16a34a;
  --success-light: #dcfce7;

  --warning: #f59e0b;
  --warning-light: #fef3c7;

  --border: #e4e4e7;
  --border-light: #f0f0f0;
  --border-focus: var(--accent);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 16px 50px rgba(0, 0, 0, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --nav-height: 64px;
  --header-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme="dark"] {
  --bg-primary: #09090b;
  --bg-secondary: #18181b;
  --bg-tertiary: #27272a;
  --bg-card: #18181b;
  --bg-elevated: #1e1e22;
  --bg-input: #27272a;
  --bg-hover: #2a2a2e;
  --bg-overlay: rgba(0, 0, 0, 0.7);

  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --text-inverse: #0a0a0a;
  --text-on-accent: #ffffff;

  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-light: #1e3a5f;
  --accent-subtle: #172554;

  --danger: #ef4444;
  --danger-hover: #f87171;
  --danger-light: #451a1a;

  --success: #22c55e;
  --success-light: #14532d;

  --warning: #fbbf24;
  --warning-light: #451a03;

  --border: #27272a;
  --border-light: #1e1e22;
  --border-focus: var(--accent);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 16px 50px rgba(0, 0, 0, 0.6);
}

/* ---- 3. TYPOGRAPHY ---- */
h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
h2 { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; }
h3 { font-size: 1.125rem; font-weight: 600; line-height: 1.4; }
h4 { font-size: 1rem; font-weight: 600; line-height: 1.4; }
p { color: var(--text-secondary); }

/* ---- 4. SCREENS ---- */
.screen {
  display: none;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ---- 5. SPLASH & ONBOARDING ---- */
#screen-splash, #screen-onboarding {
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}
.splash-container, .onboarding-container {
  text-align: center;
  padding: 2rem;
  max-width: 400px;
  margin: 0 auto;
}
.splash-logo { color: var(--accent); margin-bottom: 1.25rem; display: inline-block; }
.splash-title { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.25rem; }
.splash-tagline { font-size: 0.875rem; color: var(--text-tertiary); margin-bottom: 2rem; }
.splash-loader { width: 120px; height: 3px; background: var(--bg-tertiary); border-radius: var(--radius-full); margin: 0 auto; overflow: hidden; }
.loader-bar { width: 40%; height: 100%; background: var(--accent); border-radius: var(--radius-full); animation: loaderSlide 1.2s ease-in-out infinite; }
@keyframes loaderSlide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

.onboarding-step { display: none; }
.onboarding-step.active { display: block; animation: fadeUp 0.4s ease; }
.onboarding-icon { font-size: 3.5rem; margin-bottom: 1.25rem; }
.onboarding-step p { font-size: 0.9375rem; margin-bottom: 2rem; }
.onboarding-dots { display: flex; gap: 8px; justify-content: center; margin-bottom: 2rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: all 0.3s ease; }
.dot.active { background: var(--accent); width: 24px; border-radius: var(--radius-full); }

/* ---- 6. AUTH SCREENS ---- */
.auth-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 85vh;
}
.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-links { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; margin-top: 1.25rem; }

/* ---- 7. APP SHELL ---- */
#app-shell { display: none; flex-direction: column; min-height: 100dvh; background: var(--bg-secondary); }
#app-shell.active { display: flex; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 1rem;
  padding-top: var(--safe-top);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.header-title { font-size: 1.125rem; font-weight: 700; text-align: center; flex: 1; }
.header-left, .header-right { width: 80px; display: flex; align-items: center; }
.header-right { justify-content: flex-end; gap: 0.25rem; }

/* Main Content Container (Centered on all screens) */
.app-main {
  flex: 1;
  padding: 1.25rem 1rem;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 1.5rem);
  overflow-y: auto;
  max-width: 700px; /* Constrains the entire app content */
  margin: 0 auto;
  width: 100%;
}
.view { display: none; animation: fadeIn 0.25s ease; width: 100%; }
.view.active { display: block; }

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: var(--nav-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-primary);
  border-top: 1px solid var(--border-light);
  max-width: 700px;
  margin: 0 auto;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 0.375rem 0.75rem; color: var(--text-tertiary); font-size: 0.625rem;
  font-weight: 500; transition: color 0.2s ease; -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--accent); }
.nav-btn-center {
  position: relative; top: -12px; background: var(--accent); color: var(--text-on-accent) !important;
  width: 56px; height: 56px; border-radius: 50%; justify-content: center; padding: 0;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
}
.nav-btn-center span { display: none; }

/* ---- 8. DASHBOARD (Centralized) ---- */
.dashboard-hero {
  text-align: center; /* Centralized Greeting */
  padding: 1rem 0 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hero-greeting { font-size: 1.625rem; font-weight: 800; letter-spacing: -0.02em; }
.hero-subtitle { font-size: 0.9375rem; margin-top: 0.25rem; }

.btn-quick-share {
  width: 100%;
  max-width: 320px; /* Restrict width, perfectly centered */
  margin: 0 auto 2rem auto;
  padding: 1rem;
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  box-shadow: var(--shadow-md);
}

.section { margin-bottom: 2rem; }
.section-header {
  display: flex; align-items: center; justify-content: center; /* Centered headers */
  gap: 0.5rem; margin-bottom: 1rem; text-align: center;
}
.section-title { font-size: 1rem; font-weight: 700; margin: 0; }
.section-count { font-size: 0.75rem; font-weight: 600; background: var(--bg-tertiary); padding: 0.125rem 0.5rem; border-radius: var(--radius-full); }

/* Horizontal Scroll for Favorites */
.advert-scroll {
  display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 0.5rem;
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
}
.advert-scroll::-webkit-scrollbar { display: none; }
.advert-scroll .advert-card {
  min-width: 150px; max-width: 160px; flex-shrink: 0;
}

/* ---- 9. ADVERT CARDS & GRID (Mobile First) ---- */
.adverts-grid {
  display: grid;
  grid-template-columns: 1fr; /* ONE COLUMN ON MOBILE (Big, tap-friendly) */
  gap: 1.25rem;
}
.advert-card {
  background: var(--bg-card); border-radius: var(--radius-lg); overflow: hidden;
  border: 1px solid var(--border-light); transition: transform 0.2s ease;
  scroll-snap-align: start; position: relative; box-shadow: var(--shadow-sm);
}
.advert-card:active { transform: scale(0.98); }
.advert-card-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--bg-tertiary); }
.advert-scroll .advert-card-thumb { aspect-ratio: 1 / 1; }

.advert-card-body { padding: 1rem; text-align: center; /* Centered card text */ }
.advert-card-title { font-size: 1rem; font-weight: 700; margin-bottom: 0.25rem; }
.advert-card-desc { font-size: 0.8125rem; margin-bottom: 0.5rem; }
.advert-card-meta { font-size: 0.6875rem; color: var(--text-tertiary); }

.advert-card-actions { display: flex; justify-content: center; gap: 0.5rem; margin-top: 1rem; }
.advert-card-actions .btn { flex: 1; padding: 0.5rem; font-size: 0.75rem; border-radius: var(--radius-sm); }

.advert-card-fav, .advert-card-status { position: absolute; backdrop-filter: blur(4px); color: white; }
.advert-card-fav { top: 0.5rem; right: 0.5rem; width: 32px; height: 32px; border-radius: 50%; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; font-size: 1rem; }
.advert-card-fav.active { color: #f59e0b; }
.advert-card-status { top: 0.5rem; left: 0.5rem; font-size: 0.625rem; font-weight: 700; text-transform: uppercase; padding: 0.25rem 0.5rem; border-radius: var(--radius-full); background: rgba(0, 0, 0, 0.5); }
.advert-card-status.draft { background: var(--warning); color: #000; }
.advert-card-status.active { background: var(--success); }

/* ---- 10. FORMS (Centered) ---- */
.advert-form {
  display: flex; flex-direction: column; gap: 1.25rem;
  max-width: 500px; margin: 0 auto; width: 100%; /* Perfectly centered */
}
.form-group { display: flex; flex-direction: column; gap: 0.375rem; }
.form-group label { font-size: 0.8125rem; font-weight: 600; text-align: left; }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 150px; }

/* Inputs */
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 0.875rem; background: var(--bg-input); border: 1.5px solid var(--border);
  border-radius: var(--radius-md); font-size: 0.9375rem; transition: border-color 0.2s ease; outline: none;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--border-focus); }
.form-group textarea { resize: vertical; min-height: 100px; }
.form-group select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 1rem center; }

.required { color: var(--danger); }
.form-error { font-size: 0.8125rem; color: var(--danger); background: var(--danger-light); padding: 0.75rem; border-radius: var(--radius-sm); text-align: center; }
.form-actions { display: flex; gap: 1rem; margin-top: 1rem; }
.form-actions .btn { flex: 1; border-radius: var(--radius-full); }

/* ---- 11. UPLOAD ZONE ---- */
.upload-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.5rem; padding: 2.5rem 1rem; border: 2px dashed var(--border);
  border-radius: var(--radius-lg); color: var(--text-tertiary); cursor: pointer; text-align: center;
}
.upload-zone:active { background: var(--accent-subtle); border-color: var(--accent); }
.image-preview-list { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; justify-content: center; }
.image-preview-item { position: relative; width: 80px; height: 80px; border-radius: var(--radius-sm); border: 2px solid var(--border); overflow: hidden; }
.image-preview-item.primary { border-color: var(--accent); }
.image-preview-item img { width: 100%; height: 100%; object-fit: cover; }
.image-preview-remove { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; background: rgba(0,0,0,0.6); color: white; border-radius: 50%; font-size: 0.625rem; display: flex; align-items: center; justify-content: center; }

/* ---- 12. COMPOSER (Centralized flow) ---- */
.composer-header {
  display: flex; align-items: center; justify-content: center; position: relative; margin-bottom: 2rem;
}
.composer-header .btn-icon { position: absolute; left: 0; }
.composer-header h2 { margin: 0; font-size: 1.125rem; }

.composer-step { max-width: 500px; margin: 0 auto; display: none; flex-direction: column; align-items: center; width: 100%; }
.composer-step.active { display: flex; animation: fadeUp 0.3s ease; }

.step-label { font-size: 0.75rem; text-transform: uppercase; color: var(--text-tertiary); letter-spacing: 0.05em; margin-bottom: 1.5rem; text-align: center; }

.composer-advert-list { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; margin-bottom: 1.5rem; }
.composer-advert-item { display: flex; align-items: center; gap: 1rem; padding: 1rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); cursor: pointer; }
.composer-advert-item img { width: 56px; height: 56px; border-radius: var(--radius-sm); object-fit: cover; }
.composer-advert-item-info h4 { font-size: 0.9375rem; margin: 0; }

.platform-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; width: 100%; }
.platform-btn { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 1.25rem 0.5rem; background: var(--bg-card); border: 2px solid var(--border); border-radius: var(--radius-lg); font-weight: 600; }
.platform-btn.selected { border-color: var(--accent); background: var(--accent-subtle); color: var(--accent); }
.platform-icon { font-size: 1.75rem; }

.preview-container { background: var(--bg-tertiary); border-radius: var(--radius-lg); padding: 1rem; display: flex; justify-content: center; width: 100%; margin-bottom: 1.5rem; }
.preview-canvas { max-width: 100%; max-height: 50vh; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); }

.bg-option-group { display: flex; justify-content: center; gap: 0.5rem; width: 100%; margin-bottom: 1.5rem; flex-wrap: wrap; }
.bg-opt { font-size: 0.75rem; font-weight: 600; padding: 0.5rem 1rem; border-radius: var(--radius-full); background: var(--bg-tertiary); }
.bg-opt.active { background: var(--accent); color: var(--text-on-accent); }

.url-display { font-size: 0.875rem; color: var(--accent); padding: 0.75rem; background: var(--bg-input); border-radius: var(--radius-sm); text-align: center; word-break: break-all; width: 100%; }

.share-actions { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; margin-top: 1.5rem; }
.share-actions .btn { border-radius: var(--radius-full); padding: 1rem; }

/* ---- 13. SETTINGS & HISTORY ---- */
.history-list { display: flex; flex-direction: column; gap: 0.75rem; max-width: 500px; margin: 0 auto; }
.history-item { display: flex; align-items: center; gap: 1rem; padding: 1rem; background: var(--bg-card); border-radius: var(--radius-md); border: 1px solid var(--border-light); }

.settings-group { max-width: 500px; margin: 0 auto 1.5rem; background: var(--bg-card); padding: 1.25rem; border-radius: var(--radius-lg); border: 1px solid var(--border-light); }
.settings-group h4 { text-align: center; color: var(--text-tertiary); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; margin-bottom: 1rem; }

/* ---- 14. BUTTONS ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.75rem 1.5rem; font-weight: 600; border-radius: var(--radius-md); font-size: 0.9375rem; transition: transform 0.15s ease; user-select: none; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-danger { background: var(--danger); color: white; }
.btn-full { width: 100%; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.8125rem; }
.btn-icon { width: 44px; height: 44px; border-radius: var(--radius-full); display: inline-flex; justify-content: center; align-items: center; font-size: 1.25rem; }

/* ---- 15. DIALOGS & TOASTS ---- */
.dialog-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; background: var(--bg-overlay); padding: 1rem; backdrop-filter: blur(4px); }
.dialog-box { background: var(--bg-elevated); border-radius: var(--radius-xl); padding: 2rem; width: 100%; max-width: 340px; text-align: center; box-shadow: var(--shadow-xl); }
.dialog-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }

.toast-container { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 0.5rem; width: 90%; max-width: 400px; pointer-events: none; }
.toast { background: var(--bg-elevated); color: var(--text-primary); padding: 1rem; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); font-size: 0.875rem; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 0.5rem; text-align: center; pointer-events: auto; }

/* ---- 16. EMPTY STATES ---- */
.empty-state { text-align: center; padding: 4rem 1rem; display: flex; flex-direction: column; align-items: center; max-width: 400px; margin: 0 auto; }
.empty-icon { font-size: 4rem; margin-bottom: 1rem; }
.empty-state p { margin-bottom: 1.5rem; font-size: 0.9375rem; }

/* ---- 17. UTILITIES & ANIMATIONS ---- */
.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ---- 18. RESPONSIVE ADJUSTMENTS ---- */
@media (min-width: 600px) {
  .adverts-grid { grid-template-columns: repeat(2, 1fr); }
  .platform-grid { grid-template-columns: repeat(4, 1fr); }
  .app-main { padding: 2rem; }
}
@media (min-width: 900px) {
  .adverts-grid { grid-template-columns: repeat(3, 1fr); }
}

@supports (padding: env(safe-area-inset-bottom)) {
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
  .app-header { padding-top: env(safe-area-inset-top); }
}