/* PhilCard - Modern One-Page Links Site */

:root {
  --bg1: #0f1724;
  --bg2: #071027;
  --card: #0b1220cc;
  --muted: rgba(255, 255, 255, 0.65);
  --glass: rgba(255, 255, 255, 0.04);
  --accent: #7c3aed;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.6);
  --maxw: 880px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: radial-gradient(1200px 600px at 10% 10%, rgba(124, 58, 237, 0.12), transparent),
              radial-gradient(1000px 500px at 90% 90%, rgba(14, 165, 233, 0.06), transparent),
              linear-gradient(180deg, var(--bg1), var(--bg2));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: #fff;
}

.wrap {
  width: 100%;
  max-width: var(--maxw);
}

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

/* Header Styles */
header {
  display: flex;
  gap: 20px;
  align-items: center;
  position: relative;
}

.avatar {
  width: 84px;
  height: 84px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #06b6d4);
  flex: 0 0 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 28px;
  color: white;
  box-shadow: 0 6px 18px rgba(12, 18, 30, 0.5);
  overflow: hidden;
  position: relative;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

.profile-controls {
  margin-left: auto;
}

.profile-controls .icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
  padding: 8px;
  border-radius: 8px;
}

.meta {
  flex: 1;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

p.lead {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* Links Grid */
.links {
  margin-top: 26px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.link-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(255, 255, 255, 0.03);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  min-width: 0; /* Allow shrinking */
}

.link-item:hover {
  transform: translateY(-6px);
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.6);
}

.link-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 0;
}

.icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 44px;
  color: rgba(255, 255, 255, 0.8);
  transition: color 0.2s ease;
  position: relative;
}

.icon-wrap svg {
  transition: transform 0.2s ease, filter 0.2s ease;
  filter: drop-shadow(0 0 0 rgba(255, 255, 255, 0));
}

.link-item:hover .icon-wrap {
  color: white;
}

.link-item:hover .icon-wrap svg {
  transform: scale(1.15);
  /* Brand color glow will be applied dynamically via JavaScript */
}

.label {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Controls */
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
}

.btn {
  padding: 8px 12px;
  border-radius: 10px;
  border: 0;
  background: linear-gradient(90deg, #ffffff10, #ffffff05);
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s ease;
}

.btn:hover {
  background: linear-gradient(90deg, #ffffff15, #ffffff08);
}

.btn.primary {
  background: linear-gradient(90deg, var(--accent), #06b6d4);
  color: white;
}

.btn.primary:hover {
  background: linear-gradient(90deg, #8b5cf6, #0891b2);
}

/* Floating Add Button */
.floating-add {
  position: fixed;
  right: 28px;
  bottom: 28px;
  background: var(--accent);
  border-radius: 999px;
  padding: 14px;
  box-shadow: 0 8px 30px rgba(124, 58, 237, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.floating-add:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 40px rgba(124, 58, 237, 0.35);
}

/* Modal Styles */
.modal-back,
.auth-modal-back {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 28px;
  backdrop-filter: blur(4px);
}

.modal {
  width: 100%;
  max-width: 720px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
  padding: 20px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  box-shadow: 0 20px 60px rgba(2, 6, 23, 0.8);
}

.modal h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

/* Form Styles */
.form-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.form-row .col {
  flex: 1;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="text"],
input[type="url"],
select {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: transparent;
  color: white;
  font-size: 14px;
  transition: border-color 0.2s ease;
}

input[type="text"]:focus,
input[type="url"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  width: 100%;
  min-height: 90px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: transparent;
  color: white;
  resize: vertical;
}

/* Utility Classes */
.small {
  font-size: 13px;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.mini {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pill {
  background: var(--glass);
  padding: 6px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

.link-controls {
  display: none; /* Hidden by default */
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.2s ease, color 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

/* Drag and Drop Styles */
.drag-handle {
  color: var(--muted);
  cursor: grab;
  padding: 4px 6px;
  margin-right: 6px;
  font-size: 14px;
  line-height: 1;
  transition: color 0.2s ease, transform 0.2s ease, background 0.2s ease;
  user-select: none;
  display: none; /* Hidden by default */
  align-items: center;
  border-radius: 4px;
  flex-shrink: 0;
}

.drag-handle:hover {
  color: white;
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.1);
}

.drag-handle:active {
  cursor: grabbing;
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.2);
}

.sortable-container {
  position: relative;
  min-height: 60px; /* Ensures there's always a drop zone */
}

.link-item.dragging {
  opacity: 0.6;
  transform: rotate(2deg) scale(1.02);
  box-shadow: 0 15px 40px rgba(2, 6, 23, 0.8);
  z-index: 1000;
  position: relative;
  border-color: var(--accent);
  pointer-events: none; /* Prevent interference with drop detection */
}

.link-item.drag-over {
  transform: translateY(-4px) scale(1.02);
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(124, 58, 237, 0.15), rgba(124, 58, 237, 0.08));
  box-shadow: 0 8px 25px rgba(124, 58, 237, 0.3);
}

.links.drag-active .link-item:not(.dragging) {
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.links.drag-active .link-item:not(.dragging):not(.drag-over) {
  opacity: 0.7;
}

/* Drop zone indicators */
.links.drag-active .link-item:not(.dragging)::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.links.drag-active .link-item:not(.dragging):hover::before {
  opacity: 0.6;
}

/* Footer */
footer {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-right {
  position: relative;
  cursor: pointer;
}

.copyright {
  transition: opacity 0.3s ease;
}

.footer-right:hover .copyright {
  opacity: 0;
}

.footer-right .admin-btn {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.3s ease;
  font-size: 11px;
  padding: 4px 8px;
  white-space: nowrap;
}

.footer-right:hover .admin-btn {
  opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  body {
    padding: 24px;
  }
  
  .card {
    padding: 24px;
  }
  
  .avatar {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    font-size: 24px;
  }
  
  header {
    flex-direction: row;
  }
  
  .links {
    grid-template-columns: 1fr;
  }
  
  .floating-add {
    right: 20px;
    bottom: 20px;
  }
  
  .modal {
    margin: 20px;
    max-width: none;
  }
  
  .form-row {
    flex-direction: column;
  }
}

/* Image Cropper Styles */
.cropper-header {
  margin-bottom: 8px;
}

.cropper-header strong {
  display: block;
  color: #fff;
  margin-bottom: 4px;
}

.cropper-container {
  background: #1a1a1a;
  border-radius: 8px;
  padding: 8px;
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, 0.1);
  max-width: 100%;
  overflow: hidden;
}

.cropper-container img {
  display: block;
  max-width: 100%;
  height: auto;
}

.crop-overlay {
  position: absolute;
  pointer-events: none;
}

.crop-box {
  position: absolute;
  border: 2px solid #007bff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  pointer-events: all;
  cursor: move;
  user-select: none;
}

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid #007bff;
  border-radius: 50%;
  pointer-events: all;
}

.crop-handle-nw {
  top: -6px;
  left: -6px;
  cursor: nw-resize;
}

.crop-handle-ne {
  top: -6px;
  right: -6px;
  cursor: ne-resize;
}

.crop-handle-sw {
  bottom: -6px;
  left: -6px;
  cursor: sw-resize;
}

.crop-handle-se {
  bottom: -6px;
  right: -6px;
  cursor: se-resize;
}

.cropper-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.cropper-actions .btn {
  padding: 8px 16px;
  font-size: 14px;
}

/* Smooth transitions for cropper */
.crop-box {
  transition: none;
}

.crop-box:not(.dragging):not(.resizing) {
  transition: all 0.1s ease;
}

/* Mobile-friendly cropper styles */
@media (max-width: 500px) {
  .cropper-container {
    max-width: 100%;
  }
  
  .crop-handle {
    width: 16px;
    height: 16px;
  }
  
  .crop-handle-nw {
    top: -8px;
    left: -8px;
  }
  
  .crop-handle-ne {
    top: -8px;
    right: -8px;
  }
  
  .crop-handle-sw {
    bottom: -8px;
    left: -8px;
  }
  
  .crop-handle-se {
    bottom: -8px;
    right: -8px;
  }
  
  .cropper-actions {
    flex-direction: column;
  }
  
  .cropper-actions .btn {
    width: 100%;
  }
}
