/* File Manager Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  overflow: hidden;
}

#file-manager {
  display: grid;
  grid-template-rows: 48px 1fr 28px;
  grid-template-columns: 200px 1fr;
  grid-template-areas:
    'toolbar toolbar'
    'sidebar content'
    'status status';
  height: 100vh;
  width: 100vw;
}

/* Toolbar */
#toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: linear-gradient(180deg, #2d2d44 0%, #252538 100%);
  border-bottom: 1px solid #3d3d5c;
}

#toolbar button {
  background: #3d3d5c;
  border: 1px solid #4d4d6c;
  border-radius: 4px;
  color: #e0e0e0;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
}

#toolbar button:hover {
  background: #4d4d6c;
  border-color: #5d5d7c;
}

#toolbar button:active {
  transform: scale(0.95);
}

#toolbar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#toolbar button:focus-visible {
  outline: 2px solid #63b3ed;
  outline-offset: 2px;
}

#path-bar {
  flex: 1;
  background: #1a1a2e;
  border: 1px solid #3d3d5c;
  border-radius: 4px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
}

.breadcrumb-segment {
  color: #7a8899;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.15s ease;
  font-size: 13px;
}

.breadcrumb-segment:hover {
  background: rgba(100, 150, 255, 0.2);
  color: #a0c0ff;
}

.breadcrumb-segment:focus {
  outline: none;
}

.breadcrumb-segment:focus-visible {
  outline: 2px solid #63b3ed;
  outline-offset: 2px;
}

.breadcrumb-segment.active {
  color: #fff;
  font-weight: 500;
  cursor: default;
}

.breadcrumb-segment.active:hover {
  background: transparent;
  color: #fff;
}

.breadcrumb-separator {
  color: #4a5568;
  font-size: 12px;
  user-select: none;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  color: #88c0d0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar */
#sidebar {
  grid-area: sidebar;
  background: #252538;
  border-right: 1px solid #3d3d5c;
  overflow-y: auto;
  padding: 12px 0;
}

.sidebar-section {
  margin-bottom: 16px;
}

.sidebar-section h3 {
  color: #888;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 16px;
}

.sidebar-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-item:hover {
  background: rgba(136, 192, 208, 0.1);
}

.sidebar-item.active {
  background: rgba(136, 192, 208, 0.2);
  color: #88c0d0;
}

.sidebar-item.drop-target {
  background: rgba(163, 190, 140, 0.3);
  border: 2px dashed #a3be8c;
  border-radius: 4px;
}

/* Content Area */
#content {
  grid-area: content;
  overflow-y: auto;
  padding: 16px;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* File list fills the content area for drag/drop */
#file-list {
  flex: 1;
  min-height: 0; /* Allow shrinking in flex */
  align-content: start; /* Keep items at top */
}

/* Grid View */
#file-list.grid-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  grid-auto-rows: min-content; /* Rows only as tall as content */
  gap: 16px;
}

/* Drag and drop states */
#file-list.drag-over {
  background: rgba(136, 192, 208, 0.15);
  border: 2px dashed #88c0d0;
  border-radius: 8px;
}

.file-item[draggable='true'] {
  cursor: grab;
}

.file-item[draggable='true']:active {
  cursor: grabbing;
}

.file-item.drop-target {
  background: rgba(163, 190, 140, 0.3);
  border: 2px dashed #a3be8c;
  border-radius: 8px;
}

/* Parent directory item */
.file-item.parent-item {
  opacity: 0.7;
}

.file-item.parent-item:hover {
  opacity: 1;
}

.file-item.parent-item .file-name {
  font-style: italic;
}

.file-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.file-item:hover {
  background: rgba(136, 192, 208, 0.1);
}

.file-item.selected {
  background: rgba(136, 192, 208, 0.25);
  outline: 2px solid #88c0d0;
}

.file-icon {
  font-size: 48px;
  margin-bottom: 8px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.file-name {
  font-size: 12px;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
  line-height: 1.3;
}

/* List View */
#file-list.list-view {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Column header (list view only) */
.file-list-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 6px 12px 8px;
  gap: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7a8f;
  border-bottom: 1px solid rgba(61, 61, 92, 0.95);
  background: linear-gradient(180deg, rgba(20, 24, 36, 0.98) 0%, rgba(26, 26, 46, 0.72) 100%);
  position: sticky;
  top: 0;
  z-index: 2;
  flex-shrink: 0;
}

.file-list-header-icon-spacer {
  font-size: 24px;
  line-height: 1;
  width: 1.25em;
  flex-shrink: 0;
  visibility: hidden;
  user-select: none;
}

.file-list-header-label {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.file-list-header-meta {
  display: flex;
  gap: 24px;
  justify-content: flex-end;
  color: #6b7a8f;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.file-list-header-meta span:first-child {
  min-width: 4.5rem;
  text-align: right;
}

.file-list-header-meta span:last-child {
  min-width: 6.5rem;
  text-align: right;
}

#file-list.list-view .file-item {
  flex-direction: row;
  padding: 8px 12px;
  gap: 12px;
  min-height: 36px;
  border-bottom: 1px solid rgba(45, 45, 68, 0.55);
}

#file-list.list-view .file-item:nth-child(odd of .file-item) {
  background: rgba(255, 255, 255, 0.028);
}

#file-list.list-view .file-item:hover {
  background: rgba(136, 192, 208, 0.12);
}

#file-list.list-view .file-item.selected {
  background: rgba(136, 192, 208, 0.25);
}

#file-list.list-view .file-icon {
  font-size: 24px;
  margin-bottom: 0;
}

#file-list.list-view .file-name {
  text-align: left;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#file-list.list-view .file-meta {
  display: flex;
  gap: 24px;
  justify-content: flex-end;
  align-items: center;
  color: #9aa6b8;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  flex-shrink: 0;
}

#file-list.list-view .file-meta span:first-child {
  min-width: 4.5rem;
  text-align: right;
}

#file-list.list-view .file-meta span:last-child {
  min-width: 6.5rem;
  text-align: right;
}

#file-list.list-view .file-item:focus-visible {
  outline: 2px solid #88c0d0;
  outline-offset: -2px;
}

/* Grid view: breathe the selection ring off the tile edge (list view uses inset focus-visible above). */
#file-list.grid-view .file-item.selected {
  outline-offset: 2px;
}

@media (prefers-contrast: more) {
  #file-list.grid-view .file-item.selected {
    outline-width: 3px;
    outline-color: #b0e8f4;
  }
}

/* Empty State (root directory — no ".." row) */
#empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #8b95a8;
  max-width: 420px;
  width: calc(100% - 48px);
  pointer-events: none;
}

#empty-state .empty-state-inner {
  pointer-events: auto;
  padding: 28px 24px;
  border-radius: 12px;
  border: 1px solid #3d3d5c;
  background: linear-gradient(160deg, rgba(45, 45, 68, 0.72) 0%, rgba(26, 26, 46, 0.5) 100%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

#empty-state .empty-icon {
  font-size: 56px;
  display: block;
  margin: 0 auto 14px;
  line-height: 1;
  opacity: 0.88;
  filter: saturate(1.05);
}

#empty-state .empty-title {
  font-size: 18px;
  font-weight: 600;
  color: #e8eaef;
  margin: 0 0 10px;
  letter-spacing: 0.02em;
}

#empty-state .empty-hint {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: #8b95a8;
}

#empty-state .empty-hint strong {
  color: #a8b4c8;
  font-weight: 600;
}

#empty-state kbd,
.empty-folder-hint kbd {
  display: inline-block;
  padding: 2px 7px;
  font-size: 11px;
  font-family: ui-monospace, 'Consolas', monospace;
  border-radius: 4px;
  background: #1a1a2e;
  border: 1px solid #4d4d6c;
  color: #c8d0e0;
}

#empty-state.hidden {
  display: none;
}

/* Non-root empty folder: only ".." — inline hint below parent row */
.empty-folder-hint {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-top: 4px;
  padding: 16px 18px;
  border-radius: 10px;
  border: 1px dashed rgba(136, 192, 208, 0.38);
  background: rgba(0, 0, 0, 0.22);
}

#file-list.list-view .empty-folder-hint {
  flex-direction: row;
  width: 100%;
}

.empty-folder-hint-icon {
  font-size: 36px;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0.9;
}

.empty-folder-hint-title {
  font-weight: 600;
  color: #c8d0e0;
  margin: 0 0 6px;
  font-size: 14px;
}

.empty-folder-hint-sub {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: #7a8899;
}

.empty-folder-hint-sub strong {
  color: #9aa6b8;
  font-weight: 600;
}

/* listDirectory / FS errors */
.file-list-error {
  padding: 18px 20px;
  border-radius: 8px;
  background: rgba(120, 40, 40, 0.2);
  border: 1px solid rgba(255, 120, 96, 0.4);
  color: #f5a898;
  font-size: 14px;
  line-height: 1.45;
  max-width: 100%;
  word-break: break-word;
}

/* Status Bar */
#status-bar {
  grid-area: status;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  padding: 0 12px;
  background: #252538;
  border-top: 1px solid #3d3d5c;
  font-size: 12px;
  line-height: 1.35;
  color: #9aa3b8;
  font-variant-numeric: tabular-nums;
}

#status-bar .status-item-count {
  flex: 1 1 auto;
  min-width: 0;
}

#status-bar .status-selected-info {
  flex: 0 1 auto;
  color: #c8d0dc;
  font-weight: 500;
  text-align: right;
}

#status-bar .status-selected-info:empty {
  display: none;
}

@media (prefers-contrast: more) {
  #status-bar {
    color: #c5ccd8;
    border-top-color: #5a5a78;
  }

  #status-bar .status-selected-info {
    color: #e8ecf2;
  }
}

/* Context Menu */
#context-menu {
  position: fixed;
  background: linear-gradient(145deg, #2d2d44, #252538);
  border: 1px solid #4d4d6c;
  border-radius: 8px;
  padding: 6px 0;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 1000;
}

#context-menu.hidden {
  display: none;
}

.menu-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s ease;
}

.menu-item:hover {
  background: rgba(136, 192, 208, 0.2);
}

.menu-item:focus-visible {
  outline: 2px solid #88c0d0;
  outline-offset: -2px;
  background: rgba(136, 192, 208, 0.22);
}

.menu-divider {
  height: 1px;
  background: #3d3d5c;
  margin: 4px 0;
}

/* Dialog Overlay */
#dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

#dialog-overlay.hidden {
  display: none;
}

#dialog {
  background: linear-gradient(145deg, #2d2d44, #252538);
  border: 1px solid #4d4d6c;
  border-radius: 12px;
  padding: 24px;
  min-width: 300px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

#dialog h3 {
  margin-bottom: 16px;
  color: #88c0d0;
}

#dialog input {
  width: 100%;
  padding: 10px 12px;
  background: #1a1a2e;
  border: 1px solid #4d4d6c;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 14px;
  margin-bottom: 16px;
}

#dialog input:focus {
  outline: none;
  border-color: #88c0d0;
}

#dialog input:focus-visible {
  outline: 2px solid rgba(136, 192, 208, 0.85);
  outline-offset: 2px;
  border-color: #88c0d0;
}

#dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#dialog-buttons button {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
}

#dialog-cancel {
  background: #3d3d5c;
  color: #e0e0e0;
}

#dialog-cancel:hover {
  background: #4d4d6c;
}

#dialog-confirm {
  background: #88c0d0;
  color: #1a1a2e;
}

#dialog-confirm:hover {
  background: #9dd0e0;
}

#dialog-buttons button:focus-visible {
  outline: 2px solid rgba(136, 192, 208, 0.9);
  outline-offset: 2px;
}

/* Preview Overlay */
#preview-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

#preview-overlay.hidden {
  display: none;
}

#preview {
  background: #252538;
  border: 1px solid #4d4d6c;
  border-radius: 12px;
  width: 80%;
  max-width: 800px;
  max-height: 80%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #2d2d44;
  border-bottom: 1px solid #3d3d5c;
}

#preview-title {
  font-weight: 500;
  color: #88c0d0;
}

#preview-close {
  background: none;
  border: none;
  color: #888;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

#preview-close:hover {
  color: #e0e0e0;
}

#preview-close:focus-visible {
  outline: 2px solid rgba(136, 192, 208, 0.85);
  outline-offset: 2px;
  border-radius: 4px;
  color: #e0e0e0;
}

#preview-content {
  padding: 16px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  font-family: ui-monospace, 'Cascadia Code', 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-variant-ligatures: none;
  scrollbar-width: thin;
  scrollbar-color: #4d4d6c #1a1a2e;
}

#preview-content.preview-file-text {
  color: #dce2ea;
}

#preview-content.preview-placeholder {
  color: #9aa6b8;
  font-style: italic;
}

@media (prefers-contrast: more) {
  #preview {
    border-color: #7a8aa0;
  }

  #preview-content.preview-file-text {
    color: #f2f5f8;
  }

  #preview-content.preview-placeholder {
    color: #c5ced9;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #1a1a2e;
}

::-webkit-scrollbar-thumb {
  background: #4d4d6c;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #5d5d7c;
}
