:root {
  --bg: #0f1218;
  --panel: #171b24;
  --panel-2: #1f2431;
  --panel-3: #262d3d;
  --line: #2a3143;
  --text: #e6e8ee;
  --muted: #8892a6;
  --brand: #ff5a1f;
  --brand-2: #ffb200;
  --ok: #22c55e;
  --danger: #ef4444;
  --selected: rgba(255, 90, 31, 0.18);
  --selected-border: #ff5a1f;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 13px; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* App shell */
.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 0; }
.brand { padding: 0 20px 18px 20px; font-size: 20px; font-weight: 700; letter-spacing: 0.5px; color: var(--brand); border-bottom: 1px solid var(--line); }
.nav { display: flex; flex-direction: column; padding: 12px 0; flex: 1; }
.nav a { padding: 10px 20px; color: var(--text); font-weight: 500; font-size: 13px; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: var(--panel-2); border-left: 3px solid var(--brand); padding-left: 17px; }
.nav a.disabled { color: var(--muted); cursor: not-allowed; }
.nav-section { padding: 18px 20px 6px 20px; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.nav-footer { padding: 16px 20px; border-top: 1px solid var(--line); }
.nav-footer .user { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.nav-footer .linkish { background: none; border: none; color: var(--brand-2); padding: 0; font-size: 12px; }

/* Content */
.content { padding: 0; overflow: hidden; height: 100vh; display: flex; flex-direction: column; }
.page-head { display: flex; align-items: baseline; gap: 14px; padding: 20px 26px 12px 26px; }
.page-head h1 { margin: 0; font-size: 20px; font-weight: 600; }
.bucket-badge { background: var(--panel-2); border: 1px solid var(--line); padding: 3px 10px; border-radius: 12px; color: var(--muted); font-family: monospace; font-size: 11px; }

/* Dashboard cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; padding: 0 26px 26px 26px; }
.card { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; transition: border-color 0.15s; }
.card:hover:not(.disabled) { border-color: var(--brand); }
.card.disabled { opacity: 0.55; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.card-sub { color: var(--muted); font-size: 13px; line-height: 1.5; }

/* Login */
.login-page { background: linear-gradient(140deg, #0f1218 0%, #1f2431 100%); }
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 36px 40px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,0.4); }
.brand-lg { font-size: 28px; font-weight: 700; color: var(--brand); text-align: center; margin-bottom: 24px; letter-spacing: 0.5px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.login-card input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; color: var(--text); font-size: 14px; }
.login-card input:focus { outline: none; border-color: var(--brand); }
.err { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--danger); color: #fca5a5; padding: 8px 10px; border-radius: 6px; font-size: 12px; margin-bottom: 12px; }
button.primary { display: block; width: 100%; padding: 10px 14px; background: var(--brand); color: white; border: none; border-radius: 6px; font-weight: 600; margin-top: 8px; }
button.primary:hover { background: #e04a10; }

/* ===================== EXPLORER (Windows-Explorer style) ===================== */
.explorer { flex: 1; display: grid; grid-template-columns: 260px 1fr; overflow: hidden; }

/* Folder tree */
.tree-pane { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; }
.tree-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 600; }
.tree-head button { background: none; border: none; color: var(--muted); font-size: 14px; padding: 2px 6px; }
.tree-head button:hover { color: var(--text); }
.tree, .tree-children { list-style: none; margin: 0; padding: 0; }
.tree-children { padding-left: 16px; display: none; }
.tree-children.open { display: block; }
.tree-item { display: flex; align-items: center; gap: 4px; padding: 4px 10px 4px 6px; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; user-select: none; }
.tree-item:hover { background: var(--panel-2); }
.tree-item.selected { background: var(--selected); color: var(--brand-2); }
.tree-chevron { display: inline-block; width: 12px; color: var(--muted); font-size: 10px; text-align: center; transition: transform 0.15s; }
.tree-chevron.empty { visibility: hidden; }
.tree-chevron.open { transform: rotate(0); }
.tree-chevron.closed { transform: rotate(-90deg); }
.tree-icon { font-size: 14px; }
.tree-name { overflow: hidden; text-overflow: ellipsis; }
.tree-loading { padding: 6px 12px; color: var(--muted); font-size: 11px; font-style: italic; }

/* Files pane */
.files-pane { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

/* Toolbar / address bar */
.explorer-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tb-btn { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 4px; padding: 4px 10px; font-size: 14px; min-width: 30px; }
.tb-btn:hover:not(:disabled) { background: var(--panel-3); border-color: var(--brand); }
.tb-btn:disabled { opacity: 0.4; cursor: default; }
.address-bar { flex: 1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 5px 10px; display: flex; align-items: center; gap: 4px; font-size: 12px; overflow: hidden; white-space: nowrap; }
.addr-seg { color: var(--text); padding: 2px 4px; border-radius: 3px; }
.addr-seg:hover { background: var(--panel-3); color: var(--brand-2); }
.addr-sep { color: var(--muted); margin: 0 2px; }
.view-modes { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.vm-btn { background: var(--panel-2); border: none; color: var(--muted); padding: 4px 10px; font-size: 14px; }
.vm-btn.active { background: var(--brand); color: white; }
.vm-btn:hover:not(.active) { background: var(--panel-3); color: var(--text); }
.search { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 4px; padding: 4px 10px; font-size: 12px; width: 200px; }
.search:focus { outline: none; border-color: var(--brand); }

.explorer-actions { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.explorer-actions button { padding: 5px 12px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 4px; font-size: 12px; }
.explorer-actions button.primary { background: var(--brand); border-color: var(--brand); color: white; }
.explorer-actions button:hover:not(.primary) { background: var(--panel-3); }
.explorer-actions .hint { margin-left: auto; color: var(--muted); font-size: 11px; }

/* Icons view */
.grid { flex: 1; overflow-y: auto; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; align-content: start; }
.grid[hidden] { display: none; }
.tile { padding: 8px 4px 6px 4px; text-align: center; cursor: pointer; border-radius: 4px; border: 1px solid transparent; user-select: none; }
.tile:hover { background: var(--panel-2); }
.tile.selected { background: var(--selected); border-color: var(--selected-border); }
.thumb { height: 96px; display: flex; align-items: center; justify-content: center; margin-bottom: 6px; overflow: hidden; }
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 2px; }
.folder-thumb { font-size: 56px; }
.tile .name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }
.tile .meta { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* Details view (table) */
.details { flex: 1; overflow-y: auto; width: 100%; border-collapse: collapse; background: var(--bg); }
.details[hidden] { display: none; }
.details thead { position: sticky; top: 0; background: var(--panel); z-index: 5; }
.details th { text-align: left; padding: 8px 12px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.details th:hover { color: var(--text); background: var(--panel-2); }
.details th .sort-ind { display: inline-block; width: 12px; color: var(--brand); font-size: 10px; }
.details td { padding: 6px 12px; border-bottom: 1px solid rgba(42, 49, 67, 0.3); font-size: 12px; }
.details tbody tr { cursor: pointer; user-select: none; }
.details tbody tr:hover { background: var(--panel-2); }
.details tbody tr.selected { background: var(--selected); }
.details .col-name { width: 45%; }
.details .col-modified { width: 22%; color: var(--muted); }
.details .col-type { width: 15%; color: var(--muted); }
.details .col-size { width: 18%; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.details .row-icon { display: inline-block; margin-right: 8px; font-size: 14px; }

/* Status bar */
.status-bar { display: flex; align-items: center; gap: 20px; padding: 6px 14px; background: var(--panel); border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.status-bar .status-right { margin-left: auto; font-family: monospace; }

/* Context menu */
.context-menu { position: fixed; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,0.6); z-index: 1000; min-width: 180px; }
.context-menu button { display: block; width: 100%; text-align: left; padding: 6px 12px; background: none; border: none; color: var(--text); border-radius: 3px; font-size: 12px; }
.context-menu button:hover { background: var(--panel-3); }
.context-menu button.danger { color: #fca5a5; }
.context-menu button.danger:hover { background: rgba(239,68,68,0.2); }
.context-menu hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

/* Modal */
.modal-shell { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 500; }
.modal-shell[hidden] { display: none; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; min-width: 520px; max-width: 90vw; max-height: 88vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.modal-head #modal-title { flex: 1; font-weight: 600; font-size: 14px; }
.modal-head #modal-close { background: none; border: none; color: var(--muted); font-size: 22px; padding: 0 8px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-body img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; }
.history-row { display: grid; grid-template-columns: 24px 1fr 100px 100px 130px; gap: 10px; padding: 8px; border-bottom: 1px solid var(--line); align-items: center; font-size: 12px; }
.history-row:last-child { border: none; }
.history-row .badge-current { color: var(--ok); font-size: 10px; font-weight: 600; }
.history-row .badge-deleted { color: var(--danger); font-size: 10px; font-weight: 600; }
.history-row button { padding: 4px 10px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 4px; font-size: 11px; }
.history-row button.primary { background: var(--brand); border-color: var(--brand); color: white; }
