:root {
  --accent: #0078d4;
  --accent-dark: #005a9e;
  --bg: #f3f3f3;
  --panel: #ffffff;
  --border: #e1e1e1;
  --text: #1b1b1b;
  --text-dim: #666;
  --hover: #eef6fc;
  --selected: #cce8ff;
  --selected-border: #99d1ff;
  --track-bg: #e6e6e6;
  --row-line: #f2f2f2;
  --overlay: rgba(0,0,0,.35);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #3aa0f3;
    --accent-dark: #1f8ce8;
    --bg: #1e1e1e;
    --panel: #252526;
    --border: #3c3c3c;
    --text: #e6e6e6;
    --text-dim: #a0a0a0;
    --hover: #2a3f52;
    --selected: #264f78;
    --selected-border: #3b82c4;
    --track-bg: #3a3a3a;
    --row-line: #333333;
    --overlay: rgba(0,0,0,.55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --accent: #3aa0f3;
  --accent-dark: #1f8ce8;
  --bg: #1e1e1e;
  --panel: #252526;
  --border: #3c3c3c;
  --text: #e6e6e6;
  --text-dim: #a0a0a0;
  --hover: #2a3f52;
  --selected: #264f78;
  --selected-border: #3b82c4;
  --track-bg: #3a3a3a;
  --row-line: #333333;
  --overlay: rgba(0,0,0,.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Segoe UI", "Noto Sans", Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tbtn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.tbtn:hover:not(:disabled) { background: var(--hover); border-color: var(--border); }
.tbtn:disabled { color: #bbb; cursor: default; }
.tbtn.active { background: var(--selected); border-color: var(--selected-border); }

.sep { width: 1px; align-self: stretch; background: var(--border); margin: 2px 4px; }
.spacer { flex: 1; }
.view-toggle { display: flex; gap: 2px; }

/* ---------- address bar ---------- */
.addressbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  white-space: nowrap;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  min-height: 16px;
}
.breadcrumb .crumb {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--text);
}
.breadcrumb .crumb:hover { background: var(--hover); }
.breadcrumb .crumb.current { font-weight: 600; }
.breadcrumb .arrow { color: var(--text-dim); }

.search-box { display: flex; align-items: center; gap: 6px; }
.search-box input[type=text] {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 220px;
  font-size: 13px;
}
.chk { color: var(--text-dim); font-size: 12px; white-space: nowrap; display:flex; align-items:center; gap:4px;}

/* ---------- main layout ---------- */
.main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.sidebar {
  width: 210px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 0;
  flex-shrink: 0;
}
.side-section-title {
  font-size: 11px;
  color: var(--text-dim);
  padding: 6px 14px 2px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.side-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.side-item:hover { background: var(--hover); }
.side-item.active { background: var(--selected); }
.side-item .icon { font-size: 15px; width: 18px; text-align:center; }
.side-item .label { overflow: hidden; text-overflow: ellipsis; }

.content-wrap {
  flex: 1;
  overflow: auto;
  background: var(--panel);
  position: relative;
}

/* ---------- drives view ---------- */
.drives-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  padding: 20px;
}
.drive-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.drive-card:hover { background: var(--hover); border-color: var(--selected-border); }
.drive-card .drive-head { display: flex; align-items: center; gap: 10px; }
.drive-card .drive-icon { font-size: 28px; }
.drive-card .drive-name { font-weight: 600; }
.drive-card .drive-sub { font-size: 11px; color: var(--text-dim); }
.drive-bar-track {
  height: 7px; border-radius: 4px; background: var(--track-bg); overflow: hidden;
}
.drive-bar-fill { height: 100%; background: var(--accent); }
.drive-bar-fill.warn { background: #e81123; }
.drive-card .drive-space { font-size: 12px; color: var(--text-dim); display: flex; justify-content: space-between; }
.shortcuts-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  padding: 20px 20px 0;
}
.shortcut-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
}
.shortcut-card:hover { background: var(--hover); }
.section-heading { padding: 14px 20px 0; font-weight: 600; color: var(--text-dim); font-size: 12px; text-transform: uppercase; }

/* ---------- file table (list view) ---------- */
.files-view { position: relative; height: 100%; }
.file-table { width: 100%; border-collapse: collapse; user-select: none; }
.file-table thead th {
  position: sticky; top: 0; background: var(--panel);
  text-align: left; font-weight: 600; font-size: 12px; color: var(--text-dim);
  padding: 8px 10px; border-bottom: 1px solid var(--border); cursor: pointer;
  z-index: 1;
}
.file-table thead th:hover { background: var(--hover); }
.sort-ind { font-size: 10px; }
.file-table td { padding: 5px 10px; border-bottom: 1px solid var(--row-line); white-space: nowrap; }
.file-table tr.file-row { cursor: default; }
.file-table tr.file-row:hover { background: var(--hover); }
.file-table tr.file-row.selected { background: var(--selected); }
.file-table tr.file-row.cut { opacity: .5; }
.name-cell { display: flex; align-items: center; gap: 8px; overflow: hidden; width: 100%; }
.name-cell .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.col-date, .col-type, .col-size { color: var(--text-dim); font-size: 12px; }
.col-size { text-align: right; }
.file-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

/* ---------- grid view ---------- */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 4px;
  padding: 12px;
  user-select: none;
}
.grid-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px; border-radius: 6px; cursor: default; text-align: center;
}
.grid-item:hover { background: var(--hover); }
.grid-item.selected { background: var(--selected); }
.grid-item.cut { opacity: .5; }
.grid-item .grid-icon { font-size: 40px; }
.grid-item .grid-name {
  font-size: 12px; word-break: break-word; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.empty-msg { padding: 40px; text-align: center; color: var(--text-dim); }

/* ---------- statusbar ---------- */
.statusbar {
  display: flex; gap: 16px; align-items: center;
  padding: 4px 12px; background: var(--panel); border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
}

/* ---------- context menu ---------- */
.context-menu {
  position: fixed; background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.15); padding: 4px;
  min-width: 180px; z-index: 1000;
}
.context-menu .cm-item {
  padding: 7px 12px; cursor: pointer; border-radius: 4px; white-space: nowrap;
}
.context-menu .cm-item:hover { background: var(--hover); }
.context-menu .cm-item.disabled { color: #bbb; cursor: default; }
.context-menu .cm-item.disabled:hover { background: none; }
.context-menu .cm-sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
.modal-box {
  background: var(--panel); border-radius: 8px; min-width: 340px; max-width: 640px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25); padding: 18px 20px;
}
.modal-box h3 { margin: 0 0 14px; font-size: 15px; }
.modal-box .modal-row { margin-bottom: 12px; }
.modal-box input[type=text], .modal-box textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px;
  font-family: inherit;
}
.modal-box textarea { min-height: 300px; resize: vertical; font-family: Consolas, monospace; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.btn {
  padding: 7px 16px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); cursor: pointer; font-size: 13px;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: #e81123; color: #fff; border-color: #e81123; }
.btn:hover { background: var(--hover); }
.prop-table { border-collapse: collapse; width: 100%; }
.prop-table td { padding: 4px 6px; vertical-align: top; }
.prop-table td:first-child { color: var(--text-dim); white-space: nowrap; width: 110px; }
.prop-img-preview { max-width: 100%; max-height: 60vh; display: block; margin: 0 auto; }
.zip-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.zip-table td { padding: 3px 6px; border-bottom: 1px solid var(--row-line); }
.zip-table td:last-child { text-align: right; color: var(--text-dim); white-space: nowrap; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #323232; color: #fff; padding: 9px 18px; border-radius: 6px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 3000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #a4262c; }

/* ---------- terminal ---------- */
.terminal-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center; z-index: 2500;
}
.terminal-box {
  width: min(960px, 92vw); height: min(560px, 82vh);
  background: #1e1e1e; border-radius: 8px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
}
.terminal-titlebar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: #323233; color: #ddd; font-size: 12px;
}
.terminal-titlebar .tbtn { color: #ddd; padding: 3px 9px; }
.terminal-titlebar .tbtn:hover { background: #e81123; color: #fff; }
#terminal-container { flex: 1; padding: 6px 8px; overflow: hidden; }

/* ---------- browser ---------- */
.browser-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center; z-index: 2500;
}
.browser-box {
  width: min(1200px, 95vw); height: min(820px, 92vh);
  background: var(--panel); border-radius: 8px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
}
.browser-titlebar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.browser-titlebar #browser-address {
  flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 13px; background: var(--bg); color: var(--text);
}
.browser-status { font-size: 11px; color: var(--text-dim); white-space: nowrap; padding: 0 4px; }
.browser-canvas-wrap { position: relative; flex: 1; overflow: hidden; background: #fff; }
.browser-canvas { display: block; width: 100%; height: 100%; cursor: default; outline: none; }
.browser-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 13px; background: #fafafa; pointer-events: none;
  text-align: center; padding: 20px;
}
.rd-picker {
  position: absolute; inset: 0; background: var(--panel); overflow: auto; padding: 16px;
}
.rd-picker h4 { margin: 0 0 12px; font-size: 13px; color: var(--text-dim); font-weight: 600; }
.rd-window-list { display: flex; flex-direction: column; gap: 4px; }
.rd-window-item {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 13px;
}
.rd-window-item:hover { background: var(--hover); }

/* ---------- apps launcher ---------- */
.apps-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: flex-start; justify-content: center; z-index: 2500;
  padding-top: 6vh;
}
.apps-box {
  width: min(1100px, 94vw); height: min(760px, 88vh);
  background: var(--panel); border-radius: 10px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
}
.apps-search-row { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.apps-search-row input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: 999px;
  font-size: 14px; background: var(--bg); color: var(--text);
}
.apps-grid {
  flex: 1; overflow: auto; padding: 24px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 18px 8px;
  align-content: start;
}
.apps-item {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  padding: 10px 6px; border-radius: 10px; cursor: pointer; user-select: none;
}
.apps-item:hover { background: var(--hover); }
.apps-item .apps-icon {
  width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;
  font-size: 32px; border-radius: 10px;
}
.apps-item .apps-icon img { width: 48px; height: 48px; object-fit: contain; }
.apps-item .apps-name {
  font-size: 12px; color: var(--text); word-break: break-word; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 3px solid var(--panel); }
::-webkit-scrollbar-track { background: var(--panel); }
