:root {
  color-scheme: light;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111827;
  --page-bg: #eceef1;
  --accent-color: #000000;
  --bg-from: #a1a1a1;
  --bg-to: #a1a1a1;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: linear-gradient(180deg, var(--bg-from) 0%, var(--bg-to) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 40px 16px;
  min-height: 100vh;
}

.page-shell {
  width: min(100%, 580px);
}

/* Central Linktree Card Container */
.profile-shell {
  position: relative;
  background: var(--page-bg);
  border-radius: 36px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
  padding: 32px 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Custom Cover Banner */
.profile-cover {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 180px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 1;
}

/* Header bar inside the profile card */
.top-bar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: #ffffff;
  border-radius: 50%;
  color: #000000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.linktree-logo {
  width: 22px;
  height: 22px;
}

.share-wrap {
  display: flex;
  align-items: center;
}

.share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: #ffffff;
  border: none;
  border-radius: 50%;
  color: #000000;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: background 0.2s, transform 0.1s;
}

.share-btn:hover {
  background: #f3f4f6;
  transform: scale(1.05);
}

.share-btn svg {
  width: 18px;
  height: 18px;
}

/* Profile Info */
.profile-card {
  position: relative;
  z-index: 2;
  max-width: 100%;
  margin: 100px auto 24px;
  text-align: center;
}

.profile-avatar {
  width: 116px;
  height: 116px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid var(--page-bg);
  background-size: cover;
  background-position: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.profile-card h1 {
  margin: 16px 0 8px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.profile-subtitle {
  margin: 16px auto 24px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.6;
  text-align: justify;
  text-align-last: center;
  max-width: 500px;
  padding: 18px 22px;
  background: var(--app-bg);
  border: 1px solid var(--app-border);
  border-radius: 16px;
  box-shadow: 0 4px 16px var(--app-shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.profile-subtitle strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Social Row */
.social-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin-top: 16px;
}

.social-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--social-color);
  text-decoration: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.social-icon:hover {
  transform: scale(1.15);
  opacity: 0.75;
}

.social-icon svg {
  width: 34px;
  height: 34px;
}

/* Links Grid (Phone Home Screen Style) */
.links-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px 16px;
  margin-top: 24px;
  padding: 0 8px;
}

@media (max-width: 480px) {
  .links-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 18px 12px;
  }
}

.app-icon-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease;
  cursor: pointer;
}

.app-icon-card:hover {
  transform: translateY(-4px) scale(1.03);
}

.app-icon-image-wrapper {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 15px; /* Squircle radius */
  background: var(--app-bg);
  box-shadow: 0 8px 16px var(--app-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  border: 1px solid var(--app-border);
}

.app-icon-card:hover .app-icon-image-wrapper {
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1), 0 4px 8px rgba(0, 0, 0, 0.06);
}

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

.dark-invert {
  filter: invert(1) brightness(1.8);
}

.app-icon-glyph {
  font-size: 26px;
  color: var(--text-primary);
  transition: color 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-icon-card:hover .app-icon-glyph {
  color: var(--accent-color);
}

.app-icon-title {
  margin-top: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  width: 100%;
  word-wrap: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* max 2 lines */
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

/* Shared form and admin styles */
.auth-container,
.admin-container {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.auth-card {
  width: 100%;
  max-width: 480px;
  background: #ffffff;
  border-radius: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  padding: 36px;
}

.admin-card {
  width: 100%;
  max-width: 1000px;
  background: #ffffff;
  border-radius: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  padding: 40px;
}

.auth-card h1,
.admin-card h1 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 1.8rem;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.03em;
}

.auth-subtitle,
.admin-subtitle {
  color: #4b5563;
  margin-top: 0;
  margin-bottom: 24px;
  font-size: 0.95rem;
}

.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  color: #374151;
}

input,
textarea,
select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  padding: 12px 16px;
  font: inherit;
  color: #1f2937;
  background-color: #f9fafb;
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #3b82f6;
  background-color: #ffffff;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

/* Color Pickers Grid styling */
.color-pickers-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  background: #f9fafb;
}

.color-picker-wrapper input[type="color"] {
  width: 44px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

.color-hex-label {
  font-family: monospace;
  font-size: 0.9rem;
  font-weight: 600;
  color: #4b5563;
}

/* Button & Action styling */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 12px 24px;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s;
}

.primary-btn {
  background: #111827;
  color: #ffffff;
}

.primary-btn:hover {
  background: #1f2937;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn-primary {
  background: #2563eb;
  color: #ffffff;
  margin-top: 0;
}

.btn-primary:hover {
  background: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.button.secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #e5e7eb;
}

.button.secondary:hover {
  background: #e5e7eb;
  color: #1f2937;
}

.logout-btn {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.logout-btn:hover {
  background: #fca5a5;
  color: #991b1b;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
}

.form-actions button {
  margin-top: 0;
  flex: 1;
}

.form-actions a {
  flex: 1;
}

.admin-sub-actions {
  margin-bottom: 24px;
}

.alert {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  font-weight: 500;
  font-size: 0.9rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 48px 24px;
  border: 2px dashed #e5e7eb;
  border-radius: 16px;
  color: #6b7280;
  background: #f9fafb;
}

.empty-state strong {
  font-size: 1.1rem;
  color: #111827;
}

/* Table styling */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background: #ffffff;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: #f9fafb;
}

thead th {
  text-align: left;
  color: #4b5563;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

tbody tr {
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.15s;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background-color: #f9fafb;
}

td {
  padding: 16px 20px;
  vertical-align: middle;
}

.preview-td {
  padding-right: 0;
}

.table-preview-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  font-weight: 700;
  color: #4b5563;
}

.table-preview-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.title-td {
  min-width: 160px;
}

.link-title-text {
  display: block;
  font-weight: 600;
  color: #111827;
  font-size: 0.95rem;
}

.link-note-text {
  display: block;
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 3px;
}

.url-td {
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-url-link {
  color: #2563eb;
  font-size: 0.9rem;
  text-decoration: none;
  font-weight: 500;
}

.admin-url-link:hover {
  text-decoration: underline;
}

.order-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 9999px;
  background: #f3f4f6;
  color: #374151;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid #e5e7eb;
}

.actions-td {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity 0.2s, background-color 0.2s;
}

.btn-edit {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.btn-edit:hover {
  background: #dbeafe;
}

.btn-delete {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.btn-delete:hover {
  background: #fca5a5;
}

.inline-form {
  display: inline-block;
}

/* Login specific styling */
.login-header-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #111827;
  margin-bottom: 16px;
}

/* Media Queries for Admin */
@media (max-width: 768px) {
  .admin-card {
    padding: 24px 16px;
  }

  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .admin-actions {
    width: 100%;
    justify-content: space-between;
  }

  .color-pickers-grid {
    grid-template-columns: 1fr;
  }

  .actions-td {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .btn-action {
    justify-content: center;
    width: 100%;
  }
}

/* Profile Footer */
.profile-footer {
  margin-top: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--app-border);
  background: var(--app-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.theme-toggle-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.05);
}

.theme-toggle-btn svg {
  display: block;
}

/* Light / Dark toggle icon state visibility */
.theme-toggle-btn .sun-icon {
  display: none;
}
.theme-toggle-btn .moon-icon {
  display: block;
}

/* Default Dark Theme toggle state */
html.default-dark .theme-toggle-btn .sun-icon {
  display: block;
}
html.default-dark .theme-toggle-btn .moon-icon {
  display: none;
}

/* Override preferences */
html.theme-dark {
  --page-bg: #101726 !important;
  --bg-from: #0b132b !important;
  --bg-to: #1c2541 !important;
  --text-primary: #ffffff !important;
  --text-secondary: #94a3b8 !important;
  --app-bg: rgba(255, 255, 255, 0.08) !important;
  --app-border: rgba(255, 255, 255, 0.12) !important;
  --app-shadow: rgba(0, 0, 0, 0.2) !important;
  --social-color: #ffffff !important;
}
html.theme-dark .app-icon-img.dark-invert,
html.theme-dark .app-icon-img.svg-icon {
  filter: invert(1) brightness(1.8) !important;
}
html.theme-dark .theme-toggle-btn .sun-icon {
  display: block !important;
}
html.theme-dark .theme-toggle-btn .moon-icon {
  display: none !important;
}

html.theme-light {
  --page-bg: #ffffff !important;
  --bg-from: #eceef1 !important;
  --bg-to: #d1d5db !important;
  --text-primary: #111827 !important;
  --text-secondary: #4b5563 !important;
  --app-bg: #ffffff !important;
  --app-border: rgba(0, 0, 0, 0.04) !important;
  --app-shadow: rgba(0, 0, 0, 0.03) !important;
  --social-color: #111827 !important;
}
html.theme-light .app-icon-img.dark-invert,
html.theme-light .app-icon-img.svg-icon {
  filter: none !important;
}
html.theme-light .theme-toggle-btn .sun-icon {
  display: none !important;
}
html.theme-light .theme-toggle-btn .moon-icon {
  display: block !important;
}

.admin-login-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s ease;
  padding: 6px 14px;
  border-radius: 9999px;
  background: var(--app-bg);
  border: 1px solid var(--app-border);
}

.admin-login-link:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.15);
}

@media (max-width: 600px) {
  body {
    padding: 16px 8px;
  }
}

@media (max-width: 480px) {
  body {
    padding: 16px 8px;
  }
  
  .profile-shell {
    border-radius: 28px;
    padding: 24px 16px;
  }

  .profile-cover {
    height: 170px;
  }

  .profile-card {
    margin: 96px auto 20px;
  }

  .profile-avatar {
    width: 100px;
    height: 100px;
  }

  .links-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px 8px;
    padding: 0;
  }

  .app-icon-image-wrapper {
    width: 52px;
    height: 52px;
    border-radius: 12px;
  }

  .app-icon-glyph {
    font-size: 22px;
  }

  .app-icon-title {
    font-size: 0.74rem;
    margin-top: 6px;
  }

  .social-row {
    gap: 14px;
    margin-top: 12px;
  }

  .social-icon {
    width: 34px;
    height: 34px;
  }

  .social-icon svg {
    width: 28px;
    height: 28px;
  }

  .social-icon i {
    font-size: 28px !important;
  }
}

/* Floating Alert Toast */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 400px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.05);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
  opacity: 0;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toast-content {
  flex-grow: 1;
}

.toast-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #111827;
}

.toast-desc {
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 2px;
}

.toast-close {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.toast-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #4b5563;
}

/* Dark theme style adaptations */
html.theme-dark .toast {
  background: #1f2937;
  border-color: #374151;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

html.theme-dark .toast-title {
  color: #ffffff;
}

html.theme-dark .toast-desc {
  color: #9ca3af;
}

html.theme-dark .toast-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #e5e7eb;
}