/* Mobile-First Upload Page CSS */

/* CSS Variables for Mobile-First Design */
:root {
  --primary-color: #1DA1F2;
  --secondary-color: #657786;
  --accent-color: #FF6B6B;
  --success-color: #1DB954;
  --warning-color: #FFB020;
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f1f3f4;
  --bg-overlay: rgba(0, 0, 0, 0.5);
  --text-primary: #14171a;
  --text-secondary: #536471;
  --text-muted: #8b98a5;
  --border-color: #e1e8ed;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 25px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.25);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 50px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --header-height: 60px;
  --safe-area-top: env(safe-area-inset-top);
  --safe-area-bottom: env(safe-area-inset-bottom);
}

/* Dark Mode Variables */
.dark {
  --bg-primary: #000000;
  --bg-secondary: #16181c;
  --bg-tertiary: #1e2328;
  --bg-overlay: rgba(0, 0, 0, 0.8);
  --text-primary: #ffffff;
  --text-secondary: #8b98a5;
  --text-muted: #6e767d;
  --border-color: #2f3336;
  --shadow-sm: 0 1px 3px rgba(255, 255, 255, 0.1);
  --shadow-md: 0 4px 12px rgba(255, 255, 255, 0.15);
  --shadow-lg: 0 8px 25px rgba(255, 255, 255, 0.2);
}

/* Global Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 16px;
  overflow-x: hidden;
  padding-top: calc(var(--header-height) + var(--safe-area-top));
  padding-bottom: var(--safe-area-bottom);
  min-height: 100vh;
  transition: var(--transition);
}

/* Mobile Header */
.view-header {
  position: fixed;
  top: var(--safe-area-top);
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-left,
.header-right {
  min-width: 44px;
  display: flex;
  align-items: center;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.back-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-lg);
  transition: var(--transition);
  color: var(--text-primary);
}

.back-btn:active {
  background: var(--bg-secondary);
  transform: scale(0.95);
}

.back-btn a {
  color: inherit;
  text-decoration: none;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 28px;
  width: auto;
}

/* Main Content */
main {
  padding: 0 16px;
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Upload Form Container */
.upload-form {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 24px 20px;
  margin: 16px 0;
  box-shadow: var(--shadow-sm);
  position: relative;
}

/* Form Labels */
.upload-form label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  margin-top: 20px;
}

.upload-form label:first-of-type {
  margin-top: 0;
}

/* Form Inputs */
.upload-form input[type="text"],
.upload-form input[type="url"], /* Added type="url" style */
.upload-form textarea {
  width: 100%;
  padding: 16px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
  transition: var(--transition);
  font-family: inherit;
  resize: vertical;
}

.upload-form input[type="text"]:focus,
.upload-form input[type="url"]:focus, /* Added type="url" focus style */
.upload-form textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  background: var(--bg-primary);
  box-shadow: 0 0 0 3px rgba(29, 161, 242, 0.1);
}

.upload-form input[type="text"]::placeholder,
.upload-form input[type="url"]::placeholder, /* Added type="url" placeholder style */
.upload-form textarea::placeholder {
  color: var(--text-muted);
}

/* File Input Wrapper */
.file-input-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  transition: var(--transition);
  cursor: pointer;
  margin-bottom: 16px;
}

.file-input-wrapper:hover {
  border-color: var(--primary-color);
  background: var(--bg-tertiary);
}

.file-input-wrapper input[type="file"] {
  display: none;
}

.file-input-wrapper label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background: var(--primary-color);
  color: white;
  border-radius: var(--radius-full);
  font-size: 20px;
  cursor: pointer;
  transition: var(--transition);
  margin: 0;
}

.file-input-wrapper label:active {
  transform: scale(0.95);
  background: #1a91da;
}

.file-input-wrapper p {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  margin: 0;
}

/* Image Preview */
#imgPreview {
  margin: 16px 0;
  text-align: center;
}

#imgPreview img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 2px solid var(--border-color);
}

/* Link Fields Section */
.link-fields {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 20px 0;
  border: 1px solid var(--border-color);
}

.link-input-group {
  margin-bottom: 16px;
}

.link-input-group:last-of-type {
  margin-bottom: 20px;
}

.link-input-group label {
  margin-top: 0;
  margin-bottom: 8px;
}

#addLinkBtn {
  width: 100%;
  padding: 12px 16px;
  background: var(--success-color);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}

#addLinkBtn:active {
  background: #1aa34a;
  transform: scale(0.98);
}

/* Links Container */
#linksContainer {
  margin: 16px 0;
}

.link-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
  font-size: 14px;
}

.link-item span {
  flex: 1;
  color: var(--text-primary);
  word-break: break-all;
}

.link-item a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
}

.link-item a:active {
  color: #1a91da;
}

.remove-link-btn {
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 16px;
  font-weight: bold;
  margin-left: 12px;
  flex-shrink: 0;
}

.remove-link-btn:active {
  background: #e55555;
  transform: scale(0.95);
}

/* Upload Button */
.up-btn {
  margin-top: 24px;
  text-align: center;
}

.up-btn button {
  width: 100%;
  padding: 18px 20px;
  background: linear-gradient(135deg, var(--primary-color) 0%, #1a91da 100%);
  color: white;
  border: none;
  border-radius: var(--radius-xl);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  position: relative;
  overflow: hidden;
}

.up-btn button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.1), transparent 50%);
  pointer-events: none;
}

.up-btn button:active {
  transform: scale(0.98);
  background: linear-gradient(135deg, #1a91da 0%, #1681c2 100%);
}

.up-btn button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.up-btn button i {
  font-size: 18px;
}

/* Loader Overlay */
.loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-overlay);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.loader-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid var(--primary-color);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loader-overlay p {
  color: white;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
}

/* Mobile Notification */
.app-notification {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: #fff;
  padding: 12px 45px 12px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  display: flex;
  align-items: center;
  min-width: 250px;
  max-width: 90%;
  opacity: 1;
  transition: opacity 0.4s ease, bottom 0.4s ease;
}

.app-notification.hide {
  opacity: 0;
  bottom: -100px;
  pointer-events: none;
}

/* Notification Types */
.app-notification.success { background-color: var(--success-color); }
.app-notification.error   { background-color: var(--accent-color); }
.app-notification.info    { background-color: var(--primary-color); }
.app-notification.warning { background-color: var(--warning-color); }

#notification-message {
  flex-grow: 1;
  font-size: 14px;
  margin-right: 10px;
}

.notification-close-btn {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 5px;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.notification-close-btn:active {
  opacity: 1;
}

/* Textarea Specific Styling */
#contentText {
  /* min-height: 200px; -- Adjusted in HTML to 15 rows */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', monospace;
  line-height: 1.6;
}

/* Responsive Design */
@media (min-width: 768px) {
  main {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 20px;
  }
  
  .upload-form {
    padding: 32px 28px;
  }
  
  .link-fields {
    padding: 24px;
  }
}

/* Safe Area Adjustments for iOS */
@supports (padding: max(0px)) {
  .view-header {
    padding-top: max(12px, var(--safe-area-top));
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles */
button:focus,
a:focus,
input:focus,
textarea:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
  }
  
  .dark {
    --border-color: #ffffff;
  }
}

/* Hide default file input styling */
input[type="file"] {
  opacity: 0;
  position: absolute;
  z-index: -1;
}

/* Loading States */
.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Utility Classes */
.hide {
  display: none !important;
}

.text-center {
  text-align: center;
}

/* NEW: Styles for the Formatting Toolbar */
#formattingToolbar {
    position: absolute; /* Position relative to the nearest positioned ancestor (usually body) */
    background-color: var(--card-bg, #ffffff); /* Use a theme variable */
    border: 1px solid var(--border-color, #ccc);
    border-radius: 8px;
    padding: 6px; /* Adjusted padding */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 100; /* Ensure it's above other content */
    display: flex; /* Arrange buttons in a row */
    gap: 3px; /* Reduced space between buttons */
    flex-wrap: wrap; /* Allow wrapping if many buttons */
    visibility: hidden; /* Start hidden */
    opacity: 0;
    transition: opacity 0.15s ease, visibility 0.15s ease; /* Faster transition */
    /* Remove transform for initial simpler positioning */
}

 #formattingToolbar.visible {
     visibility: visible;
     opacity: 1;
     /* transform: translateY(0); Remove if not using initial transform */
 }

#formattingToolbar button {
    background: none; /* Buttons within toolbar have no background */
    border: none;
    padding: 5px 7px; /* Adjusted padding */
    cursor: pointer;
    font-size: 0.9em; /* Adjusted icon size */
    color: var(--text-secondary, #555); /* Default color */
    border-radius: 4px;
    transition: background-color 0.1s ease, color 0.1s ease;
    min-width: auto; /* Override default button min-width */
    line-height: 1; /* Ensure proper icon alignment */
    display: flex;
    align-items: center;
    justify-content: center;
}

 #formattingToolbar button i {
     /* Ensure icons are sized correctly relative to button font-size */
     font-size: 1em;
 }


#formattingToolbar button:hover:not(:disabled) {
    background-color: var(--bg-secondary, #f0f0f0); /* Subtle hover effect */
    color: var(--primary-color, #007bff); /* Highlight on hover */
}

#formattingToolbar button:active:not(:disabled) {
    background-color: var(--bg-tertiary, #e0e0e0);
    transform: scale(0.95);
}

#formattingToolbar button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Specific styles for color buttons */
#formattingToolbar button.color-red { color: #e74c3c; }
#formattingToolbar button.color-green { color: #2ecc71; }
#formattingToolbar button.color-blue { color: #3498db; }

/* Optional: Style for active button (e.g., bold is ON) - requires JS to manage state */
#formattingToolbar button.active {
    background-color: var(--bg-secondary, #f0f0f0);
    color: var(--primary-color, #007bff);
    font-weight: bold; /* Example */
}

