:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #171a1f;
  --muted: #69707d;
  --border: #e3e6eb;
  --accent: #2f5bd8;
  --accent-soft: #e8eefc;
  --danger: #c4323a;
  --radius: 12px;
  --gutter: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e8eaee;
    --muted: #9198a5;
    --border: #2b3039;
    --accent: #7c9cff;
    --accent-soft: #232c45;
    --danger: #ff7a80;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }

/* 상단 바 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px max(var(--gutter), env(safe-area-inset-left)) 10px max(var(--gutter), env(safe-area-inset-right));
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar form { margin: 0; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px var(--gutter) calc(40px + env(safe-area-inset-bottom));
}

/* 버튼 */
.btn-ghost {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 36px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; white-space: nowrap; font-size: 14px;
}
.btn-ghost:hover { border-color: var(--muted); }
.btn-primary {
  display: inline-flex; justify-content: center; align-items: center;
  min-height: 44px; padding: 10px 16px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .btn-primary { color: #0b1020; } }

/* 툴바 */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search {
  flex: 1 1 240px; min-width: 0; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  font-size: 16px; /* iOS 확대 방지 */
}
.search:focus, .auth-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.segmented a {
  padding: 6px 12px; border-radius: 7px; font-size: 14px; color: var(--muted); white-space: nowrap;
}
.segmented a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count { margin: 14px 2px 8px; font-size: 13px; }

/* 리포트 목록 */
.report-list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.report-head, .report a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 136px 136px 72px;
  gap: 16px; align-items: center;
  padding: 12px 18px;
}
.report-head {
  font-size: 12px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 60%, var(--surface));
}
.report + .report { border-top: 1px solid var(--border); }
.report a:hover { background: var(--accent-soft); }
.r-main { display: flex; flex-direction: column; min-width: 0; }
.r-title { font-weight: 600; overflow-wrap: anywhere; }
.r-file { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-date, .r-size { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.r-size { text-align: right; }
.r-date em { display: none; font-style: normal; }
.sort-created .c-created, .sort-modified .c-modified { color: var(--text); }
.report-head .c-created, .report-head .c-modified { color: var(--muted); }
.sort-created .report-head .c-created, .sort-modified .report-head .c-modified { color: var(--accent); }
.empty { padding: 40px 0; text-align: center; }

/* 모바일: 카드형 */
@media (max-width: 720px) {
  .container { padding-top: 14px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .segmented { display: flex; }
  .segmented a { flex: 1; text-align: center; }
  .report-head { display: none; }
  .report a {
    grid-template-columns: 1fr auto;
    gap: 4px 12px; padding: 14px 16px;
  }
  .r-main { grid-column: 1 / -1; }
  .r-title { font-size: 15.5px; line-height: 1.4; }
  .r-date em { display: inline; color: var(--muted); }
  .r-date { font-size: 12.5px; }
  .r-size { display: none; }
}

/* 뷰어 */
.page-viewer { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.viewer-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px max(12px, env(safe-area-inset-left)) 8px max(12px, env(safe-area-inset-right));
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.viewer-title {
  flex: 1; min-width: 0; margin: 0;
  font-size: 15px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viewer-frame { flex: 1; width: 100%; border: 0; background: #fff; }

/* 로그인 */
.page-auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.auth-card {
  width: 100%; max-width: 360px;
  padding: 28px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
.auth-card h1 { margin: 0 0 18px; font-size: 22px; }
.auth-card form { display: flex; flex-direction: column; }
.auth-card label { font-size: 13px; color: var(--muted); margin: 10px 0 6px; }
.auth-card input {
  min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  font-size: 16px;
}
.auth-card .btn-primary { margin-top: 20px; width: 100%; }
.auth-card p { margin: 0 0 16px; }
.error { color: var(--danger); font-size: 14px; }

/* 상단 바 버튼·메시지 */
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.messages { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.messages li { padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; overflow-wrap: anywhere; }
.messages .msg-error { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn-danger { color: var(--danger); }
.viewer-bar form { margin: 0; }
.link { color: var(--accent); text-decoration: underline; }

/* 업로드 */
.page-title { font-size: 20px; margin: 0 0 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.form-stack { display: flex; flex-direction: column; max-width: 560px; }
.form-stack label { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.form-stack label:first-of-type { margin-top: 0; }
.form-stack input[type=text] {
  min-height: 44px; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.form-stack input[type=file] { max-width: 100%; }
.form-stack .hint { font-size: 13px; margin: 12px 0 16px; }
.form-stack .error { margin: 6px 0 0; }
