@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700;900&display=swap');

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-hover: #f9fafb;
  --input-bg: #ffffff;
  --panel-bg: #fafafa;
  --hover-tint: #fff5e6;
  --text: #111827;
  --muted: #5a6c7d;
  --border: #e5e7eb;
  --primary: #f37832;
  --primary-dark: #e6581a;
  --brand-dark: #2c3e50;
  --brand-dark-2: #34495e;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
  --flash-success-bg: #ecfdf5;
  --flash-success-text: #047857;
  --flash-success-border: #a7f3d0;
  --flash-error-bg: #fef2f2;
  --flash-error-text: #b91c1c;
  --flash-error-border: #fecaca;

  /* Public profile page text/overlay contrast (light mode = dark text) */
  --profile-text: #16233a;
  --profile-text-muted: #4b5768;
  --profile-text-soft: #33415a;
  --profile-text-faint: rgba(22, 35, 58, 0.55);
  --profile-overlay-bg: rgba(17, 24, 39, 0.08);
  --profile-overlay-bg-hover: rgba(17, 24, 39, 0.15);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #1a1d23;
    --surface-hover: #20242c;
    --input-bg: #12151a;
    --panel-bg: #12151a;
    --hover-tint: rgba(243, 120, 50, 0.15);
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #2d323c;
    --flash-success-bg: rgba(22, 163, 74, 0.15);
    --flash-success-text: #4ade80;
    --flash-success-border: rgba(74, 222, 128, 0.3);
    --flash-error-bg: rgba(220, 38, 38, 0.15);
    --flash-error-text: #f87171;
    --flash-error-border: rgba(248, 113, 113, 0.3);
    --profile-text: #ffffff;
    --profile-text-muted: rgba(255, 255, 255, 0.75);
    --profile-text-soft: rgba(255, 255, 255, 0.9);
    --profile-text-faint: rgba(255, 255, 255, 0.5);
    --profile-overlay-bg: rgba(255, 255, 255, 0.15);
    --profile-overlay-bg-hover: rgba(255, 255, 255, 0.25);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #1a1d23;
  --surface-hover: #20242c;
  --input-bg: #12151a;
  --panel-bg: #12151a;
  --hover-tint: rgba(243, 120, 50, 0.15);
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #2d323c;
  --flash-success-bg: rgba(22, 163, 74, 0.15);
  --flash-success-text: #4ade80;
  --flash-success-border: rgba(74, 222, 128, 0.3);
  --flash-error-bg: rgba(220, 38, 38, 0.15);
  --flash-error-text: #f87171;
  --flash-error-border: rgba(248, 113, 113, 0.3);
  --profile-text: #ffffff;
  --profile-text-muted: rgba(255, 255, 255, 0.75);
  --profile-text-soft: rgba(255, 255, 255, 0.9);
  --profile-text-faint: rgba(255, 255, 255, 0.5);
  --profile-overlay-bg: rgba(255, 255, 255, 0.15);
  --profile-overlay-bg-hover: rgba(255, 255, 255, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; }

/* ---------- Visitor/admin theme toggle button ---------- */

.page-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  /* Stays on the right even when there is no logo to its left. */
  margin-left: auto;
}

.lang-switcher {
  display: flex;
  gap: 2px;
  background: var(--profile-overlay-bg);
  border-radius: 999px;
  padding: 3px;
  backdrop-filter: blur(4px);
}

.lang-switcher-btn {
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--profile-text);
  text-decoration: none;
  opacity: 0.7;
}

.lang-switcher-btn:hover { opacity: 1; }

.lang-switcher-btn.active {
  background: var(--primary);
  color: #fff;
  opacity: 1;
}

.theme-toggle-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--profile-overlay-bg);
  color: var(--profile-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.theme-toggle-btn:hover { background: var(--profile-overlay-bg-hover); }

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

/* ---------- Public profile page ---------- */

.profile-page-body {
  background: var(--profile-bg-light);
}

:root[data-theme="dark"] .profile-page-body {
  background: var(--profile-bg-dark);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .profile-page-body {
    background: var(--profile-bg-dark);
  }
}

.profile-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 20px 16px 64px;
}

.profile-card {
  width: 100%;
  max-width: 480px;
  text-align: center;
}

/* Logo left, language/theme controls right. Lives inside .profile-card, so on
   wide screens it is held to the same 480px column as the link buttons rather
   than stretching to the edges of the viewport. */
.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

/* The uploaded image exactly as it is — no circular crop, border or tinted
   backing. Width is a share of the header set in Settings (--logo-width, set
   inline on .profile-header); height follows the image's own proportions.
   min-width: 0 lets it shrink rather than overlap the controls if a wide
   setting doesn't fit beside them on a narrow screen. */
.profile-logo {
  display: block;
  width: var(--logo-width, 30%);
  height: auto;
  min-width: 0;
}

.profile-name {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--profile-text);
}

.profile-username {
  color: var(--profile-text-muted);
  margin: 0 0 8px;
  font-size: 14px;
}

.profile-bio {
  color: var(--profile-text-soft);
  margin: 0 0 28px;
  font-size: 15px;
  line-height: 1.5;
}

.link-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.link-button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.12s ease;
}

.link-button:hover { transform: translateY(-2px); }

.link-button .icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.link-button .icon svg { width: 100%; height: 100%; }

.link-button .icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.link-button .label {
  flex: 1;
  text-align: center;
}

.shape-rounded { border-radius: 10px; }
.shape-pill { border-radius: 999px; }
.shape-square { border-radius: 0; }

summary.link-button {
  cursor: pointer;
  list-style: none;
}

summary.link-button::-webkit-details-marker { display: none; }
summary.link-button::marker { display: none; content: ""; }

.details-chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

details[open] > summary .details-chevron { transform: rotate(180deg); }

.link-sublist {
  margin-top: 10px;
  padding-left: 22px;
  border-left: 2px dashed var(--profile-text-faint);
}

.link-button.featured {
  box-shadow: 0 0 0 3px var(--primary), 0 4px 14px rgba(0, 0, 0, 0.25);
  transform: scale(1.02);
}

.link-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 2), 1fr);
  gap: 14px;
}

.link-grid-card {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.12s ease;
}

.link-grid.single-column .link-grid-card {
  aspect-ratio: 3 / 1;
}

.link-grid-card:hover { transform: translateY(-2px); }

.link-grid-card.featured {
  box-shadow: 0 0 0 3px var(--primary), 0 4px 14px rgba(0, 0, 0, 0.25);
}

.link-grid-card .icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.link-grid-card .icon svg { width: 100%; height: 100%; }

.link-grid-card .icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.link-grid-card .grid-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.link-grid-card .grid-label {
  position: relative;
  z-index: 1;
}

.link-grid-card .grid-label-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px 10px 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
  color: #fff;
  text-align: left;
  font-size: 13px;
}

.social-icons-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 0 0 24px;
}

.social-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.12s ease;
}

.social-icon-btn:hover { transform: translateY(-2px); }

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

.social-icon-btn img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.link-button .lock-badge {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}

.link-grid-card .lock-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 16px;
  height: 16px;
  padding: 3px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  box-sizing: content-box;
}

.social-icon-btn { position: relative; }

.social-icon-btn svg.lock-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  padding: 2px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  box-sizing: content-box;
}

.empty-state {
  color: var(--profile-text-muted);
  margin-top: 40px;
  font-size: 14px;
}

.profile-footer {
  margin-top: 40px;
  font-size: 12px;
  color: var(--profile-text-faint);
}

/* ---------- Auth pages ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.auth-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.auth-card .subtitle {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 24px;
}

/* ---------- Avatar cropper ---------- */

.avatar-cropper-wrap {
  display: none;
  gap: 20px;
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-bg);
  flex-wrap: wrap;
}

.avatar-cropper-wrap.active { display: flex; }

.avatar-cropper-stage {
  width: 280px;
  max-width: 100%;
  height: 280px;
  background: #111827;
  overflow: hidden;
  border-radius: 8px;
}

.avatar-cropper-stage img { display: block; max-width: 100%; }

.avatar-cropper-side {
  display: flex;
  flex-direction: column;
  width: 140px;
}

.avatar-crop-preview {
  display: block;
  max-width: 100%;
  max-height: 96px;
  border: 2px solid var(--border);
  background: var(--bg);
}

.grid-image-crop-preview {
  width: 100%;
  max-width: 140px;
  max-height: 140px;
  border-radius: 8px;
  object-fit: contain;
  border: 2px solid var(--border);
  background: var(--bg);
}

/* ---------- Forms ---------- */

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="search"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}

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

input[type="color"] {
  width: 56px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
}

.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="text"] { flex: 1; }

.radio-group, .shape-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.radio-group label, .shape-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  background: var(--primary);
  color: #fff;
}

.btn:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--flash-error-bg); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon { padding: 6px 9px; }

/* ---------- Dashboard shell ---------- */

.dash-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.dash-header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.brand { font-weight: 800; font-size: 16px; }

.dash-nav { display: flex; gap: 4px; align-items: center; }

.dash-nav a {
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.dash-nav a.active, .dash-nav a:hover { background: var(--hover-tint); color: var(--primary); }

.dash-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title h1 { font-size: 20px; margin: 0; }
.page-title p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ---------- Flashes ---------- */

.flash {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 500;
}

.flash-success { background: var(--flash-success-bg); color: var(--flash-success-text); border: 1px solid var(--flash-success-border); }
.flash-error { background: var(--flash-error-bg); color: var(--flash-error-text); border: 1px solid var(--flash-error-border); }

/* ---------- Link rows ---------- */

.link-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.link-row:last-child { border-bottom: none; }

.link-row.dragging { opacity: 0.4; }

.group-children {
  margin-left: 34px;
  padding-left: 14px;
  border-left: 2px dashed var(--border);
  min-height: 8px;
}

.group-children:empty::before {
  content: "Drag a link here to nest it";
  display: block;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0;
}

.drag-handle {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--muted);
  cursor: grab;
}

.drag-handle:active { cursor: grabbing; }

.drag-handle svg { width: 100%; height: 100%; }

.link-row .icon-preview {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.link-row .icon-preview svg { width: 20px; height: 20px; }
.link-row .icon-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }

.link-row .meta { flex: 1; min-width: 0; }
.link-row .meta .label { font-weight: 600; font-size: 14px; }
.link-row .meta .url { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row.inactive { opacity: 0.5; }

.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 8px;
  max-width: 520px;
  max-height: 260px;
  overflow-y: auto;
  padding: 2px;
}

#icon-search-input { max-width: 520px; }

#icon-search-empty { grid-column: 1 / -1; padding: 12px 0; }

.icon-picker-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.icon-picker-btn svg { width: 20px; height: 20px; }

.icon-picker-btn:hover { border-color: var(--primary); color: var(--primary); }

.icon-picker-btn.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.link-row .actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--hover-tint);
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------- Sharing / dashboard extras ---------- */

.section-heading { font-size: 15px; margin: 0 0 12px; }

.qr-card-body { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }

.badge-featured { background: var(--primary); color: #fff; }
.badge-danger { background: var(--flash-error-bg); color: var(--flash-error-text); }

/* ---------- Stats / analytics ---------- */

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 24px; }

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-box .value { font-size: 26px; font-weight: 800; }
.stat-box .label { color: var(--muted); font-size: 12px; margin-top: 2px; }

.chart-tabs { display: flex; gap: 6px; margin-bottom: 12px; }

.chart-tabs button {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.chart-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; font-size: 13px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.search-form { display: flex; gap: 8px; margin: 0 0 16px; }
.search-form input { flex: 1; }

.pagination { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 16px; margin-top: 16px; }
.pagination-status { color: var(--muted); font-size: 13px; }

.pagination-jump { display: flex; align-items: center; gap: 6px; }
.pagination-jump label { font-size: 12px; color: var(--muted); }
.pagination-jump input[type="number"] { width: 64px; padding: 6px 8px; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 480px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog .hint { margin: 0 0 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

th a { color: inherit; text-decoration: none; }
th a:hover { color: var(--text); }

.section-spacer { height: 24px; }

.empty-hint { color: var(--muted); font-size: 14px; padding: 20px 0; text-align: center; }

@media (max-width: 600px) {
  .two-col { grid-template-columns: 1fr; }
  .dash-nav { gap: 0; }
  .dash-nav a { padding: 8px; font-size: 13px; }
  .link-grid { grid-template-columns: repeat(min(2, var(--grid-cols, 2)), 1fr); }
}
