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

:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1e2530;
  --muted: #7a8494;
  --accent: #2f6fed;
  --accent-hover: #1f5bd0;
  --border: #e2e6ec;
  --danger: #d94848;
  --radius: 10px;
}

body {
  font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: #eef1f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.subtle { border-color: transparent; background: transparent; color: var(--muted); }
.btn.subtle:hover { color: var(--text); background: #eef1f6; }

/* ---------- 로그인 ---------- */
#auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 340px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(20, 30, 60, .08);
}
.auth-card h1 { font-size: 26px; margin-bottom: 6px; }
#auth-subtitle { color: var(--muted); margin-bottom: 22px; font-size: 14px; }
.auth-card input {
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.auth-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.auth-card button {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  margin-top: 4px;
}
.auth-card button:hover { background: var(--accent-hover); }
.auth-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 1em; }

/* ---------- 헤더 / 툴바 ---------- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 19px; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 10px; }
#whoami { color: var(--muted); font-size: 14px; }
#usage-badge {
  font-size: 12px;
  color: var(--muted);
  background: #f0f2f6;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ---------- 레이아웃 (사이드바 + 콘텐츠) ---------- */
.layout {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 61px);
}
#sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
}
.side-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 0 10px 8px;
}
#space-list { display: flex; flex-direction: column; gap: 2px; }
.space-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  width: 100%;
}
.space-item:hover { background: #eef1f6; }
.space-item.active { background: #e7eefc; color: var(--accent); font-weight: 600; }
.space-item .ro { margin-left: auto; font-size: 11px; }
.side-hint {
  margin-top: 18px;
  padding: 0 10px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}
.side-hint code { background: #f0f2f6; padding: 1px 4px; border-radius: 4px; font-size: 10px; }
.content { flex: 1; min-width: 0; }
#readonly-badge { font-size: 13px; color: var(--muted); align-self: center; }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  #sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); padding: 10px 12px; }
  #space-list { flex-direction: row; flex-wrap: wrap; }
  .space-item { width: auto; }
  .side-hint { display: none; }
}

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
  padding: 14px 24px 4px;
}
#breadcrumb { font-size: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
#breadcrumb a { color: var(--accent); text-decoration: none; padding: 4px 6px; border-radius: 6px; }
#breadcrumb a:hover { background: #e7eefc; }
#breadcrumb .sep { color: var(--muted); }
#breadcrumb .current { color: var(--text); font-weight: 600; padding: 4px 6px; }
.toolbar-actions { display: flex; gap: 8px; align-items: center; }

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}
.view-toggle button {
  border: none;
  background: transparent;
  padding: 8px 11px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.view-toggle button + button { border-left: 1px solid var(--border); }
.view-toggle button:hover { background: #eef1f6; color: var(--text); }
.view-toggle button.active { background: #e7eefc; color: var(--accent); }

#drop-hint {
  display: none;
  margin: 10px 24px 0;
  padding: 24px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  text-align: center;
  color: var(--accent);
  background: #eef4ff;
  font-size: 15px;
}
body.dragging #drop-hint { display: block; }

#upload-status {
  margin: 10px 24px 0;
  padding: 10px 16px;
  background: #eef4ff;
  border: 1px solid #c9dbff;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--accent);
}

/* ---------- 파일 목록 ---------- */
#file-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  padding: 18px 24px 40px;
}
.entry {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  position: relative;
  transition: box-shadow .15s, transform .15s;
}
.entry:hover { box-shadow: 0 4px 14px rgba(20, 30, 60, .1); transform: translateY(-2px); }
.entry .icon {
  height: 90px;
  display: flex; align-items: center; justify-content: center;
  font-size: 46px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: #f6f8fb;
  overflow: hidden;
}
.entry .icon img { width: 100%; height: 100%; object-fit: cover; }
.entry .name {
  font-size: 13px;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.4em;
}
.entry .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

.entry .actions {
  position: absolute;
  top: 6px; right: 6px;
  display: none;
  gap: 4px;
}
.entry:hover .actions { display: flex; }
.entry .actions button, .entry .actions a {
  border: none;
  background: rgba(255, 255, 255, .95);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px; height: 28px;
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
  color: var(--text);
}
.entry .actions button:hover, .entry .actions a:hover { background: #eef1f6; }
.entry .actions .del:hover { color: var(--danger); }

#empty-hint {
  text-align: center;
  color: var(--muted);
  padding: 60px 0;
  font-size: 15px;
}

/* ---------- 촘촘히 보기 ---------- */
#file-list.view-compact {
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
#file-list.view-compact .entry { padding: 8px; }
#file-list.view-compact .entry .icon { height: 58px; font-size: 30px; margin-bottom: 6px; }
#file-list.view-compact .entry .name { font-size: 12px; min-height: 2.2em; }
#file-list.view-compact .entry .meta { display: none; }

/* ---------- 목록 보기 ---------- */
#file-list.view-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
#file-list.view-list .entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--border);
}
#file-list.view-list .entry:first-child {
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}
#file-list.view-list .entry:last-child {
  border-bottom: none;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}
#file-list.view-list .entry:hover { transform: none; box-shadow: none; background: #f6f8fb; }
#file-list.view-list .entry .icon {
  height: 34px; width: 34px;
  flex-shrink: 0;
  font-size: 20px;
  margin-bottom: 0;
  border-radius: 6px;
}
#file-list.view-list .entry .name {
  flex: 1;
  min-width: 0;
  min-height: auto;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}
#file-list.view-list .entry .meta {
  margin-top: 0;
  font-size: 12px;
  white-space: nowrap;
  text-align: right;
  width: 150px;
  flex-shrink: 0;
}
#file-list.view-list .entry .actions {
  position: static;
  flex-shrink: 0;
  width: 100px;
  justify-content: flex-end;
  display: flex;            /* 자리를 항상 차지해 호버 시 레이아웃 밀림 방지 */
  visibility: hidden;
}
#file-list.view-list .entry:hover .actions { visibility: visible; }
@media (max-width: 720px) {
  #file-list.view-list .entry .meta { width: auto; }
  #file-list.view-list .entry .actions { width: auto; }
}

/* ---------- 공용 모달 ---------- */
.modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 22, .55); }
.modal-card {
  position: relative;
  background: var(--card);
  border-radius: 14px;
  padding: 26px 28px;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(10, 16, 32, .25);
}
.modal-card.wide { width: min(680px, calc(100vw - 32px)); }
.modal-card h2 { font-size: 18px; margin-bottom: 16px; }
.modal-card h3 { font-size: 14px; margin: 18px 0 10px; color: var(--muted); }
.modal-card input[type="text"], .modal-card input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.modal-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

#add-user-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
#add-user-form input[type="text"], #add-user-form input[type="password"] {
  flex: 1; min-width: 130px; margin-bottom: 0;
}
.check-label { font-size: 13px; display: flex; align-items: center; gap: 5px; white-space: nowrap; }

/* ---------- 외부 저장소 관리 ---------- */
#storage-list { margin: 8px 0 4px; max-height: 60vh; overflow-y: auto; }
.storage-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.storage-head {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 14px;
  margin-bottom: 10px;
}
.storage-users {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  padding-left: 4px;
}
.storage-users .check-label { cursor: pointer; }

.table-wrap { overflow-x: auto; }
#user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#user-table th, #user-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
#user-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
#user-table .user-actions { display: flex; gap: 4px; justify-content: flex-end; }
#user-table .user-actions button {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}
#user-table .user-actions button:hover { background: #eef1f6; }
#user-table .user-actions .danger:hover { color: var(--danger); border-color: var(--danger); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  background: #e7eefc;
  color: var(--accent);
}
.badge.plain { background: #f0f2f6; color: var(--muted); }
.me-note { color: var(--muted); font-size: 12px; }

/* ---------- QR 로그인 ---------- */
.qr-card { text-align: center; }
.qr-desc { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 14px; }
#qr-box {
  display: flex; align-items: center; justify-content: center;
  min-height: 220px;
}
#qr-img {
  width: 220px; height: 220px;
  border: 1px solid var(--border);
  border-radius: 10px;
  image-rendering: pixelated;
  transition: opacity .2s;
}
#qr-img[src=""] { visibility: hidden; }
.qr-status { font-size: 13px; color: var(--muted); margin-top: 12px; min-height: 1.2em; }
.qr-status.ok { color: #1d9e50; font-weight: 600; }
.qr-card .modal-actions { justify-content: center; }

/* ---------- 미리보기 ---------- */
#preview-modal { position: fixed; inset: 0; z-index: 100; }
.preview-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 22, .8); }
.preview-body {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 18px;
}
.preview-top {
  display: flex; align-items: center; justify-content: space-between;
  color: #fff;
  margin-bottom: 12px;
}
.preview-top .btn.subtle { color: #d5dbe6; }
.preview-top .btn.subtle:hover { color: #fff; background: rgba(255,255,255,.12); }
#preview-name { font-size: 15px; word-break: break-all; }
#preview-content {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  min-height: 0;
}
#preview-content img, #preview-content video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}
#preview-content audio { width: min(480px, 90%); }
