:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e4e7ec;
  --text: #1f2430;
  --muted: #7a828f;
  --accent: #f6821f;
  --accent-dark: #d96d10;
  --danger: #e14b4b;
  --hover: #f0f2f5;
  --selected: #fff3e6;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
body {
  margin: 0; height: 100vh; display: flex; flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); }

/* Header + Tabs */
header {
  background: linear-gradient(90deg, #2b2f38, #1f2430);
  color: #fff; padding: 0 20px; display: flex; align-items: center; gap: 24px; height: 52px; flex-shrink: 0;
}
.brand { font-size: 16px; font-weight: 700; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: none; border: none; color: #b9bfca; padding: 8px 16px; border-radius: 7px;
  cursor: pointer; font-size: 14px; font-weight: 500;
}
.tab:hover { background: rgba(255,255,255,.08); color: #fff; }
.tab.active { background: var(--accent); color: #fff; }

.layout { flex: 1; display: flex; min-height: 0; }

/* Sidebar */
#sidebar {
  width: 280px; background: var(--panel); border-right: 1px solid var(--border);
  overflow-y: auto; flex-shrink: 0;
}
.sidebar-head {
  padding: 12px 16px; font-weight: 600; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 1;
}
.account { border-bottom: 1px solid var(--border); }
.account-name { padding: 10px 14px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 8px; user-select: none; }
.account-name:hover { background: var(--hover); }
.arrow { color: var(--muted); font-size: 11px; width: 12px; }
.acc-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bucket-list { padding-bottom: 6px; }
.bucket {
  padding: 7px 14px 7px 32px; cursor: pointer; display: flex; align-items: center;
  justify-content: space-between; gap: 6px;
}
.bucket:hover { background: var(--hover); }
.bucket.active { background: var(--selected); color: var(--accent-dark); font-weight: 600; }
.bucket-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bucket-meta { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.side-msg { padding: 8px 32px; font-size: 12px; color: var(--muted); }

#main { flex: 1; overflow-y: auto; min-width: 0; position: relative; }
.view { padding: 20px; min-height: 100%; }
#view-browser.drag { outline: 3px dashed var(--accent); outline-offset: -12px; }

.center-msg { display: flex; align-items: center; justify-content: center; min-height: 300px; color: var(--muted); text-align: center; }

/* Buttons */
button { font-family: inherit; }
.btn, button.primary, button.danger, .btn-sm, .btn-xs {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.btn:hover, .btn-sm:hover, .btn-xs:hover { background: var(--hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.danger, .btn-xs.danger, .btn-sm.danger { color: var(--danger); border-color: #f2c6c6; }
button.danger:hover:not(:disabled), .btn-xs.danger:hover, .btn-sm.danger:hover { background: #fdeaea; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 12px; margin-left: 4px; }

/* Dashboard / panels */
.dash-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dash-head h2 { margin: 0; font-size: 20px; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); }
.stat-card.warn { border-color: #f2d19a; background: #fffaf0; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 700; margin: 4px 0; }
.stat-sub { font-size: 12px; color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.panel-head h3 { margin: 0; font-size: 15px; }
.hint { font-size: 12px; margin: 8px 0 0; }

/* Bar chart */
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr auto; align-items: center; gap: 10px; }
.bar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--hover); border-radius: 5px; height: 16px; overflow: hidden; }
.bar-fill { background: linear-gradient(90deg, var(--accent), #ffb066); height: 100%; border-radius: 5px; }
.bar-val { font-size: 12px; color: var(--text); white-space: nowrap; }
.bar-sub { color: var(--muted); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--hover); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 12px; }

/* Donut */
.donut-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.donut { width: 160px; height: 160px; flex-shrink: 0; }
.legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Mini table */
.mini-table { width: 100%; border-collapse: collapse; }
.mini-table th, .mini-table td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.mini-table th { color: var(--muted); font-weight: 600; font-size: 12px; }

/* Clean lists */
.clean-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.clean-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--border); }
.clean-row:last-child { border-bottom: none; }
.clean-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.clean-name.link { color: var(--accent-dark); cursor: pointer; }
.clean-name.link:hover { text-decoration: underline; }
.clean-sub { font-size: 12px; white-space: nowrap; }
.dup-group { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.dup-head { display: flex; align-items: center; justify-content: space-between; background: var(--hover); padding: 7px 12px; font-size: 13px; }
.dup-row { grid-template-columns: auto 1fr; }

/* Browser toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.breadcrumb { font-size: 14px; }
.breadcrumb .crumb { cursor: pointer; color: var(--accent-dark); }
.breadcrumb .crumb:hover { text-decoration: underline; }
.breadcrumb .sep { margin: 0 6px; color: var(--muted); }
.toolbar-actions { display: flex; gap: 8px; align-items: center; }
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.view-toggle button { border: none; border-radius: 0; padding: 6px 10px; background: var(--panel); }
.view-toggle button.active { background: var(--accent); color: #fff; }

/* Grid view */
.grid-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; position: relative; transition: box-shadow .15s; box-shadow: var(--shadow); }
.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.card.selected { outline: 2px solid var(--accent); }
.card-thumb { height: 120px; display: flex; align-items: center; justify-content: center; font-size: 44px; background: var(--hover); overflow: hidden; }
.card-thumb.folder-thumb { background: #fff6ea; }
.thumb-img { width: 100%; height: 100%; object-fit: cover; }
.card-name { padding: 8px 10px 2px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { padding: 0 10px 8px; font-size: 11px; color: var(--muted); }
.card-check { position: absolute; top: 8px; left: 8px; width: 16px; height: 16px; z-index: 2; }

/* List view */
.list-view { display: flex; flex-direction: column; }
.lrow { display: grid; grid-template-columns: 32px 1fr 110px 180px 200px; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.lrow.lhead { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--bg); }
.lrow:hover:not(.lhead) { background: var(--hover); }
.lrow.selected { background: var(--selected); }
.lc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lc-name.link, .lc-name.folder-link { cursor: pointer; color: var(--accent-dark); }
.lc-name.link:hover, .lc-name.folder-link:hover { text-decoration: underline; }
.lc-act { text-align: right; }

.load-more { display: block; margin: 16px auto; padding: 8px 24px; }

/* Preview modal */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.72); }
.modal-box { position: relative; z-index: 1; width: 92vw; height: 90vh; background: #16181d; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; color: #fff; background: #1f2228; }
.modal-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-head-actions { display: flex; gap: 8px; }
.modal-head-actions .btn-sm { background: #2b2f38; color: #fff; border-color: #3a3f4a; text-decoration: none; }
.modal-body { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 12px; }
.preview-media { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-media.pdf { width: 100%; height: 100%; border: none; background: #fff; }
.preview-text { color: #d6d9df; font-size: 12px; white-space: pre-wrap; word-break: break-all; max-width: 100%; max-height: 100%; overflow: auto; text-align: left; font-family: ui-monospace, Menlo, monospace; }
.preview-audio { display: flex; flex-direction: column; align-items: center; gap: 20px; color: #fff; }
.audio-icon { font-size: 80px; }
.preview-none { color: #aeb3bd; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.preview-none .btn { background: var(--accent); color: #fff; border: none; text-decoration: none; }
.preview-loading { color: #aeb3bd; }
.modal-meta { padding: 8px 16px; color: #9aa0ab; font-size: 12px; text-align: center; background: #1f2228; }
.modal-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; background: rgba(0,0,0,.4); color: #fff; border: none; font-size: 34px; width: 48px; height: 72px; cursor: pointer; }
.modal-nav:hover { background: rgba(0,0,0,.7); }
.modal-nav.prev { left: 8px; border-radius: 0 8px 8px 0; }
.modal-nav.next { right: 8px; border-radius: 8px 0 0 8px; }

/* Toast + spinner */
#toast { position: fixed; bottom: 24px; right: 24px; background: #2b2f38; color: #fff; padding: 12px 18px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 380px; z-index: 300; }
#toast.error { background: var(--danger); }
#toast.success { background: #2e9e5b; }
.spinner { border: 2px solid #ddd; border-top-color: var(--accent); border-radius: 50%; width: 16px; height: 16px; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
