:root {
  --theme-bg: #152018;
  --theme-panel: #0f1812;
  --theme-border: #2f4a3b;
  --theme-border-strong: #3a5a47;
  --theme-accent: #1e2f25;
  --theme-accent-border: #4a6a55;
  --theme-text: #e3f1e8;
  --theme-text-muted: #9eb9aa;
  --theme-success: #2d744a;
  --theme-success-border: #5fb87f;
  --theme-danger: #7a2d34;
  --theme-danger-border: #be5a66;
  --theme-warning: #8a6a22;
  --theme-warning-border: #c8a14a;
  --theme-focus: #6a8bd6;
  --theme-selection: #3a5a47;
  --scrollbar-thumb: #5d6469;
  --scrollbar-thumb-hover: #6a7177;
  --scrollbar-track: #8e959b;
}

* {
  box-sizing: border-box;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--theme-bg);
  color: var(--theme-text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--theme-accent-border);
  border-radius: 4px;
  background: var(--theme-accent);
  color: var(--theme-text);
  min-height: 34px;
  padding: 6px 10px;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--theme-focus);
  outline: 2px solid transparent;
}

input,
select {
  width: 100%;
  border: 1px solid var(--theme-border);
  border-radius: 4px;
  background: #0b120d;
  color: var(--theme-text);
  min-height: 36px;
  padding: 7px 9px;
}

a {
  color: var(--theme-text);
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(21, 32, 24, 0.95), rgba(15, 24, 18, 0.98)),
    var(--theme-bg);
}

.auth-panel {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--theme-border-strong);
  border-radius: 8px;
  background: var(--theme-panel);
  padding: 28px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.auth-panel h1 {
  margin: 0 0 20px;
  font-size: 28px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: #ff9aa5;
}

.topbar {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  border-bottom: 1px solid var(--theme-border);
  background: var(--theme-panel);
}

.topbar #currentUser {
  color: var(--theme-text-muted);
  flex: 1;
}

.desktop-surface {
  position: relative;
  height: calc(100vh - 42px);
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(47, 74, 59, 0.15) 1px, transparent 1px),
    linear-gradient(rgba(47, 74, 59, 0.15) 1px, transparent 1px),
    var(--theme-bg);
  background-size: 32px 32px;
}

.launcher {
  position: absolute;
  left: 14px;
  top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 180px;
  z-index: 2;
}

.launcher button {
  min-height: 48px;
  text-align: center;
}

.window-layer {
  position: absolute;
  inset: 0;
}

.taskbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 42px;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 5px 8px;
  border-top: 1px solid var(--theme-border);
  background: rgba(15, 24, 18, 0.95);
  z-index: 5000;
}

.taskbar:empty {
  display: none;
}

.taskbar-button {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.explorer-window {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 520px;
  min-height: 320px;
  border: 1px solid var(--theme-border-strong);
  border-radius: 6px;
  overflow: hidden;
  background: var(--theme-panel);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.4);
}

.window-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 4;
}

.window-resize-handle::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--theme-text-muted);
  border-bottom: 2px solid var(--theme-text-muted);
}

.explorer-window.maximized .window-resize-handle {
  display: none;
}

.explorer-window.active {
  border-color: var(--theme-focus);
}

.explorer-window.minimized {
  display: none;
}

.explorer-window.maximized {
  inset: 8px !important;
  width: auto !important;
  height: auto !important;
}

.window-titlebar {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 10px;
  background: var(--theme-accent);
  border-bottom: 1px solid var(--theme-border);
  cursor: move;
  user-select: none;
}

.window-titlebar span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.window-actions {
  display: flex;
}

.window-control {
  width: 38px;
  min-height: 34px;
  border-radius: 0;
  border-width: 0 0 0 1px;
}

.window-control.close:hover {
  background: var(--theme-danger);
}

.window-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--theme-border);
}

.path-box {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  color: var(--theme-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.path-link {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--theme-focus);
  cursor: pointer;
  font: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
}

.path-link:hover {
  text-decoration: underline;
}

.path-link[aria-current="page"] {
  color: inherit;
  cursor: default;
  text-decoration: none;
}

.path-separator {
  flex: 0 0 auto;
  color: var(--theme-text-muted);
}

.window-content {
  display: grid;
  grid-template-columns: var(--tree-panel-width, 240px) 6px minmax(0, 1fr);
  min-height: 0;
  flex: 1;
}

.tree-panel,
.list-panel {
  min-width: 0;
  overflow: auto;
}

.tree-panel {
  padding: 8px;
}

.panel-resizer {
  cursor: col-resize;
  border-inline: 1px solid var(--theme-border);
  background: var(--theme-panel);
}

.panel-resizer:hover,
.is-resizing-panel .panel-resizer {
  background: var(--theme-focus);
}

.is-resizing-panel {
  cursor: col-resize;
  user-select: none;
}

.tree-children {
  margin-left: 0;
}

.tree-row {
  display: flex;
  align-items: center;
  min-height: 30px;
  margin-bottom: 4px;
}

.tree-toggle {
  flex: 0 0 22px;
  min-height: 30px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--theme-text-muted);
}

.tree-node {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 30px;
  text-align: left;
  border-color: transparent;
  background: transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-node.selected,
tr.selected {
  background: var(--theme-selection);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--theme-border);
  padding: 7px 9px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--theme-accent);
  cursor: pointer;
}

tr {
  cursor: default;
}

tr.directory-row {
  color: var(--theme-success-border);
  font-weight: 700;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}

.column-resizer:hover {
  background: var(--theme-focus);
}

.context-menu {
  position: fixed;
  z-index: 10000;
  min-width: 170px;
  border: 1px solid var(--theme-border-strong);
  border-radius: 5px;
  background: var(--theme-panel);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
  padding: 4px;
}

.context-menu-item {
  display: block;
  width: 100%;
  min-height: 30px;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.context-menu-separator {
  height: 1px;
  margin: 4px 2px;
  background: var(--theme-border);
}

.context-menu-item.danger {
  color: var(--theme-danger-border);
}

.context-menu-item:disabled {
  color: var(--theme-text-muted);
  cursor: not-allowed;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 11000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
}

.progress-modal {
  width: min(520px, 100%);
  border: 1px solid var(--theme-border-strong);
  border-radius: 8px;
  background: var(--theme-panel);
  padding: 18px;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.5);
}

.progress-modal h2 {
  margin: 0 0 12px;
  font-size: 19px;
}

.progress-modal p {
  margin: 8px 0;
}

.progress-modal progress {
  width: 100%;
  height: 18px;
  accent-color: var(--theme-success-border);
}

.folder-modal-label {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.folder-name-input.invalid {
  border-color: var(--theme-danger-border);
  box-shadow: 0 0 0 1px var(--theme-danger-border);
}

.folder-name-error {
  min-height: 20px;
  color: var(--theme-danger-border);
  font-size: 0.9rem;
}

.conflict-modal ul {
  max-height: 180px;
  margin: 10px 0;
  padding-left: 22px;
  overflow: auto;
  color: var(--theme-text-muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 16px;
  padding: 16px;
}

.panel {
  border: 1px solid var(--theme-border);
  border-radius: 6px;
  background: var(--theme-panel);
  padding: 14px;
  min-width: 0;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.root-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  gap: 8px;
  align-items: center;
}

.table-wrap {
  overflow: auto;
}

@media (max-width: 800px) {
  .admin-grid,
  .admin-form,
  .root-row,
  .window-content {
    grid-template-columns: 1fr;
  }

  .explorer-window {
    left: 8px !important;
    right: 8px;
    width: auto !important;
  }
}

.app-version {
  margin: 0;
  text-align: center;
  color: var(--theme-text-muted);
  font-size: 0.85rem;
}
