: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; }
.sidebar-toggle { background: rgba(255,255,255,.1); border: none; color: #fff; width: 30px; height: 30px; border-radius: 7px; cursor: pointer; font-size: 15px; }
.sidebar-toggle:hover { background: rgba(255,255,255,.2); }
.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: 14px; text-align: center; flex-shrink: 0; }
.acc-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bucket-list { padding-bottom: 6px; }
.bucket { padding: 6px 14px 6px 16px; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.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; flex: 1; }
.bucket-meta { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.bucket .arrow, .folder-item .arrow { cursor: pointer; border-radius: 3px; }
.bucket .arrow:hover, .folder-item .arrow:hover { background: rgba(0,0,0,.1); }
.folder-item { padding: 5px 14px 5px 16px; cursor: pointer; display: flex; align-items: center; gap: 4px; font-size: 13px; }
.folder-item:hover { background: var(--hover); }
.folder-item.active { background: var(--selected); color: var(--accent-dark); font-weight: 600; }
.folder-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-msg { padding: 8px 20px; font-size: 12px; color: var(--muted); }
.side-msg.sub { padding-left: 42px; }

#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; }

.ins-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }

/* 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; gap: 10px; background: var(--hover); padding: 7px 12px; font-size: 13px; flex-wrap: wrap; }
.dup-head > div:last-child { margin-left: auto; }
.dup-head.review { background: #fff6e0; }
.review-msg { font-size: 11px; color: #b8860b; }
.dup-panel-head { flex-wrap: wrap; gap: 10px; }
.dup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dup-summary { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.review-note { color: #b8860b; margin-left: 4px; }
.dup-row { grid-template-columns: auto 1fr auto; }
.dup-usage { font-size: 12px; white-space: nowrap; }
.dup-usage.used { color: #2e9e5b; font-weight: 600; }
.dup-usage.unused { color: var(--muted); }
.dup-row.keep-row { background: #eafaf0; }

/* Browser toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-left { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.count-line { font-size: 12px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.sel-count { color: var(--accent-dark); font-weight: 600; }
.bucket-domain { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.domain-chip { font-size: 12px; background: #eef6ff; color: #1a6fd4; border: 1px solid #d3e6fb; border-radius: 20px; padding: 2px 10px; text-decoration: none; }
.domain-chip:hover { background: #dcecfd; }
.link-btn { border: none; background: none; color: var(--accent-dark); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.link-btn:hover { text-decoration: underline; }

/* 側邊欄 bucket 網域 */
.bucket-domain-line { padding: 0 14px 4px 34px; display: flex; flex-direction: column; gap: 2px; }
.side-domain { font-size: 11px; color: #1a6fd4; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-domain:hover { text-decoration: underline; }

/* 網域管理彈窗 */
.dom-section { padding: 14px 0; border-bottom: 1px solid var(--border); }
.dom-section:last-child { border-bottom: none; }
.dom-sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dom-sec-head h4 { margin: 0; font-size: 14px; }
.dom-url { color: var(--accent-dark); text-decoration: none; font-size: 13px; word-break: break-all; }
.dom-url:hover { text-decoration: underline; }
.warn-text { color: #b8860b; margin-top: 6px; }
.dom-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.dom-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.dom-item-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dom-status { font-size: 11px; color: var(--muted); }
.dom-status.ok { color: #2e9e5b; }
.dom-item-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.dom-add { display: flex; gap: 8px; margin-bottom: 6px; }

/* 開關 switch */
.switch { width: 44px; height: 24px; border-radius: 12px; background: #ccc; border: none; position: relative; cursor: pointer; padding: 0; transition: background .15s; flex-shrink: 0; }
.switch.on { background: #2e9e5b; }
.switch.small { width: 38px; height: 20px; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: left .15s; }
.switch.small .knob { width: 16px; height: 16px; }
.switch.on .knob { left: 22px; }
.switch.small.on .knob { left: 20px; }
.ctrl { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 5px 8px; border-radius: 6px; font-size: 13px; font-family: inherit; }
.ctrl.search { width: 150px; }
.ctrl:focus { outline: none; border-color: var(--accent); }
.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; flex-wrap: wrap; justify-content: flex-end; }
.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; }
.card-info { position: absolute; top: 6px; right: 6px; z-index: 2; border: none; background: rgba(0,0,0,.45); color: #fff; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; cursor: pointer; padding: 0; line-height: 22px; }
.card-info:hover { background: rgba(0,0,0,.75); }
.card-actions { position: absolute; left: 6px; right: 6px; top: 88px; z-index: 2; display: none; justify-content: center; gap: 6px; }
.card:hover .card-actions { display: flex; }
.card-act { border: none; background: rgba(0,0,0,.55); color: #fff; width: 28px; height: 28px; border-radius: 7px; font-size: 13px; cursor: pointer; padding: 0; }
.card-act:hover { background: rgba(0,0,0,.85); }
.card-act.danger:hover { background: var(--danger); }

/* Detail modal */
.detail-box { position: relative; z-index: 1; width: 640px; max-width: 94vw; max-height: 88vh; background: var(--panel); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.detail-box .modal-head { background: #1f2228; }
.detail-body { padding: 8px 20px 20px; overflow-y: auto; }
.detail-row { display: grid; grid-template-columns: 150px 1fr auto; gap: 12px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.detail-label { color: var(--muted); font-size: 13px; padding-top: 2px; }
.detail-val { font-size: 13px; }
.detail-val.link { color: var(--accent-dark); text-decoration: none; }
.detail-val.link:hover { text-decoration: underline; }
.detail-sep { grid-column: 1 / -1; margin: 14px 0 2px; font-weight: 600; font-size: 13px; color: var(--text); }
.copy-btn { align-self: start; }

/* 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: 16px; color: #fff; }
.audio-icon { font-size: 80px; }
.audio-name { color: #c9ced6; font-size: 14px; max-width: 70vw; text-align: center; word-break: break-all; }
.preview-audio audio { width: min(520px, 80vw); }
.preview-hd { position: absolute; bottom: 60px; right: 20px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 6px 12px; border-radius: 20px; display: flex; align-items: center; gap: 6px; }
.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); } }
