/* Linker List - Responsive Design */
:root {
  --primary: #8f5bb2;
  --primary-dark: #6f3fa3;
  --secondary: #0097b5;
  --border: #e5e3ea;
  --text: #222;
  --muted: #666;
  --bg: #f6f7fb;
  --card: #fff;
  --danger: #dc3545;
  --success: #28a745;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden; /* 가로 스크롤 방지 */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* iOS safe area */
body {
  padding-bottom: calc(60px + env(safe-area-inset-bottom)); /* 고정 푸터 겹침 방지 */
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: 60px; /* footer 공간 확보 */
}

/* Back Button */
.back-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  background: var(--card);
  color: var(--primary);
  padding: 10px 16px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 1000;
  transition: all .2s;
}
.back-btn:hover {
  transform: translateX(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

/* Header */
.header {
  text-align: center;
  padding: 84px 20px 24px; /* 상단 고정 버튼 고려해 여백 증가 */
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  margin-bottom: 24px;
}
.header h1 {
  font-size: 28px;
  margin: 0 0 8px;
  font-weight: 700;
}
.header p {
  font-size: 14px;
  opacity: .9;
  margin: 0;
}

/* Content Container */
.content {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px 32px;
}

/* Phone Section (Verification) */
.phone-section {
  background: var(--card);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.phone-section h2 {
  font-size: 20px;
  margin: 0 0 16px;
  color: var(--primary);
}
.input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.phone-input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  transition: border-color .2s;
}
.phone-input:focus {
  outline: none;
  border-color: var(--primary);
}
.search-btn {
  padding: 12px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
}
.search-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
}
.search-btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* Loading */
.loading {
  text-align: center;
  padding: 48px 20px;
}
.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading p {
  color: var(--muted);
  font-size: 14px;
}

/* Links Section */
.links-section {
  background: var(--card);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.links-section h3 {
  margin: 0 0 16px;
  font-size: 18px;
}

/* Top Bar (Phone + Logout) */
.links-section > div:first-of-type {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.links-section > div:first-of-type h3 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 160px; /* 좁은 화면에서 깨짐 방지 */
}
.links-section > div:first-of-type span {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.links-section > div:first-of-type button {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.links-section > div:first-of-type button:hover {
  opacity: .9;
  transform: translateY(-1px);
}

/* Link Item (Card) */
.link-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  transition: all .2s;
}
.link-item:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  border-color: var(--primary);
}
.link-item > div:first-child {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.link-item > div:first-child > div:first-child {
  flex: 1;
  min-width: 0; /* 텍스트 overflow 방지 */
}
.linker-name {
  font-weight: 600;
  font-size: 16px;
  color: var(--primary);
  cursor: pointer;
  padding: 4px 0;
  transition: opacity .2s;
  word-break: break-word;
}
.linker-name:hover {
  opacity: .8;
}
.link-item .code,
.link-item a {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
  word-break: break-all;
  overflow-wrap: anywhere; /* 모바일에서 긴 URL 강제 줄바꿈 */
}
.link-item a {
  color: var(--secondary);
  font-size: 13px;
  text-decoration: none;
  display: block;
  margin-top: 4px;
}
.link-item a:hover {
  text-decoration: underline;
}
.link-item > div:first-child > div:last-child {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;        /* 버튼 줄바꿈 허용 */
  justify-content: flex-end;
  row-gap: 8px;
}

/* Status Badge */
.link-status {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: all .2s;
}
.status-active {
  background: #d4edda;
  color: var(--success);
}
.status-inactive {
  background: #f8d7da;
  color: var(--danger);
}
.link-status:hover {
  opacity: .8;
}

/* Action Buttons */
.qr-btn, .delete-btn {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all .2s;
}
.qr-btn {
  background: var(--primary);
  color: #fff;
}
.qr-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}
.delete-btn {
  background: var(--danger);
  color: #fff;
  padding: 8px 12px;
  font-size: 16px;
}
.delete-btn:hover {
  opacity: .9;
  transform: scale(1.05);
}

/* QR Container */
.qr-container {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.qr-container canvas {
  width: min(280px, 100%);  /* 부모 폭에 맞게 축소 */
  height: auto;             /* 종횡비 유지 */
  image-rendering: pixelated; /* QR 가장자리 선명도 */
  border: 3px solid var(--primary);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: transform .2s;
}
.qr-container canvas:hover {
  transform: scale(1.02);
}

/* Empty State */
.link-item p[style*="text-align:center"] {
  padding: 32px 16px;
  color: var(--muted);
  font-size: 14px;
}

/* Footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  text-align: center;
  padding: 16px;
  font-size: 13px;
  color: var(--muted);
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}

/* Mobile Responsive (< 640px) */
@media (max-width: 640px) {
  .back-btn {
    top: 12px;
    left: 12px;
    padding: 8px 12px;
    font-size: 13px;
  }

  .header {
    padding: 60px 16px 20px;
  }
  .header h1 {
    font-size: 22px;
  }
  .header p {
    font-size: 13px;
  }

  .content {
    padding: 0 16px 28px;
  }

  .phone-section {
    padding: 20px 16px;
  }
  .phone-section h2 {
    font-size: 18px;
  }

  .input-group {
    flex-direction: column;
    gap: 10px;
  }
  .search-btn {
    width: 100%;
    padding: 12px;
  }

  .links-section {
    padding: 20px 16px;
  }
  .links-section h3 {
    font-size: 16px;
  }

  /* Top Bar Stack on Mobile */
  .links-section > div:first-of-type {
    flex-direction: column;
    align-items: stretch;
  }
  .links-section > div:first-of-type button {
    width: 100%;
  }

  /* Link Item Mobile Layout */
  .link-item {
    padding: 14px;
  }
  .link-item > div:first-child {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .link-item > div:first-child > div:last-child {
    width: 100%;
    justify-content: flex-start; /* 버튼 왼쪽 정렬 */
  }

  .linker-name {
    font-size: 15px;
  }
  .link-item .code {
    font-size: 12px;
  }

  .link-status {
    padding: 5px 10px;
    font-size: 11px;
  }

  .qr-btn, .delete-btn {
    padding: 7px 12px;
    font-size: 12px;
  }

  .qr-container canvas {
    width: 100%;      /* 모바일에서 꽉 차게 */
    max-width: 320px; /* 너무 커지지 않도록 */
  }

  .footer {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Tablet (641px ~ 900px) */
@media (min-width: 641px) and (max-width: 900px) {
  .content {
    padding: 0 24px 32px;
  }

  .header h1 {
    font-size: 26px;
  }

  .link-item > div:first-child {
    flex-wrap: wrap;
  }
}

/* Large Desktop (> 1200px) */
@media (min-width: 1201px) {
  .content {
    max-width: 1100px;
  }

  .link-item {
    padding: 20px;
  }

  .linker-name {
    font-size: 17px;
  }
}