:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --hover: #f0f3f9;
  --danger-bg: #fdecec;
  --danger-text: #a51b1b;
  --info-bg: #eaf2ff;
  --info-text: #1c4fb0;
  --selected-bg: #dbe7ff;
  --selected-hover: #cddcfd;
  --share: #11855a;
  --share-bg: #e3f5ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --border: #2c313a;
    --text: #e6e8eb;
    --muted: #9aa1ad;
    --accent: #5b8dff;
    --accent-text: #0d1220;
    --hover: #232830;
    --danger-bg: #3a1f21;
    --danger-text: #ff9a9a;
    --info-bg: #1d2a44;
    --info-text: #a7c4ff;
    --selected-bg: #22345a;
    --selected-hover: #2a3e68;
    --share: #4fd19a;
    --share-bg: #17352a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
        "Malgun Gothic", "Noto Sans KR", Roboto, sans-serif;
}

a { color: inherit; text-decoration: none; }

.container { max-width: 1060px; margin: 0 auto; padding: 20px 16px 48px; }

/* 상단 바 */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.who { color: var(--muted); font-size: 13px; }
.inline { display: inline; margin: 0; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-family: inherit; cursor: pointer; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-get {
  white-space: nowrap; font-weight: 600;
  background: var(--info-bg); border-color: var(--accent); color: var(--info-text);
  transition: background .12s ease, color .12s ease, box-shadow .12s ease, transform .12s ease;
}
.btn-get:hover, .btn-get:focus-visible {
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 2px 6px rgba(47, 111, 237, .35); transform: translateY(-1px);
}
.btn-get:active { transform: translateY(0); box-shadow: none; }
.btn-share, .btn-shared {
  white-space: nowrap;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.btn-share { background: transparent; color: var(--muted); }
.btn-share:hover, .btn-share:focus-visible { border-color: var(--share); color: var(--share); background: var(--share-bg); }
.btn-shared { background: var(--share-bg); border-color: var(--share); color: var(--share); font-weight: 600; }
.btn-shared:hover, .btn-shared:focus-visible { background: var(--share); color: var(--surface); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger-text); color: var(--danger-text); font-weight: 600; white-space: nowrap; }
.btn-danger:hover, .btn-danger:focus-visible { background: var(--danger-text); color: var(--surface); }
.btn-block { width: 100%; margin-top: 8px; }

/* 화면 이동 (뒤로·홈) */
.pagenav { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.btn-nav { font-weight: 600; }
.btn-nav:hover, .btn-nav:focus-visible { border-color: var(--accent); color: var(--accent); background: var(--info-bg); }

/* 카드 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* 알림 */
.flashes { margin-bottom: 14px; display: grid; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.flash-error { background: var(--danger-bg); color: var(--danger-text); }
.flash-info { background: var(--info-bg); color: var(--info-text); }

/* 로그인 */
.login-wrap { min-height: 78vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 360px; padding: 28px; }
.login-title { margin: 0 0 4px; font-size: 20px; }
.muted { color: var(--muted); font-size: 13px; }
.field { display: block; margin: 14px 0; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.field input {
  width: 100%; padding: 10px 12px; font: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.req { color: var(--danger-text); font-style: normal; font-size: 11px; font-weight: 400; }
.opt { color: var(--muted); font-style: normal; font-size: 11px; font-weight: 400; }

/* 경로 */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 14px; font-size: 14px; }
.crumb { padding: 3px 7px; border-radius: 6px; }
a.crumb:hover { background: var(--hover); }
.crumb.current { font-weight: 600; }
.sep { color: var(--muted); }

/* 툴바 */
.toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 12px; flex-wrap: wrap; }
.filter {
  flex: 1 1 220px; min-width: 160px; padding: 8px 12px; font: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.spacer { flex: 1 1 auto; }
.summary { white-space: nowrap; }

/* 목록 */
.table-wrap { overflow-x: auto; }
.listing { width: 100%; border-collapse: collapse; font-size: 14px; }
.listing th, .listing td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.listing thead th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.listing tbody tr:last-child td { border-bottom: none; }
.listing tbody tr:hover { background: var(--hover); }
/* 체크된 행: 줄 전체 배경 + 왼쪽 강조선 */
.listing tbody tr.is-selected { background: var(--selected-bg); }
.listing tbody tr.is-selected:hover { background: var(--selected-hover); }
.listing tbody tr.is-selected td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.listing tbody tr.is-selected .name span { font-weight: 600; }
.col-check { width: 40px; }
.col-size { width: 110px; white-space: nowrap; color: var(--muted); }
.col-date { width: 140px; white-space: nowrap; color: var(--muted); }
.col-act { width: 150px; text-align: right; white-space: nowrap; }
.col-act .btn + .btn { margin-left: 4px; }
.col-num { width: 80px; white-space: nowrap; text-align: right; color: var(--muted); }
.name { display: inline-flex; gap: 8px; align-items: baseline; overflow-wrap: anywhere; }
.meta-m { display: none; }
.name:hover span { text-decoration: underline; }
.row-up td { color: var(--muted); }
.empty-cell { text-align: center; color: var(--muted); padding: 32px 12px; }
.sort { color: inherit; }
.sort-active { color: var(--text); }
.caret { font-size: 9px; margin-left: 3px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.footer-bar { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.pager { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* 설정 */
.page-title { font-size: 20px; margin: 4px 0 16px; }
.form-card { max-width: 480px; padding: 22px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
code { background: var(--hover); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* 공유 */
.share-file { margin: 0 0 4px; word-break: break-all; }
.share-path { word-break: break-all; font-size: 12px; margin: 2px 0 0; }
.share-state { font-weight: 600; margin: 0 0 6px; color: var(--muted); }
.share-state.on { color: var(--share); }
.copy-row { display: flex; gap: 6px; align-items: center; margin: 10px 0; }
.listing .copy-row { margin: 0; min-width: 260px; }
.copy-input {
  flex: 1 1 auto; min-width: 0; padding: 7px 10px; font: inherit; font-size: 13px;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.select {
  width: 100%; padding: 9px 10px; font: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.share-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 12px 0; font-size: 14px; }
.share-meta dt { color: var(--muted); }
.share-meta dd { margin: 0; }
.badge-warn { margin-left: 6px; padding: 1px 6px; border-radius: 6px; font-size: 11px; background: var(--danger-bg); color: var(--danger-text); }

/* 오류 */
.empty { text-align: center; padding: 48px 24px; display: grid; gap: 12px; justify-items: center; }
.empty-icon { font-size: 34px; margin: 0; }

@media (max-width: 640px) {
  .col-date { display: none; }
  .container { padding: 14px 12px 40px; }

  /* 상단 바: 메뉴 글자가 세로로 쪼개지지 않게 줄이고, 사용자 이름은 숨긴다 */
  .topbar { padding: 10px 12px; gap: 8px; }
  .brand { font-size: 15px; white-space: nowrap; }
  .who { display: none; }
  .topbar-actions { gap: 4px; }
  .topbar-actions .btn { padding: 7px 10px; font-size: 13px; }

  /* iOS는 16px 미만 입력칸에 초점이 가면 화면을 확대한다 */
  .filter, .field input, .select, .copy-input { font-size: 16px; }

  .page-title { font-size: 18px; }
  .form-card { padding: 18px 16px; }

  /* 툴바: 검색창 한 줄, 선택 요약과 ZIP 버튼 한 줄 */
  .toolbar { padding: 10px; gap: 8px; }
  .filter { flex: 1 1 100%; }
  .spacer { display: none; }
  .summary { flex: 1 1 auto; }

  /* 파일 목록: 크기·수정일 칸을 빼고 이름 아래 한 줄로, 버튼은 세로로 쌓아 이름 칸을 넓힌다 */
  .listing th, .listing td { padding: 10px 8px; }
  .col-size { display: none; }
  .col-check { width: 34px; }
  .col-act { width: 78px; }
  .col-act .btn { display: flex; width: 100%; }
  .col-act .btn + .btn { margin: 6px 0 0; }
  .btn-sm { padding: 6px 10px; min-height: 32px; }
  .meta-m { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); }
  input[type="checkbox"] { width: 20px; height: 20px; }

  .footer-bar { flex-wrap: wrap; }

  /* 공유 목록: 표 대신 항목마다 카드 형태로 쌓는다 */
  .listing.shares thead { display: none; }
  .listing.shares tr {
    display: grid; grid-template-columns: 1fr auto; gap: 6px 10px;
    padding: 12px; border-bottom: 1px solid var(--border);
  }
  .listing.shares tbody tr:last-child { border-bottom: none; }
  .listing.shares td { display: block; padding: 0; border: none; width: auto; text-align: left; }
  .listing.shares td.col-name, .listing.shares td.col-link, .listing.shares td.empty-cell { grid-column: 1 / -1; }
  .listing.shares td.empty-cell { padding: 20px 0; text-align: center; }
  .listing.shares .copy-row { min-width: 0; }
  .listing.shares td.col-date, .listing.shares td.col-num { grid-column: 1; font-size: 13px; }
  .listing.shares td[data-label]::before { content: attr(data-label) " "; color: var(--muted); margin-right: 4px; }
  .listing.shares td.col-num::after { content: "회"; }
  .listing.shares td.col-act { grid-column: 2; grid-row: 3 / span 2; align-self: center; }
}
