/* ==========================================================================
   Windows 11 / 10 Fluent Explorer Stylesheet for Telegram WebApp
   ========================================================================== */

:root {
  /* Light Theme (Windows 11 Mica / Acrylic Inspired) */
  --bg-app: #f9f9f9;
  --bg-window: #ffffff;
  --bg-sidebar: #f3f3f3;
  --bg-command-bar: #ffffff;
  --bg-hover: #f0f0f0;
  --bg-selected: #e0eef9;
  --border-selected: #0078d4;
  --bg-selected-hover: #d2e7f7;
  --border-color: #e5e5e5;
  --border-subtle: #eeeeee;
  --text-main: #1c1c1c;
  --text-muted: #5c5c5c;
  --text-dimmed: #8a8a8a;
  --accent-color: #0067c0;
  --accent-hover: #1879cd;
  --accent-text: #ffffff;
  --status-bar-bg: #f3f3f3;
  --card-bg: #ffffff;
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.12);
  --font-family: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

/* Dark Theme */
body.theme-dark {
  --bg-app: #1e1e1e;
  --bg-window: #252525;
  --bg-sidebar: #202020;
  --bg-command-bar: #252525;
  --bg-hover: #2d2d2d;
  --bg-selected: #243c52;
  --border-selected: #4cc2ff;
  --bg-selected-hover: #2b4964;
  --border-color: #383838;
  --border-subtle: #2f2f2f;
  --text-main: #f5f5f5;
  --text-muted: #b0b0b0;
  --text-dimmed: #7a7a7a;
  --accent-color: #4cc2ff;
  --accent-hover: #60cdff;
  --accent-text: #000000;
  --status-bar-bg: #1a1a1a;
  --card-bg: #2d2d2d;
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* Base reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  user-select: none;
  font-size: 13px;
  line-height: 1.4;
}

/* Main Window Layout */
.explorer-window {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  background: var(--bg-window);
}

/* 1. Window Titlebar */
.window-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  padding: 0 12px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.titlebar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  white-space: nowrap;
}

.explorer-icon {
  display: flex;
  align-items: center;
}

.window-title {
  font-weight: 600;
  font-size: 13px;
}

.title-separator {
  color: var(--text-dimmed);
}

.current-window-folder {
  color: var(--text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.titlebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-icon {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  transition: background 0.15s ease;
}

.btn-icon:hover {
  background-color: var(--bg-hover);
}

/* 2. Command Ribbon */
.command-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background-color: var(--bg-command-bar);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}

.nav-btn {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-main);
  transition: background 0.15s ease, opacity 0.15s ease;
}

.nav-btn:hover:not(:disabled) {
  background-color: var(--bg-hover);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Address Breadcrumb Bar */
.address-bar-container {
  display: flex;
  align-items: center;
  flex: 1;
  height: 32px;
  background-color: var(--bg-window);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: none;
}

.address-bar-container::-webkit-scrollbar {
  display: none;
}

.address-bar-icon {
  display: flex;
  align-items: center;
  margin-right: 6px;
  flex-shrink: 0;
}

.address-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 2px;
}

.breadcrumb-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.breadcrumb-chip:hover {
  background-color: var(--bg-hover);
}

.breadcrumb-chip.active {
  font-weight: 600;
}

.breadcrumb-arrow {
  color: var(--text-dimmed);
  font-size: 11px;
  margin: 0 1px;
}

/* Search Box */
.search-box-container {
  display: flex;
  align-items: center;
  position: relative;
  width: 220px;
  height: 32px;
  background-color: var(--bg-window);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 8px;
}

.search-icon {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  margin-right: 6px;
}

.search-box-container input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: 12px;
  color: var(--text-main);
}

.search-box-container input::placeholder {
  color: var(--text-dimmed);
}

.search-clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 0 4px;
}

/* 3. Actions Ribbon */
.actions-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background-color: var(--bg-command-bar);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.actions-left, .actions-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-window);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-button:hover:not(:disabled) {
  background-color: var(--bg-hover);
}

.action-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.action-button.primary {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--accent-text);
}

.action-button.primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.view-switchers {
  display: flex;
  background-color: var(--bg-sidebar);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.view-btn {
  background: none;
  border: none;
  width: 28px;
  height: 26px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
}

.view-btn.active {
  background-color: var(--bg-window);
  color: var(--text-main);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* 4. Explorer Main Split Body */
.explorer-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Sidebar Navigation Pane */
.sidebar-pane {
  width: 240px;
  min-width: 200px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  padding: 8px 4px;
}

.tree-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tree-section-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dimmed);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 12px 4px 12px;
}

.tree-node {
  display: flex;
  flex-direction: column;
}

.tree-node-row {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 8px 0 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-main);
  font-size: 12px;
  transition: background 0.15s ease;
}

.tree-node-row:hover {
  background-color: var(--bg-hover);
}

.tree-node-row.active {
  background-color: var(--bg-selected);
  color: var(--border-selected);
  font-weight: 600;
}

.tree-toggle-arrow {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.tree-toggle-arrow.expanded svg {
  transform: rotate(90deg);
}

.tree-node-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tree-node-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-node-badge {
  font-size: 10px;
  color: var(--text-muted);
  background-color: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 8px;
}

.tree-children {
  display: none;
  padding-left: 16px;
}

.tree-children.open {
  display: block;
}

/* Right Content Area */
.content-pane {
  flex: 1;
  background-color: var(--bg-window);
  overflow: auto;
  position: relative;
}

/* Table Details View */
.details-view-wrapper {
  min-width: 100%;
}

.file-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.file-table thead {
  position: sticky;
  top: 0;
  background-color: var(--bg-window);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.file-table th {
  padding: 6px 10px;
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-right: 1px solid var(--border-subtle);
  user-select: none;
  white-space: nowrap;
}

.file-table th:hover {
  background-color: var(--bg-hover);
}

.file-table th .sort-arrow {
  margin-left: 4px;
  font-size: 10px;
}

.file-table tbody tr {
  height: 32px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.1s ease;
}

.file-table tbody tr:hover {
  background-color: var(--bg-hover);
}

.file-table tbody tr.selected {
  background-color: var(--bg-selected) !important;
  outline: 1px solid var(--border-selected);
  outline-offset: -1px;
}

.file-table td {
  padding: 4px 10px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.cell-name-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-title-text {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-subpath {
  font-size: 11px;
  color: var(--text-dimmed);
  margin-left: 6px;
}

/* Grid / Tiles View */
.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  padding: 14px;
}

.grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease;
  border: 1px solid transparent;
}

.grid-item:hover {
  background-color: var(--bg-hover);
}

.grid-item.selected {
  background-color: var(--bg-selected);
  border-color: var(--border-selected);
}

.grid-item-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

.grid-item-name {
  font-size: 12px;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.2;
}

.grid-item-size {
  font-size: 10px;
  color: var(--text-dimmed);
  margin-top: 2px;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  color: var(--text-dimmed);
  padding: 20px;
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 8px;
  opacity: 0.6;
}

.empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}

.empty-subtitle {
  font-size: 12px;
  margin-top: 4px;
}

/* 5. Bottom Details / File Properties Card (Flyout Pane) */
.details-card-pane {
  position: absolute;
  bottom: 26px; /* above status bar */
  left: 0;
  right: 0;
  background-color: var(--card-bg);
  border-top: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  padding: 12px 16px;
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  animation: slideUp 0.2s cubic-bezier(0.1, 0.9, 0.2, 1);
}

.details-card-pane.open {
  display: flex;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.details-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-info-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-info-titles {
  flex: 1;
  overflow: hidden;
}

.file-info-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-info-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-card-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.btn-card-close:hover {
  background-color: var(--bg-hover);
}

.card-summary {
  font-size: 12px;
  background-color: var(--bg-app);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-color);
  color: var(--text-muted);
  max-height: 80px;
  overflow-y: auto;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.card-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.card-btn.primary {
  background-color: var(--accent-color);
  color: var(--accent-text);
}

.card-btn.primary:hover {
  background-color: var(--accent-hover);
}

.card-btn.secondary {
  background-color: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-color);
}

.card-btn.secondary:hover {
  background-color: var(--bg-selected);
  border-color: var(--border-selected);
}

/* 6. Status Bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 24px;
  padding: 0 12px;
  background-color: var(--status-bar-bg);
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-separator {
  color: var(--text-dimmed);
}

.status-app-badge {
  color: var(--text-dimmed);
}

/* Loading Spinners */
.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border-color);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 8px;
}

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

.tree-loading, .content-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 34px;
  right: 14px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background-color: var(--card-bg);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-color);
  font-size: 12px;
  pointer-events: auto;
  animation: toastIn 0.2s ease;
  max-width: 300px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Mobile Responsive Rules
   ========================================================================== */
@media (max-width: 768px) {
  .search-box-container {
    width: 140px;
  }

  .file-table th.col-date,
  .file-table td.cell-date,
  .file-table th.col-type,
  .file-table td.cell-type {
    display: none;
  }

  /* Off-canvas sidebar for mobile */
  .sidebar-pane {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -260px;
    width: 260px;
    z-index: 60;
    transition: transform 0.25s cubic-bezier(0.1, 0.9, 0.2, 1);
    box-shadow: var(--shadow-card);
  }

  .sidebar-pane.open {
    transform: translateX(260px);
  }

  .sidebar-backdrop {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0,0,0,0.35);
    z-index: 55;
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .actions-left .action-button span {
    display: none;
  }

  .actions-left .action-button {
    padding: 0 8px;
  }
}
