/* ============================================
   Instagram Clone — Global Styles
   Dark theme with glassmorphism + gradient accents
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* --- CSS Variables --- */
:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #111111;
  --bg-card: rgba(24, 24, 27, 0.85);
  --bg-card-hover: rgba(32, 32, 36, 0.9);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-input: rgba(255, 255, 255, 0.06);
  --bg-input-focus: rgba(255, 255, 255, 0.1);

  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --text-link: #818cf8;

  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(129, 140, 248, 0.5);

  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  --gradient-accent: linear-gradient(135deg, #f093fb 0%, #f5576c 50%, #fda085 100%);
  --gradient-instagram: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);

  --color-like: #ef4444;
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-info: #818cf8;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(129, 140, 248, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  --max-width: 480px;
  --nav-height: 60px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Ambient background glow */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 20%, rgba(102, 126, 234, 0.05) 0%, transparent 50%),
              radial-gradient(circle at 70% 80%, rgba(240, 147, 251, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: #a5b4fc;
}

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

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

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

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Navigation Bar (Bottom on mobile, Top on desktop)
   ============================================ */
.navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 16px;
  z-index: 1000;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}

.nav-item.active {
  color: var(--text-primary);
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gradient-instagram);
}

.nav-icon {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.nav-label {
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ============================================
   Page Layout
   ============================================ */
.page-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
  padding-bottom: calc(var(--nav-height) + 24px);
  min-height: 100vh;
}

.page-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 10, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--gradient-instagram);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ============================================
   Auth Pages (Login / Signup)
   ============================================ */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: fadeInUp 0.6s ease;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 2.2rem;
  font-weight: 700;
  background: var(--gradient-instagram);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.auth-logo p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 8px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-footer {
  text-align: center;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ============================================
   Form Elements
   ============================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-input {
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.938rem;
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:focus {
  background: var(--bg-input-focus);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.1);
}

.form-input::placeholder {
  color: var(--text-muted);
}

textarea.form-input {
  resize: vertical;
  min-height: 80px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.938rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), 0 0 20px rgba(129, 140, 248, 0.3);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-input-focus);
  border-color: var(--border-focus);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

.btn-follow {
  padding: 8px 20px;
  font-size: 0.813rem;
  border-radius: var(--radius-sm);
}

.btn-full {
  width: 100%;
}

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

/* Loading spinner inside buttons */
.btn .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ============================================
   Post Card
   ============================================ */
.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  animation: fadeInUp 0.5s ease;
}

.post-card:hover {
  box-shadow: var(--shadow-md);
}

.post-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}

.post-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid transparent;
  background-image: var(--gradient-instagram);
  background-origin: border-box;
  background-clip: content-box, border-box;
  cursor: pointer;
}

.post-username {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
}

.post-username:hover {
  color: var(--text-link);
}

.post-time {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.post-image-container {
  position: relative;
  width: 100%;
  background: var(--bg-secondary);
}

.post-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.post-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px 8px;
}

.post-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 4px;
  transition: all var(--transition-fast);
}

.post-action-btn:hover {
  color: var(--text-primary);
}

.post-action-btn.liked {
  color: var(--color-like);
}

.post-action-btn.liked .heart-icon {
  fill: var(--color-like);
  animation: heartBounce 0.4s ease;
}

.post-action-icon {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  transition: transform var(--transition-fast);
}

.post-action-btn:hover .post-action-icon {
  transform: scale(1.15);
}

.post-likes {
  padding: 0 16px;
  font-size: 0.875rem;
  font-weight: 600;
}

.post-caption {
  padding: 8px 16px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.post-caption .caption-username {
  font-weight: 600;
  margin-right: 6px;
}

.post-comments-preview {
  padding: 4px 16px 14px;
}

.post-comments-link {
  font-size: 0.813rem;
  color: var(--text-muted);
  cursor: pointer;
}

.post-comments-link:hover {
  color: var(--text-secondary);
}

/* ============================================
   Profile Page
   ============================================ */
.profile-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 24px 0;
}

.profile-avatar {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid transparent;
  background-image: var(--gradient-instagram);
  background-origin: border-box;
  background-clip: content-box, border-box;
  flex-shrink: 0;
}

.profile-info {
  flex: 1;
  min-width: 0;
}

.profile-username {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.profile-stats {
  display: flex;
  gap: 24px;
  margin-top: 12px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.profile-bio {
  padding: 0 0 16px;
}

.profile-fullname {
  font-weight: 600;
  font-size: 0.875rem;
}

.profile-bio-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.profile-actions {
  display: flex;
  gap: 8px;
  padding-bottom: 20px;
}

/* Profile Tabs */
.profile-tabs {
  display: flex;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 4px;
}

.profile-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.profile-tab:hover {
  color: var(--text-secondary);
  background: var(--bg-glass);
}

.profile-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}

.profile-tab svg {
  opacity: 0.7;
}

.profile-tab.active svg {
  opacity: 1;
}

.tab-content {
  min-height: 200px;
}

/* Modal large variant (for post detail) */
.modal-content-lg {
  max-width: 480px;
  max-height: 90vh;
}

/* Comment delete button inside modal */
.comment-delete-btn {
  margin-left: 12px;
  color: var(--color-error);
  cursor: pointer;
  font-size: 0.688rem;
  transition: opacity var(--transition-fast);
}

.comment-delete-btn:hover {
  opacity: 0.7;
}

/* Post Grid */
.post-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  border-top: 1px solid var(--border-color);
  padding-top: 3px;
}

.grid-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
}

.grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.grid-item:hover img {
  transform: scale(1.05);
  opacity: 0.7;
}

.grid-item-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity var(--transition-normal);
  color: white;
  font-size: 0.875rem;
  font-weight: 600;
}

.grid-item:hover .grid-item-overlay {
  opacity: 1;
}

.grid-stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============================================
   Create Post Page
   ============================================ */
.create-container {
  padding-top: 24px;
}

.image-upload-area {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  transition: all var(--transition-normal);
  overflow: hidden;
  margin-bottom: 20px;
  background: var(--bg-glass);
}

.image-upload-area:hover {
  border-color: var(--border-focus);
  background: rgba(129, 140, 248, 0.05);
}

.image-upload-area.has-image {
  border: none;
}

.image-upload-area .upload-icon {
  width: 48px;
  height: 48px;
  stroke: var(--text-muted);
  stroke-width: 1.5;
  fill: none;
}

.image-upload-area .upload-text {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.image-upload-area .upload-subtext {
  color: var(--text-muted);
  font-size: 0.75rem;
  opacity: 0.7;
}

.image-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}

.image-upload-input {
  display: none;
}

/* ============================================
   Single Post / Comments
   ============================================ */
.comment-list {
  padding: 16px 0;
}

.comment-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  animation: fadeIn 0.3s ease;
}

.comment-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.comment-body {
  flex: 1;
  min-width: 0;
}

.comment-username {
  font-weight: 600;
  font-size: 0.813rem;
  margin-right: 6px;
}

.comment-text {
  font-size: 0.875rem;
  line-height: 1.4;
  word-break: break-word;
}

.comment-time {
  font-size: 0.688rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.comment-form {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid var(--border-color);
  position: sticky;
  bottom: var(--nav-height);
  background: var(--bg-primary);
}

.comment-input {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: all var(--transition-fast);
}

.comment-input:focus {
  border-color: var(--border-focus);
  background: var(--bg-input-focus);
}

.comment-submit {
  background: none;
  border: none;
  color: var(--text-link);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0 8px;
  transition: opacity var(--transition-fast);
}

.comment-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================
   Loading & Empty States
   ============================================ */
.loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-color);
  border-top-color: var(--text-link);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  stroke: var(--text-muted);
  stroke-width: 1;
  fill: none;
  margin: 0 auto 16px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: 0.875rem;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: all var(--transition-normal);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  white-space: nowrap;
}

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

.toast-success {
  background: rgba(34, 197, 94, 0.2);
  color: var(--color-success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.toast-error {
  background: rgba(239, 68, 68, 0.2);
  color: var(--color-error);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.toast-info {
  background: rgba(129, 140, 248, 0.2);
  color: var(--color-info);
  border: 1px solid rgba(129, 140, 248, 0.3);
}

/* ============================================
   User List Items (Followers, Following)
   ============================================ */
.user-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.user-list-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
}

.user-list-info {
  flex: 1;
  min-width: 0;
}

.user-list-name {
  font-weight: 600;
  font-size: 0.875rem;
}

.user-list-fullname {
  font-size: 0.813rem;
  color: var(--text-secondary);
}

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  animation: fadeInUp 0.3s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

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

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes heartBounce {
  0% { transform: scale(1); }
  25% { transform: scale(1.3); }
  50% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}

/* Skeleton loading placeholder */
.skeleton {
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--bg-input-focus) 50%, var(--bg-input) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: var(--radius-sm);
}

.skeleton-circle {
  border-radius: 50%;
}

/* ============================================
   Responsive (larger screens)
   ============================================ */
@media (min-width: 768px) {
  :root {
    --max-width: 520px;
  }

  .navbar {
    top: 0;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--border-color);
    max-width: var(--max-width);
    left: 50%;
    transform: translateX(-50%);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }

  .page-container {
    padding-top: calc(var(--nav-height) + 24px);
    padding-bottom: 24px;
  }

  .page-header {
    top: var(--nav-height);
  }
}
