/* ============================================================
   HDB Web File Explorer – Apple Finder-inspired styles
   Bootstrap 5 companion stylesheet
   ============================================================ */

:root {
  --fe-bg: #f0f0f0;
  --fe-sidebar-bg: #e4e4e4;
  --fe-toolbar-bg: #f5f5f5;
  --fe-border: #c8c8c8;
  --fe-column-border: #d0d0d0;
  --fe-text: #1c1c1e;
  --fe-text-muted: #6c6c70;
  --fe-selection: #2b70c9;
  --fe-selection-light: rgba(43, 112, 201, 0.12);
  --fe-hover: rgba(0,0,0,0.06);
  --fe-icon-folder: #5b9bd5;
  --fe-icon-file: #8e8e93;
  --fe-header-height: 44px;
  --fe-sidebar-width: 180px;
  --fe-statusbar-height: 26px;
  --fe-column-width: 220px;
  --fe-radius: 10px;
  --fe-shadow: 0 4px 24px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.10);
}

/* ── Window ─────────────────────────────────────────────── */
.fe-window {
  display: flex;
  flex-direction: column;
  background: var(--fe-bg);
  border-radius: var(--fe-radius);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: var(--fe-text);
  border: 1px solid var(--fe-border);
  box-shadow: var(--fe-shadow);
  min-width: 520px;
  min-height: 300px;
  height: 100%;
  width: 100%;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* ── Titlebar ────────────────────────────────────────────── */
.fe-titlebar {
  display: flex;
  align-items: center;
  height: var(--fe-header-height);
  background: linear-gradient(to bottom, #f8f8f8, #ebebeb);
  border-bottom: 1px solid var(--fe-border);
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  user-select: none;
}

.fe-traffic-lights {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.fe-tl {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: transparent;
  transition: filter 0.1s;
  padding: 0;
}
.fe-tl:hover { color: rgba(0,0,0,0.5); }
.fe-tl-close  { background: #ff5f57; }
.fe-tl-min    { background: #febc2e; }
.fe-tl-max    { background: #28c840; }

.fe-title-text {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--fe-text);
  letter-spacing: -0.01em;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.fe-toolbar {
  display: flex;
  align-items: center;
  height: 40px;
  background: var(--fe-toolbar-bg);
  border-bottom: 1px solid var(--fe-border);
  padding: 0 10px;
  gap: 6px;
  flex-shrink: 0;
}

.fe-toolbar-btn {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fe-text);
  cursor: pointer;
  transition: background 0.1s;
  padding: 0;
}
.fe-toolbar-btn:hover  { background: var(--fe-hover); }
.fe-toolbar-btn:active { background: rgba(0,0,0,0.12); }
.fe-toolbar-btn:disabled { opacity: 0.35; cursor: default; }

.fe-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--fe-border);
  margin: 0 2px;
  flex-shrink: 0;
}

.fe-view-group {
  display: flex;
  border: 1px solid var(--fe-border);
  border-radius: 5px;
  overflow: hidden;
}
.fe-view-group .fe-toolbar-btn {
  border-radius: 0;
  width: 30px;
  border-right: 1px solid var(--fe-border);
}
.fe-view-group .fe-toolbar-btn:last-child { border-right: none; }
.fe-view-group .fe-toolbar-btn.active { background: rgba(0,0,0,0.1); }

.fe-path-bar {
  flex: 1;
  height: 26px;
  display: flex;
  align-items: center;
  background: white;
  border: 1px solid var(--fe-border);
  border-radius: 5px;
  padding: 0 8px;
  overflow: hidden;
  font-size: 12px;
  color: var(--fe-text-muted);
  gap: 4px;
}
.fe-path-segment {
  cursor: pointer;
  white-space: nowrap;
  color: var(--fe-text);
  padding: 1px 3px;
  border-radius: 3px;
}
.fe-path-segment:hover { background: var(--fe-hover); }
.fe-path-sep { color: var(--fe-text-muted); flex-shrink: 0; }

.fe-search {
  height: 26px;
  border: 1px solid var(--fe-border);
  border-radius: 13px;
  padding: 0 10px 0 28px;
  font-size: 12px;
  background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%236c6c70' d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.099zm-5.242 1.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 9px center;
  width: 160px;
  outline: none;
  transition: width 0.2s, box-shadow 0.2s;
}
.fe-search:focus {
  width: 200px;
  box-shadow: 0 0 0 3px var(--fe-selection-light);
}

/* ── Body ────────────────────────────────────────────────── */
.fe-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.fe-sidebar {
  width: var(--fe-sidebar-width);
  background: var(--fe-sidebar-bg);
  border-right: 1px solid var(--fe-column-border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 8px 0;
}
.fe-sidebar::-webkit-scrollbar { width: 6px; }
.fe-sidebar::-webkit-scrollbar-track { background: transparent; }
.fe-sidebar::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

.fe-sidebar-section { margin-bottom: 8px; }

.fe-sidebar-heading {
  font-size: 11px;
  font-weight: 700;
  color: var(--fe-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 12px 2px;
}

.fe-sidebar-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 12px;
  cursor: pointer;
  border-radius: 5px;
  margin: 0 4px;
  color: var(--fe-text);
  font-size: 13px;
  user-select: none;
  transition: background 0.1s;
}
.fe-sidebar-item:hover { background: rgba(0,0,0,0.07); }
.fe-sidebar-item.active { background: var(--fe-selection); color: white; }
.fe-sidebar-item .bi { font-size: 14px; flex-shrink: 0; }

/* ── Content area ────────────────────────────────────────── */
.fe-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Loading / empty states */
.fe-loading, .fe-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--fe-text-muted);
  font-size: 14px;
  pointer-events: none;
}
.fe-loading .spinner-border { color: var(--fe-selection); }

/* ── Column View ─────────────────────────────────────────── */
.fe-columns {
  display: flex;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  height: 100%;
}
.fe-columns::-webkit-scrollbar { height: 8px; }
.fe-columns::-webkit-scrollbar-track { background: transparent; }
.fe-columns::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 4px; }

.fe-column {
  width: var(--fe-column-width);
  min-width: var(--fe-column-width);
  border-right: 1px solid var(--fe-column-border);
  overflow-y: auto;
  height: 100%;
  flex-shrink: 0;
}
.fe-column:last-child { border-right: none; min-width: calc(var(--fe-column-width) * 1.5); }
.fe-column::-webkit-scrollbar { width: 6px; }
.fe-column::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

/* ── List View ───────────────────────────────────────────── */
.fe-list {
  flex: 1;
  overflow-y: auto;
  height: 100%;
}
.fe-list::-webkit-scrollbar { width: 6px; }
.fe-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

.fe-list-header {
  display: grid;
  grid-template-columns: 1fr 90px 120px 80px;
  padding: 4px 12px;
  background: var(--fe-toolbar-bg);
  border-bottom: 1px solid var(--fe-column-border);
  font-size: 11px;
  font-weight: 600;
  color: var(--fe-text-muted);
  position: sticky;
  top: 0;
  z-index: 1;
  user-select: none;
}
.fe-list-header span { cursor: pointer; }
.fe-list-header span:hover { color: var(--fe-text); }

/* ── List View – tree toggle ─────────────────────────────── */
.fe-list-name-cell {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.fe-list-toggle {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  font-family: monospace;
  color: var(--fe-text-muted);
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 3px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}
.fe-list-toggle:not(.fe-list-toggle-empty):hover {
  background: rgba(0,0,0,0.1);
  color: var(--fe-text);
}
.fe-file-row.selected .fe-list-toggle { color: rgba(255,255,255,0.8); }
.fe-file-row.selected .fe-list-toggle:hover { background: rgba(255,255,255,0.15); }

.fe-list-toggle-empty {
  cursor: default;
  pointer-events: none;
}

/* ── Icon View ───────────────────────────────────────────── */
.fe-icons {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  height: 100%;
}
.fe-icons::-webkit-scrollbar { width: 6px; }
.fe-icons::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

/* ── File Row (shared list+column) ──────────────────────── */
.fe-file-row {
  display: grid;
  grid-template-columns: 1fr 90px 120px 80px;
  align-items: center;
  padding: 3px 12px;
  cursor: pointer;
  user-select: none;
  border-radius: 4px;
  margin: 0 2px;
  transition: background 0.08s;
  min-height: 26px;
}
.fe-column .fe-file-row {
  grid-template-columns: auto 1fr auto;
  gap: 0;
}
.fe-file-row:hover { background: var(--fe-hover); }
.fe-file-row.selected { background: var(--fe-selection); color: white; }
.fe-file-row.selected .fe-text-muted { color: rgba(255,255,255,0.7); }

.fe-file-icon { font-size: 16px; margin-right: 6px; flex-shrink: 0; }
.fe-file-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}
.fe-file-meta {
  font-size: 11px;
  color: var(--fe-text-muted);
  white-space: nowrap;
}
.fe-col-arrow {
  color: var(--fe-text-muted);
  font-size: 10px;
  margin-left: 4px;
}
.fe-file-row.selected .fe-col-arrow { color: rgba(255,255,255,0.7); }

/* ── Icon item ───────────────────────────────────────────── */
.fe-icon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 80px;
  padding: 8px 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.08s;
  text-align: center;
}
.fe-icon-item:hover { background: var(--fe-hover); }
.fe-icon-item.selected { background: var(--fe-selection); color: white; }
.fe-icon-item.selected .fe-icon-label { color: white; }
.fe-icon-img { font-size: 36px; line-height: 1; margin-bottom: 4px; }
.fe-icon-label {
  font-size: 11px;
  color: var(--fe-text);
  word-break: break-word;
  line-height: 1.3;
  max-width: 72px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Status bar ──────────────────────────────────────────── */
.fe-statusbar {
  height: var(--fe-statusbar-height);
  background: var(--fe-toolbar-bg);
  border-top: 1px solid var(--fe-border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 11px;
  color: var(--fe-text-muted);
  gap: 16px;
  flex-shrink: 0;
}
.fe-status-center {
  flex: 1;
  text-align: center;
}

/* ── Action buttons (Select / Cancel) ───────────────────── */
.fe-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--fe-toolbar-bg);
  border-top: 1px solid var(--fe-border);
  flex-shrink: 0;
}
.fe-actions-spacer { flex: 1; }

/* ── Remote connection panel ─────────────────────────────── */
.fe-connect-panel {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(240,240,240,0.92);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.fe-connect-form {
  background: white;
  border-radius: 10px;
  padding: 24px;
  width: 340px;
  box-shadow: var(--fe-shadow);
  border: 1px solid var(--fe-border);
}
.fe-connect-form h6 {
  font-weight: 700;
  margin-bottom: 16px;
  font-size: 14px;
}

/* ── Popup mode ──────────────────────────────────────────── */
.fe-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 9998;
  display: none;
  backdrop-filter: blur(2px);
}
.fe-popup-overlay.visible { display: block; }

.fe-popup-wrapper {
  position: fixed;
  z-index: 9999;
  display: none;
  box-shadow: 0 8px 40px rgba(0,0,0,0.28);
  border-radius: var(--fe-radius);
}
.fe-popup-wrapper.visible { display: block; }

/* Resize handle */
.fe-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: se-resize;
  opacity: 0.4;
}
.fe-resize-handle::before,
.fe-resize-handle::after {
  content: '';
  position: absolute;
  background: var(--fe-text-muted);
  border-radius: 1px;
}
.fe-resize-handle::before {
  right: 3px; bottom: 7px;
  width: 9px; height: 1.5px;
  transform: rotate(-45deg);
}
.fe-resize-handle::after {
  right: 3px; bottom: 4px;
  width: 6px; height: 1.5px;
  transform: rotate(-45deg);
}

/* ── Local / LAN section ─────────────────────────────────── */
.fe-heading-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 8px;
}

.fe-lan-btn {
  background: none;
  border: none;
  padding: 1px 3px;
  border-radius: 3px;
  cursor: pointer;
  color: var(--fe-text-muted);
  font-size: 11px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.fe-lan-btn:hover { color: var(--fe-text); background: var(--fe-hover); }
.fe-lan-btn-spin i { animation: fe-spin 0.8s linear infinite; }

@keyframes fe-spin { to { transform: rotate(360deg); } }

.fe-lan-scanning {
  padding: 3px 12px;
  font-size: 11px;
  color: var(--fe-text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.fe-lan-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--fe-selection);
  animation: fe-pulse 1s ease-in-out infinite;
}
@keyframes fe-pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.2; }
}

.fe-lan-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fe-lan-ip {
  font-size: 10px;
  color: var(--fe-text-muted);
  white-space: nowrap;
  margin-left: auto;
  padding-left: 4px;
  flex-shrink: 0;
}
.fe-sidebar-item.active .fe-lan-ip { color: rgba(255,255,255,0.65); }

/* ── Connection badge in sidebar ─────────────────────────── */
.fe-conn-badge {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(0,0,0,0.12);
  color: var(--fe-text-muted);
  margin-left: auto;
}
.fe-sidebar-item.active .fe-conn-badge { background: rgba(255,255,255,0.2); color: white; }

/* ── Dark mode support ───────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --fe-bg: #2c2c2e;
    --fe-sidebar-bg: #242426;
    --fe-toolbar-bg: #323234;
    --fe-border: #48484a;
    --fe-column-border: #3a3a3c;
    --fe-text: #f2f2f7;
    --fe-text-muted: #8e8e93;
    --fe-selection: #2b6fd4;
    --fe-selection-light: rgba(43,111,212,0.2);
    --fe-hover: rgba(255,255,255,0.07);
  }
  .fe-titlebar {
    background: linear-gradient(to bottom, #3a3a3c, #2c2c2e);
  }
  .fe-search {
    background-color: #3a3a3c;
    color: var(--fe-text);
    border-color: var(--fe-border);
  }
  .fe-connect-form { background: #2c2c2e; }
}

/* ── Standalone page wrapper ─────────────────────────────── */
.fe-standalone {
  width: 100%;
  height: 100vh;
  padding: 0;
}
.fe-standalone .fe-window {
  border-radius: 0;
  height: 100vh;
  min-height: unset;
  box-shadow: none;
  border: none;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 600px) {
  :root { --fe-sidebar-width: 0px; }
  .fe-sidebar { display: none; }
  .fe-window { min-width: 320px; }
}
