:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --ink: #1f2937;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #2457c5;
  --accent-soft: #eef4ff;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---- brand ---- */
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 16px; letter-spacing: -.01em;
}
.brand em { color: var(--muted); font-style: normal; font-weight: 500; margin-left: 2px; }
.brand-dot {
  width: 11px; height: 11px; border-radius: 4px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---- login ---- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
  padding: 28px 26px; display: flex; flex-direction: column; gap: 14px;
}
.login-card .brand { font-size: 18px; }
.login-sub { margin: -4px 0 6px; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; color: var(--ink); background: #fff; outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-err { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 58px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.lib-tabs { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.lib-tab {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  font-size: 13px; font-weight: 600; transition: .12s;
}
.lib-tab:hover { border-color: #cdd3dd; color: var(--ink); }
.lib-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.lib-tab .type { opacity: .7; font-weight: 500; margin-left: 5px; font-size: 11px; }

/* ---- layout ---- */
.cols {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
  padding: 18px 20px; max-width: 1400px; margin: 0 auto;
  align-items: start;
}
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 320px;
  max-height: calc(100vh - 96px);
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 700; margin-right: auto; }
.badge {
  font-size: 11px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); padding: 2px 8px; border-radius: 999px;
}

/* ---- crumbs ---- */
.crumbs {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
  padding: 10px 16px 0; font-size: 12.5px; color: var(--muted);
}
.crumbs .crumb { cursor: pointer; padding: 3px 6px; border-radius: 6px; color: var(--accent); }
.crumbs .crumb:hover { background: var(--accent-soft); }
.crumbs .crumb.cur { color: var(--ink); cursor: default; font-weight: 600; }
.crumbs .crumb.cur:hover { background: transparent; }
.crumbs .sep { color: #c3c9d2; }

/* ---- search ---- */
.search { padding: 10px 16px; }
.search input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 13.5px; outline: none; background: #fff;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- scan bar ---- */
.scan-bar {
  display: flex; align-items: center; gap: 12px;
  margin: 0 16px 12px; padding: 12px 14px;
  background: var(--accent-soft); border: 1px solid #d5e2fb; border-radius: 9px;
}
.scan-info { min-width: 0; flex: 1; }
.scan-path { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---- lists ---- */
.list {
  list-style: none; margin: 0; padding: 4px 8px 12px;
  overflow-y: auto; flex: 1;
}
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.row:hover { background: #f6f8fb; }
.row .ico { color: var(--muted); flex-shrink: 0; display: flex; }
.row .label { flex: 1; min-width: 0; }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.row .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.row .chev { color: #c3c9d2; }
.icon-btn {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--muted); cursor: pointer; padding: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.icon-btn:disabled { opacity: .6; cursor: default; }

.row.up { color: var(--accent); }
.row.up .name { font-weight: 600; }
.row.up:hover { background: var(--accent-soft); }
.row.leaf { cursor: default; }
.row.leaf:hover { background: transparent; }
.row .acts { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.done-label {
  font-size: 12px; font-weight: 700; color: var(--ok);
  background: var(--ok-soft); padding: 5px 10px; border-radius: 7px; white-space: nowrap;
}
.copy-prog {
  font-size: 12px; font-weight: 600; color: #0e9384;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.copy-prog em { color: var(--muted); font-style: normal; font-weight: 500; }
.copy-prog.ok { color: var(--ok); }

/* item cards */
.item {
  border: 1px solid var(--line); border-radius: 9px;
  margin: 6px 4px; padding: 11px 12px; cursor: default;
}
.item-head { display: flex; align-items: center; gap: 10px; }
.item-title { flex: 1; min-width: 0; }
.item-title .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-title .m { font-size: 12px; color: var(--muted); margin-top: 2px; }
.type-tag {
  font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: #eef1f5; color: var(--muted); flex-shrink: 0;
}
.type-tag.show { background: var(--accent-soft); color: var(--accent); }
.files {
  margin: 9px 0 0; padding: 8px 0 0; border-top: 1px dashed var(--line);
  display: none;
}
.files.open { display: block; }
.file-row {
  display: flex; gap: 8px; font-size: 12.5px; color: var(--muted);
  padding: 3px 0;
}
.file-row .fn { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.file-row .fs { flex-shrink: 0; }
.link { color: var(--accent); cursor: pointer; font-size: 12px; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ---- buttons ---- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600;
  font-size: 13px; font-family: inherit; transition: .12s; white-space: nowrap;
}
.btn:hover { border-color: #cdd3dd; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1e49a8; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f3c6c1; background: var(--danger-soft); }
.btn.danger:hover { background: #fde3df; }
.btn.alt { background: #0e9384; border-color: #0e9384; color: #fff; }
.btn.alt:hover { background: #0b7c6f; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.block { width: 100%; padding: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.empty { padding: 30px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.spin {
  width: 15px; height: 15px; border: 2px solid #fff; border-top-color: transparent;
  border-radius: 50%; display: inline-block; animation: sp .7s linear infinite; vertical-align: -2px;
}
@keyframes sp { to { transform: rotate(360deg); } }

/* ---- toasts ---- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  background: #101828; color: #fff; padding: 11px 15px; border-radius: 9px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(16,24,40,.18);
  max-width: 360px; animation: slideIn .18s ease;
}
.toast.ok { background: #05603a; }
.toast.err { background: #912018; }
@keyframes slideIn { from { transform: translateY(8px); opacity: 0; } }

/* ---- modal ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(16,24,40,.35);
  display: grid; place-items: center; z-index: 90; padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; padding: 22px; max-width: 400px; width: 100%;
  box-shadow: 0 20px 48px rgba(16,24,40,.24);
}
.modal.wide { max-width: 520px; }
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.modal p { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.fld { margin-bottom: 14px; }
.fld > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.fld input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; outline: none; font-family: inherit;
}
.fld input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: #fff; color: var(--muted); padding: 8px 20px; cursor: pointer;
  font-weight: 600; font-size: 13px; font-family: inherit;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }

.picker { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.picker-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: #f6f8fb; border-bottom: 1px solid var(--line);
}
.picker-cur {
  flex: 1; min-width: 0; font-size: 12.5px; color: var(--ink); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.picker-list { max-height: 240px; padding: 4px; }
.picked { margin-top: 10px; font-size: 13px; color: var(--muted); }
.picked b { color: var(--accent); word-break: break-all; }
.picked em { font-style: normal; }

/* topbar buttons */
#addLib, #gdriveRefresh, #logout { flex-shrink: 0; }
