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

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-card: #1a1a1a;
  --bg-card-hover: #222222;
  --bg-input: #1e1e1e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-glow: rgba(139, 92, 246, 0.3);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --border: #2a2a2a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* Light Theme */
.light-theme {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f3f5;
  --bg-input: #f1f3f5;
  --text-primary: #1a1a1a;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --accent-glow: rgba(139, 92, 246, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

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

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 20px 100px;
  position: relative;
}

.hidden { display: none !important; }

/* === Hero / Search (Google-style) === */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 12vh;
  transition: padding-top 0.3s ease;
}

.hero.compact {
  padding-top: 16px;
}

.profile {
  text-align: center;
  margin-bottom: 28px;
}

.avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #ec4899);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 32px;
  color: white;
  overflow: hidden;
  border: 3px solid var(--border);
  transition: all 0.3s;
}

.hero.compact .avatar {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

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

.profile-name {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
  transition: font-size 0.3s;
}

.hero.compact .profile-name {
  font-size: 18px;
}

.profile-bio {
  color: var(--text-secondary);
  font-size: 15px;
  transition: all 0.3s;
}

.hero.compact .profile-bio {
  font-size: 13px;
  margin-bottom: 0;
}

.hero.compact .social-icons {
  display: none;
}

/* === Search Box (Google-style) === */
.search-box {
  width: 100%;
  max-width: 580px;
  margin: 0 auto;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 16px;
  color: var(--text-muted);
  font-size: 18px;
  pointer-events: none;
  z-index: 1;
}

#search-input {
  width: 100%;
  padding: 14px 48px 14px 48px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: all 0.2s;
  -webkit-appearance: none;
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.2);
}

.search-clear {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 8px;
  display: flex;
  align-items: center;
}

.search-clear:hover { color: var(--text-primary); }

/* === Search Results === */
.search-results {
  margin-top: 20px;
}

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

.results-count {
  font-size: 13px;
  color: var(--text-muted);
}

.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  transition: background 0.2s;
}

.btn-back:hover {
  background: var(--bg-card);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
}

.result-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 32px rgba(139, 92, 246, 0.2);
}

.result-card-img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: var(--bg-secondary);
}

.result-card-info {
  padding: 10px;
}

.result-card-title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.result-card-code {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}

.result-card-views {
  font-size: 10px;
  color: var(--text-muted);
}

.result-card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 12px;
}

.results-loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* === Result Detail Modal === */
.result-detail-modal {
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.result-detail-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-detail-img {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}

.detail-code {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.detail-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.detail-meta span {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.detail-meta span i {
  margin-right: 4px;
}

.detail-categories {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.detail-categories span {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: 3px 8px;
  border-radius: 6px;
}

/* === Links Section === */
.links-section {
  margin-top: 24px;
}

.links-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.link-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: inherit;
  position: relative;
  overflow: hidden;
}

.link-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.1);
}

.link-card:active { transform: translateY(0); }

.link-image {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-secondary);
}

.link-image-placeholder {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #ec4899);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  color: white;
}

.link-content {
  flex: 1;
  min-width: 0;
}

.link-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.link-url {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-clicks {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.link-arrow {
  color: var(--text-muted);
  font-size: 16px;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.link-card:hover .link-arrow {
  transform: translateX(4px);
  color: var(--accent);
}

/* === Social Icons === */
.social-icons {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.social-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 16px;
  text-decoration: none;
  transition: all 0.2s;
}

.social-icon:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-2px);
}

/* === Section Divider === */
.section-divider {
  text-align: center;
  margin: 32px 0 20px;
  position: relative;
}

.section-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}

.section-divider span {
  position: relative;
  background: var(--bg-primary);
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.section-divider span i {
  color: var(--accent);
  margin-right: 6px;
}

/* === Drama Grid === */
.drama-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
}

.drama-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
}

.drama-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 32px rgba(139, 92, 246, 0.2);
}

.drama-card-img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: var(--bg-secondary);
}

.drama-card-img-placeholder {
  width: 100%;
  aspect-ratio: 2/3;
  background: linear-gradient(135deg, var(--accent), #ec4899);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: white;
}

.drama-card-info {
  padding: 8px;
}

.drama-card-title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.drama-card-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent);
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 16px;
  text-transform: uppercase;
}

/* === Drama Detail Modal === */
.drama-detail-modal {
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.drama-detail-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.drama-detail-img {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}

.drama-detail-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.drama-watch-btn {
  width: 100%;
  justify-content: center;
  padding: 14px;
  font-size: 15px;
  text-decoration: none;
}

/* === Footer === */
.footer {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.theme-toggle,
.qr-btn,
.admin-trigger {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.2s;
}

.theme-toggle:hover,
.qr-btn:hover,
.admin-trigger:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* === Click Counter === */
.link-clicks {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* === QR Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}

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

.modal-header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
}

.modal-header h3 i {
  color: var(--accent);
}

.qr-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.qr-content canvas {
  border-radius: 8px;
  background: white;
  padding: 14px;
}

/* === Buttons === */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.2s;
}

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

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* === Admin Panel === */
.admin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 100;
  overflow-y: auto;
  padding: 16px;
}

.admin-container {
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.admin-header h2 {
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-header h2 i { color: var(--accent); }

#login-section,
#dashboard-section {
  padding: 20px;
}

.admin-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.admin-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.admin-section h3 {
  font-size: 15px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.admin-section h3 i {
  color: var(--accent);
  font-size: 13px;
}

/* === Forms === */
.form-group {
  margin-bottom: 10px;
}

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

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group .btn-secondary { margin-top: 6px; }

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.image-preview { margin: 6px 0; }
.image-preview img {
  max-width: 180px;
  max-height: 100px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* === Spinner === */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* === Toast === */
.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  z-index: 200;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2s forwards;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* === Admin Link/Drama Items === */
.admin-link-item,
.admin-drama-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.admin-link-item img,
.admin-drama-item img {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg-secondary);
}

.admin-drama-item img {
  width: 32px;
  height: 46px;
  border-radius: 4px;
}

.admin-link-info,
.admin-drama-info {
  flex: 1;
  min-width: 0;
}

.admin-link-info .title,
.admin-drama-info .title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-link-info .url,
.admin-drama-info .link {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-link-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* === Social Admin Grid === */
.social-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.social-grid-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.social-grid-item i {
  width: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.social-grid-item input {
  flex: 1;
  padding: 5px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-primary);
  font-size: 12px;
  min-width: 0;
}

.social-grid-item input:focus {
  outline: none;
  border-color: var(--accent);
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 40px;
  margin-bottom: 12px;
  display: block;
}

.empty-state p { font-size: 14px; }

/* === Responsive === */
@media (max-width: 480px) {
  .container { padding: 12px 12px 80px; }

  .hero { padding-top: 8vh; }
  .hero.compact { padding-top: 12px; }

  .avatar { width: 64px; height: 64px; font-size: 26px; }
  .hero.compact .avatar { width: 36px; height: 36px; font-size: 14px; }

  .profile-name { font-size: 22px; }
  .hero.compact .profile-name { font-size: 16px; }

  #search-input {
    padding: 12px 40px 12px 40px;
    font-size: 15px;
    border-radius: 20px;
  }

  .results-grid,
  .drama-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
  }

  .result-card-info,
  .drama-card-info { padding: 8px; }

  .result-card-title,
  .drama-card-title { font-size: 11px; }

  .link-card { padding: 12px; gap: 10px; }
  .link-image, .link-image-placeholder { width: 48px; height: 48px; font-size: 18px; }
  .link-title { font-size: 14px; }

  .modal-overlay { padding: 12px; }
  .modal-box { padding: 16px; }

  .footer { bottom: 12px; right: 12px; gap: 6px; }
  .theme-toggle, .qr-btn, .admin-trigger { width: 38px; height: 38px; font-size: 14px; }

  .admin-overlay { padding: 8px; }
  #login-section, #dashboard-section { padding: 16px; }

  .social-grid { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
  .results-grid,
  .drama-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}
