* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1115; --card: #171a21; --border: #262b36;
  --text: #e6e8ee; --muted: #8a93a5; --accent: #3b82f6;
  --input: #0d0f14; --btn: #222834; --hover: #1b202a;
  --sel-bg: rgba(59,130,246,.12); --overlay: rgba(0,0,0,.55);
  --pbar-bg: #0d0f14; --action-bg: rgba(0,0,0,.68);
  --danger: #dc2626;
}
html[data-theme="light"] {
  --bg: #f4f6fa; --card: #ffffff; --border: #e1e5ee;
  --text: #1f2430; --muted: #64708a; --accent: #2563eb;
  --input: #eef1f6; --btn: #e6eaf1; --hover: #eef1f7;
  --sel-bg: rgba(37,99,235,.10); --overlay: rgba(15,17,21,.4);
  --pbar-bg: #e6eaf1; --action-bg: rgba(255,255,255,.85);
}
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, sans-serif; transition: background .2s, color .2s; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.err { color: #f87171; }

.view { min-height: 100vh; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }

.login-card { max-width: 360px; margin: 15vh auto; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { text-align: center; }
.login-card .btn { width: 100%; justify-content: center; }

input, select, textarea { background: var(--input); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 9px 12px; }
textarea { font-family: ui-monospace, monospace; font-size: 12px; }

.btn { padding: 9px 16px; border-radius: 6px; border: 1px solid var(--border); background: var(--btn); color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { padding: 7px 8px; }
.icon-btn svg { width: 17px; height: 17px; }

@keyframes pulse { 0% { opacity: .5; } 50% { opacity: 1; } 100% { opacity: .5; } }

.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--card); }
.brand { font-weight: 700; font-size: 17px; color: var(--accent); }
.tab { background: transparent; border: none; color: var(--muted); padding: 8px 12px; cursor: pointer; border-radius: 6px; }
.tab.active { background: var(--btn); color: var(--text); }

/* ---- top loading bar (Google Drive style) ---- */
.loadbar { position: fixed; top: 0; left: 0; width: 100%; height: 3px; z-index: 300; overflow: hidden; }
.loadbar-inner { height: 100%; width: 35%; background: var(--accent); border-radius: 2px; animation: slide 1s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

.panel { max-width: 1000px; margin: 18px auto; padding: 0 14px; }
.toolbar, .drivebar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
#crumb { font-size: 13px; color: var(--muted); word-break: break-all; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr:hover { background: var(--hover); }
tbody tr.selected { background: var(--sel-bg); }
td.actions { text-align: right; white-space: nowrap; }
.file-row { cursor: pointer; }

/* ---- svg icons ---- */
.ic { display: inline-flex; vertical-align: middle; }
.ic svg { width: 18px; height: 18px; }
.icon { margin-right: 8px; }
.icon svg { width: 17px; height: 17px; vertical-align: -3px; }
.big-icon svg { width: 52px; height: 52px; }
.big-icon { display: flex; }
.card-actions a, .card-actions button { display: inline-flex; align-items: center; justify-content: center; }
.card-actions svg { width: 14px; height: 14px; }

.modal { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { position: relative; width: min(520px, 92vw); display: flex; flex-direction: column; gap: 12px; }
.modal-box.wide { width: min(900px, 94vw); }
.modal-x {
  position: absolute; top: 10px; right: 12px; z-index: 5;
  background: transparent; border: none; color: var(--muted);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 6px; border-radius: 6px;
}
.modal-x:hover { background: var(--hover); color: var(--text); }
.modal-box form { display: flex; flex-direction: column; gap: 12px; }
.modal-box h2 { font-size: 17px; padding-right: 24px; }
.modal-box label { font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.preview-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.preview-img { max-width: 100%; max-height: 62vh; object-fit: contain; border-radius: 6px; }
.preview-frame { width: 100%; height: 68vh; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.preview-text {
  width: 100%; max-height: 62vh; overflow: auto; text-align: left;
  background: var(--input); border: 1px solid var(--border); border-radius: 6px;
  padding: 12px; font: 12px/1.5 ui-monospace, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.preview-info { color: var(--muted); font-size: 13px; text-align: center; }

/* ---- selection bar ---- */
.selbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--accent);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 12px;
}
.selbar span { font-weight: 600; }

/* ---- grid view (Google Drive style) ---- */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 14px 12px; margin-top: 4px; }
.file-card { cursor: pointer; user-select: none; }
.file-card .card-thumb {
  position: relative;
  aspect-ratio: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.file-card .card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-card .card-name {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.35;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.file-card:hover .card-thumb { border-color: var(--accent); box-shadow: 0 2px 8px rgba(59,130,246,.25); }
.card-actions {
  position: absolute; top: 5px; right: 5px;
  display: none; gap: 4px;
}
.file-card:hover .card-actions { display: flex; }
.card-actions button {
  background: var(--action-bg); color: var(--text); border: none; border-radius: 5px;
  width: 26px; height: 26px; cursor: pointer; line-height: 1; text-decoration: none;
}
.card-actions button:hover { background: var(--accent); color: #fff; }
.card-check {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  width: 18px; height: 18px; accent-color: var(--accent);
  opacity: 0; cursor: pointer;
}
.file-card:hover .card-check, .file-card.selected .card-check { opacity: 1; }
.file-card.selected .card-thumb { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.file-card.selected .card-name { color: var(--accent); }
.file-row .row-check { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.view-toggle { display: flex; gap: 4px; }
.view-toggle .btn { padding: 7px 9px; }
.view-toggle svg { width: 16px; height: 16px; }
.view-toggle .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- progress panel ---- */
.progress-list { display: flex; flex-direction: column; gap: 10px; max-height: 46vh; overflow-y: auto; }
.prow { display: grid; grid-template-columns: 1fr 70px; align-items: center; gap: 8px; font-size: 13px; }
.pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pbar { grid-column: 1 / 2; background: var(--pbar-bg); border: 1px solid var(--border); border-radius: 6px; height: 10px; overflow: hidden; }
.pfill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  box-shadow: 0 0 6px rgba(59,130,246,.6);
  width: 0;
  transition: width .2s;
}
.pfill.busy { width: 35%; animation: slide 1s ease-in-out infinite; }
.pstat { grid-column: 2 / 3; grid-row: 1; text-align: right; color: var(--muted); white-space: nowrap; }
.prow .pstat.err { color: #f87171; }
.prow .pstat.done { color: #4ade80; }

#backend-list, #user-list { font-size: 13px; }
section.card { margin-bottom: 18px; }
section.card h2 { margin-bottom: 12px; font-size: 16px; }
