/* =========================================================
   나의 사이트 — 디자인 시스템 (반응형, 모바일 우선)
   ========================================================= */

:root {
  /* 색상 */
  --bg: #f7f8fb;
  --bg-soft: #eef1f7;
  --card: #ffffff;
  --ink: #161a22;
  --ink-soft: #475067;
  --muted: #8a93a6;
  --brand: #4f6bff;
  --brand-2: #7c5cff;
  --brand-ink: #ffffff;
  --border: #e6e9f0;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --success: #16a34a;

  /* 형태 */
  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 10px;

  /* 그림자 */
  --shadow-sm: 0 1px 2px rgba(22, 26, 34, .06);
  --shadow: 0 6px 24px rgba(22, 26, 34, .08);
  --shadow-lg: 0 16px 48px rgba(22, 26, 34, .14);

  /* 레이아웃 */
  --maxw: 1040px;
  --gutter: clamp(16px, 4vw, 28px);

  /* 모션 */
  --t: .18s cubic-bezier(.2, .7, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --bg-soft: #151a22;
    --card: #171c26;
    --ink: #eef1f7;
    --ink-soft: #b7c0d4;
    --muted: #7e899e;
    --brand: #6d83ff;
    --brand-2: #9a7bff;
    --border: #262d3a;
    --danger: #ff6b6f;
    --danger-soft: #2a1a1c;
  }
}

/* ---------- 사이트 테마 (관리자가 선택, data-theme 으로 적용) ---------- */
/* 기본(indigo)은 위 :root 값을 그대로 사용. 나머지는 브랜드 컬러만 교체하면
   배경 그라데이션·버튼·카드 호버 등 강조 요소에 전부 반영된다. */
:root[data-theme="ocean"]  { --brand: #0ea5e9; --brand-2: #06b6d4; }
:root[data-theme="forest"] { --brand: #16a34a; --brand-2: #0d9488; }
:root[data-theme="sunset"] { --brand: #f97316; --brand-2: #ef4444; }
:root[data-theme="rose"]   { --brand: #ec4899; --brand-2: #f43f5e; }
:root[data-theme="mono"]   { --brand: #475569; --brand-2: #1e293b; }

@media (prefers-color-scheme: dark) {
  :root[data-theme="ocean"]  { --brand: #38bdf8; --brand-2: #22d3ee; }
  :root[data-theme="forest"] { --brand: #34d399; --brand-2: #2dd4bf; }
  :root[data-theme="sunset"] { --brand: #fb923c; --brand-2: #f87171; }
  :root[data-theme="rose"]   { --brand: #f472b6; --brand-2: #fb7185; }
  :root[data-theme="mono"]   { --brand: #94a3b8; --brand-2: #cbd5e1; }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard",
    "Apple SD Gothic Neo", "Malgun Gothic", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 100% -10%, color-mix(in srgb, var(--brand) 10%, transparent), transparent 60%),
    linear-gradient(to bottom,
      color-mix(in srgb, var(--bg) 72%, transparent),
      color-mix(in srgb, var(--bg) 86%, transparent)),
    url("server.jpg") center center / cover no-repeat fixed,
    var(--bg);
  color: var(--ink);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--card) 80%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: clamp(17px, 2.4vw, 21px);
  letter-spacing: -0.02em;
  color: var(--ink);
}
.brand:hover { text-decoration: none; opacity: .9; }
.nav-links {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ---------- 레이아웃 ---------- */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(24px, 5vw, 48px) var(--gutter) 80px;
}

.page-head { margin-bottom: clamp(20px, 4vw, 32px); }
.page-title {
  font-size: clamp(26px, 5.5vw, 40px);
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
  font-weight: 800;
}
.page-sub {
  color: var(--ink-soft);
  font-size: clamp(15px, 2.4vw, 17px);
  margin: 0;
  max-width: 60ch;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: clamp(18px, 3vw, 22px); font-weight: 700; letter-spacing: -0.02em; }

.divider { height: 1px; background: var(--border); margin: 28px 0; border: 0; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  min-height: 42px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--t), background var(--t), border-color var(--t), box-shadow var(--t);
  box-shadow: var(--shadow-sm);
}
.btn:hover { text-decoration: none; background: var(--bg-soft); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent;
  color: var(--brand-ink);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 35%, transparent);
}
.btn.primary:hover { filter: brightness(1.05); background: linear-gradient(135deg, var(--brand), var(--brand-2)); }

.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--bg-soft); }

.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); background: var(--card); }
.btn.danger:hover { background: var(--danger-soft); }

.btn.small { min-height: 36px; padding: 8px 14px; font-size: 13.5px; }
.btn.block { width: 100%; }

/* ---------- 카드 그리드 (메인) ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: clamp(14px, 2.5vw, 20px);
}
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 150px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  opacity: 0;
  transition: opacity var(--t);
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--brand) 30%, var(--border));
}
.card:hover::before { opacity: 1; }
.card h3 { margin: 0; font-size: clamp(17px, 2.6vw, 19px); font-weight: 700; letter-spacing: -0.01em; }
.card .excerpt { color: var(--ink-soft); font-size: 14.5px; margin: 0; flex: 1; }
.card .meta { color: var(--muted); font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }

/* ---------- 빈 상태 ---------- */
.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: clamp(48px, 10vw, 80px) 20px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 60%, transparent);
}

/* ---------- 폼 ---------- */
.form-row { margin-bottom: 18px; }
label { display: block; font-weight: 650; margin-bottom: 8px; font-size: 14px; color: var(--ink); }
input[type="text"], input[type="password"], input[type="url"], input[type="search"], textarea {
  width: 100%;
  padding: 13px 15px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* iOS 확대 방지 */
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--card);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent);
}
textarea { min-height: 240px; resize: vertical; line-height: 1.6; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }

.form-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- 패널/카드 컨테이너 ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 4vw, 32px);
  box-shadow: var(--shadow-sm);
}

/* ---------- 검색 ---------- */
.section-head .search-input { width: min(260px, 100%); padding: 10px 14px; }
.search-main { max-width: 420px; margin-bottom: 22px; }

/* ---------- 이미지 업로드 ---------- */
.upload-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.upload-row input[type="file"] {
  flex: 1;
  min-width: 200px;
  padding: 10px;
  font-size: 14px;
  color: var(--muted);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.upload-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.upload-item img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}
.upload-item .upload-name { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .actions { display: flex; gap: 6px; }
.upload-item .actions .btn { flex: 1; min-height: 32px; padding: 6px 8px; font-size: 12.5px; }

/* 그리드 안 빈 상태 메시지는 전체 폭 사용 */
.grid .empty { grid-column: 1 / -1; }

/* ---------- 관리자 목록 ---------- */
.admin-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.admin-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t), box-shadow var(--t);
}
.admin-item:hover { border-color: color-mix(in srgb, var(--brand) 25%, var(--border)); box-shadow: var(--shadow); }
.admin-item .info { min-width: 0; }
.admin-item .info h4 { margin: 0 0 3px; font-size: 16.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-item .info .meta { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-item .actions { display: flex; gap: 8px; flex-shrink: 0; }

/* 모바일: 관리자 항목 세로 정렬 */
@media (max-width: 560px) {
  .admin-item { flex-direction: column; align-items: stretch; }
  .admin-item .actions { justify-content: flex-end; }
  .admin-item .actions .btn { flex: 1; }
}

/* ---------- 본문 글 (하부 페이지) ---------- */
.article {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(24px, 5vw, 44px);
  box-shadow: var(--shadow-sm);
}
.article h1 { margin-top: 0; font-size: clamp(24px, 5vw, 36px); letter-spacing: -0.03em; line-height: 1.2; }
.article-meta {
  color: var(--muted);
  font-size: 13.5px;
  margin: 6px 0 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.article-body { font-size: clamp(16px, 2.4vw, 17.5px); color: var(--ink); }
.article-body :is(h2, h3) { letter-spacing: -0.02em; }
.article-body img { border-radius: var(--radius-sm); }
.article-body a { text-decoration: underline; }
.article-link { margin: 28px 0 0; padding-top: 24px; border-top: 1px solid var(--border); }
.article-link a { text-decoration: none; }

/* ---------- 로그인 카드 ---------- */
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: clamp(24px, 8vh, 80px);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(28px, 6vw, 40px);
  box-shadow: var(--shadow-lg);
}
.login-card .lock { font-size: 32px; margin-bottom: 8px; }
.login-card .page-title { font-size: clamp(22px, 5vw, 26px); }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(24px);
  background: var(--ink);
  color: var(--bg);
  padding: 13px 22px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t), transform var(--t);
  z-index: 100;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 테마 선택 (관리자) ---------- */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.theme-swatch {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}
.theme-swatch:hover {
  border-color: color-mix(in srgb, var(--sw) 55%, var(--border));
  transform: translateY(-2px);
}
.theme-swatch:focus-visible { outline: 2px solid var(--sw); outline-offset: 2px; }
.theme-swatch .dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--sw), color-mix(in srgb, var(--sw) 55%, #ffffff));
  box-shadow: 0 2px 7px color-mix(in srgb, var(--sw) 45%, transparent);
}
.theme-swatch.active {
  border-color: var(--sw);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sw) 25%, transparent);
}
.theme-swatch.active .name::after {
  content: " ✓";
  color: var(--sw);
  font-weight: 800;
}

/* ---------- 접근성: 모션 최소화 ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .card:hover { transform: none; }
}
