/* 홈서버 포털 — 휴대폰 우선, 밝은/어두운 테마 자동 */

:root {
  color-scheme: light dark;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #17202e;
  --muted: #5d6a7e;
  --border: #dde3ec;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --focus: #93b4ff;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 18px;
  --t-files: #2563eb;
  --t-status: #0d9488;
  --t-claude: #c2410c;
  --t-remote: #7c3aed;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --surface: #18202b;
    --surface-2: #222b38;
    --text: #e8edf4;
    --muted: #9aa7b9;
    --border: #2a3442;
    --primary: #4f8cff;
    --focus: #3b6fd8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --t-files: #3b82f6;
    --t-status: #14b8a6;
    --t-claude: #ea580c;
    --t-remote: #8b5cf6;
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

h1, h2 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; color: var(--muted); font-weight: 600; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }

/* ---------- 카드 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card.narrow { width: 100%; max-width: 400px; }

/* ---------- 가운데 정렬 페이지(로그인, 안내) ---------- */
.center-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}
.center-page .card { padding: 2rem 1.5rem; text-align: center; }
.center-page .form { text-align: left; margin-top: 1.25rem; }
.logo { display: block; margin: 0 auto 1rem; }
.server-name { font-size: 1.6rem; }
.message .button { margin-top: .5rem; }

/* ---------- 폼 ---------- */
.form { display: flex; flex-direction: column; gap: .5rem; }
.form label { font-weight: 600; font-size: .95rem; }
.form label.check { font-weight: 400; display: flex; align-items: center; gap: .5rem; color: var(--muted); }
.form label.check input { width: 1.15rem; height: 1.15rem; }

input[type="password"], input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 1.1rem;
  padding: .85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: .5rem;
}
input:focus-visible, .button:focus-visible, .tile:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
input:disabled { opacity: .6; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 48px;
  padding: .7rem 1.25rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.button.primary:hover { filter: brightness(1.08); }
.button.ghost { background: transparent; }
.button.small { min-height: 40px; padding: .4rem .9rem; font-size: .9rem; }
.button.wide { width: 100%; margin-top: .5rem; font-size: 1.05rem; }
.button:disabled { opacity: .55; cursor: not-allowed; }

.error { color: var(--danger); min-height: 1.5em; margin: .25rem 0 0; font-weight: 600; }
.success { color: var(--ok); min-height: 1.5em; margin: .25rem 0 0; font-weight: 600; }
.notice {
  background: var(--surface-2);
  border-left: 4px solid var(--warn);
  border-radius: 10px;
  padding: .85rem 1rem;
  text-align: left;
}

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  padding-top: max(.75rem, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand, .back {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
  min-height: 44px;
}
.back { font-weight: 600; font-size: 1rem; color: var(--primary); }

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}
.page-head { margin-bottom: 1rem; }

/* ---------- 홈 타일 ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .9rem;
  margin-bottom: 1.25rem;
}
.tile {
  --c: var(--primary);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .35rem;
  min-height: 150px;
  padding: 1.1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:hover { transform: translateY(-2px); }
.tile:active { transform: scale(.98); }
.tile-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--c);
  margin-bottom: .4rem;
}
.tile-title { font-size: 1.2rem; font-weight: 700; }
.tile-desc { font-size: .9rem; color: var(--muted); line-height: 1.35; }
.tile-files { --c: var(--t-files); }
.tile-status { --c: var(--t-status); }
.tile-claude { --c: var(--t-claude); }
.tile-remote { --c: var(--t-remote); }

@media (min-width: 760px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tile { min-height: 180px; }
}

/* ---------- 요약 ---------- */
.summary-list { list-style: none; margin: 0; padding: 0; }
.summary-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem 0;
  border-bottom: 1px solid var(--border);
}
.summary-list .k { color: var(--muted); }
.summary-list .v { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.summary .more { display: inline-block; margin-top: .9rem; font-weight: 600; text-decoration: none; }

/* ---------- 상태 ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stat .big { font-size: 2rem; font-weight: 700; margin: 0 0 .25rem; font-variant-numeric: tabular-nums; }

.bar {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin: .5rem 0;
}
.bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--ok);
  transition: width .4s ease;
}
.bar > span.lv-warn { background: var(--warn); }
.bar > span.lv-danger { background: var(--danger); }

.disk-list { display: flex; flex-direction: column; gap: 1.1rem; }
.disk-head, .disk-foot { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.disk-foot { font-size: .9rem; }
.disk-foot .free { font-weight: 600; color: var(--text); }

.proc-list { margin: 0; padding: 0; list-style: none; counter-reset: p; }
.proc-list li {
  counter-increment: p;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 0;
  border-bottom: 1px solid var(--border);
}
.proc-list li::before {
  content: counter(p);
  flex: 0 0 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
}
.proc-list li.muted::before { content: none; }
.proc-list .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proc-list .pmem { font-weight: 600; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .tile, .bar > span { transition: none; }
}

/* ---------- 파일 화면 ---------- */
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.notice.is-error { border-left-color: var(--danger); color: var(--danger); font-weight: 600; }
.notice { margin: 0 0 1rem; }

.files-head { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem .4rem;
  font-size: 1.15rem;
  min-height: 2.5rem;
}
.crumb { text-decoration: none; font-weight: 600; padding: .25rem .35rem; border-radius: 8px; }
.crumb:hover { background: var(--surface-2); }
.crumb.current { color: var(--text); padding: .25rem .35rem; }
.crumb-sep { color: var(--muted); }

.files-tools { display: flex; flex-direction: column; gap: .6rem; }
.tool-buttons { display: flex; gap: .6rem; }
.tool-buttons .button { flex: 1; }
input.search {
  width: 100%;
  font: inherit;
  padding: .75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
input.search:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (min-width: 700px) {
  .files-tools { flex-direction: row; align-items: center; }
  .files-tools .search { flex: 1; }
  .tool-buttons .button { flex: 0 0 auto; }
}

.selection-bar {
  position: sticky;
  top: 4.25rem;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .6rem .8rem;
  margin-bottom: .75rem;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--primary);
  box-shadow: var(--shadow);
}
.selection-bar #selection-count { font-weight: 700; }
.selection-actions { display: flex; flex-wrap: wrap; gap: .4rem; }

.file-card { padding: .25rem .5rem; }
.file-list { list-style: none; margin: 0; padding: 0; }
.file-row {
  display: flex;
  align-items: center;
  gap: .25rem;
  border-bottom: 1px solid var(--border);
}
.file-row:last-child { border-bottom: 0; }
.file-row.selected { background: var(--surface-2); border-radius: 12px; }
.file-check { flex: 0 0 auto; width: 1.35rem; height: 1.35rem; margin: 0 .6rem; accent-color: var(--primary); }
.file-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .7rem .4rem;
  min-height: 60px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  border-radius: 12px;
}
.file-main:hover { background: var(--surface-2); }
.file-main:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.file-main img { flex: 0 0 auto; }
.file-text { display: flex; flex-direction: column; min-width: 0; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: .85rem; color: var(--muted); }
.root-row .file-main { padding-left: .6rem; }
.root-row.unavailable { opacity: .55; }
.root-row.unavailable .file-main { cursor: default; }
.loading { padding: 1rem .6rem; }
.empty { padding: 2rem 1rem; text-align: center; margin: 0; }

.drop-hint {
  margin-bottom: 1rem;
  padding: 1.5rem;
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  text-align: center;
  font-weight: 700;
  color: var(--primary);
}
.dragging .file-card { outline: 2px dashed var(--primary); outline-offset: 4px; }

.uploads-head { display: flex; align-items: center; justify-content: space-between; }
.upload-list { list-style: none; margin: 0; padding: 0; }
.upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .1rem .75rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
}
.upload-row .bar { grid-column: 1 / -1; margin: .25rem 0 0; height: 8px; }
.upload-row .bar > span { background: var(--primary); transition: width .2s linear; }
.upload-row .bar > span.lv-ok { background: var(--ok); }
.upload-row .bar > span.lv-danger { background: var(--danger); }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.upload-status { font-size: .85rem; text-align: right; }
.upload-status.error { min-height: 0; margin: 0; }

/* 대화상자 */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  padding: 0;
}
dialog::backdrop { background: rgba(10, 15, 25, .55); }
.dialog { width: min(92vw, 420px); }
.dialog form { padding: 1.4rem; }
.dialog h2 { color: var(--text); font-size: 1.2rem; }
.dialog input { margin: .5rem 0 0; }
.dialog-buttons { display: flex; gap: .6rem; justify-content: flex-end; margin-top: .5rem; }
.dialog-buttons .button { flex: 1; }

.viewer { width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; margin: 0; border: 0; border-radius: 0; }
.viewer[open] { display: flex; flex-direction: column; }
.viewer-open { overflow: hidden; }
.viewer-stage { flex: 1; min-height: 0; position: relative; background: var(--surface-2); }
.viewer-arrow { position: absolute; top: 50%; transform: translateY(-50%); z-index: 1; padding: .5rem; min-width: 44px; opacity: .9; }
.viewer-prev { left: .4rem; }
.viewer-next { right: .4rem; }
.viewer-caption { min-width: 0; display: flex; flex-direction: column; }
.viewer-caption strong { display: block; }
.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  padding-bottom: max(.75rem, env(safe-area-inset-bottom));
  flex-wrap: wrap;
}
.viewer-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.viewer-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.viewer-body { display: flex; height: 100%; align-items: center; justify-content: center; padding: .5rem; touch-action: pan-y pinch-zoom; }
.viewer-body > img, .viewer-body > video { width: 100%; height: 100%; object-fit: contain; }
.viewer-body audio { width: 100%; }
.viewer-body p { padding: 2rem 1rem; }
.viewer-error { text-align: center; }

/* 사진 격자 */
.view-switch { display: flex; gap: .4rem; margin: 0 0 .75rem; }
.view-switch [aria-pressed="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.gallery-folders .file-main { min-height: 48px; padding-top: .3rem; padding-bottom: .3rem; }
.photo-grid { list-style: none; padding: .5rem 0; margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; }
@media (min-width: 640px) { .photo-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; } }
.photo-tile { min-width: 0; position: relative; border-radius: 10px; overflow: hidden; }
.photo-tile.selected { outline: 3px solid var(--primary); outline-offset: -3px; }
.photo-tile .file-check { position: absolute; top: .4rem; left: .4rem; z-index: 1; margin: 0; }
.photo-main { width: 100%; display: block; padding: 0; border: 0; background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer; }
.photo-main:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.thumb-square { aspect-ratio: 1; display: grid; place-items: center; position: relative; overflow: hidden; }
.thumb-square > img { grid-area: 1 / 1; }
.thumb-square .thumb-image { width: 100%; height: 100%; min-height: 0; object-fit: cover; }
.photo-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: .35rem; font-size: .8rem; }
.video-mark { position: absolute; bottom: .35rem; right: .4rem; background: var(--surface); border-radius: 50%; width: 1.7rem; height: 1.7rem; }
.gallery-more { display: flex; margin: .5rem auto; }
.gallery-others { padding: .5rem; border-top: 1px solid var(--border); }
.gallery-others summary { min-height: 44px; padding: .6rem 0; cursor: pointer; font-weight: 600; }

/* 2단계 인증 */
.linklike {
  background: none;
  border: 0;
  padding: .4rem 0;
  min-height: 40px;
  color: var(--primary);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
  align-self: flex-start;
}
.linklike:disabled { opacity: .55; cursor: not-allowed; }
.small-text { font-size: .9rem; margin: 0; }
.tfa-buttons { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .5rem; }
.qr-box { display: flex; justify-content: center; margin: .75rem 0; }
.qr-box img { width: 240px; height: 240px; max-width: 100%; background: #ffffff; border-radius: 8px; image-rendering: pixelated; }
.secret {
  display: block;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1rem;
  letter-spacing: .05em;
  word-break: break-all;
  background: var(--surface-2);
  border-radius: 8px;
  padding: .5rem .75rem;
  user-select: all;
}
.codes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .4rem .75rem;
  margin: .75rem 0;
  padding: .75rem 1rem .75rem 2rem;
  background: var(--surface-2);
  border-radius: 10px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.05rem;
  user-select: all;
}
