* { box-sizing: border-box; }

:root {
  --bg: #0b0c0f;
  --surface: #131519;
  --surface-2: #1a1d23;
  --surface-3: #21252c;
  --border: #23262d;
  --border-soft: #1c1f25;
  --text: #e7e8ea;
  --text-dim: #8b8f9a;
  --text-faint: #5c6070;
  --accent: #6e7dfa;
  --accent-hover: #8291ff;
  --accent-soft: rgba(110, 125, 250, 0.14);
  --danger: #f0596a;
  --danger-soft: rgba(240, 89, 106, 0.14);
  --success: #35c98c;
  --radius: 10px;
  --radius-sm: 7px;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent-soft);
}

#app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

#app-header h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  white-space: nowrap;
  color: var(--text);
}

#toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-family: inherit;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover {
  background: var(--surface-3);
  border-color: #2e323b;
}

button:active {
  background: #262a32;
}

button.danger {
  border-color: transparent;
  background: var(--danger-soft);
  color: #ff8a96;
}

button.danger:hover {
  background: rgba(240, 89, 106, 0.22);
}

button.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

button.primary:hover {
  background: var(--accent-hover);
}

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

input[type="text"],
input[type="url"],
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s ease;
}

input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus {
  border-color: var(--accent);
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

label {
  color: var(--text-dim);
}

a {
  color: var(--accent-hover);
}

#app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#sidebar {
  width: 270px;
  min-width: 210px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#tree-container {
  flex: 1;
  overflow: auto;
  padding: 10px 8px;
}

.tree, .tree ul {
  list-style: none;
  margin: 0;
  padding-left: 14px;
}

.tree {
  padding-left: 2px;
}

.tree li {
  margin: 1px 0;
}

.tree-node {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  user-select: none;
  font-size: 12.5px;
  color: var(--text-dim);
}

.tree-node:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tree-node.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 500;
}

.tree-toggle {
  display: inline-block;
  width: 10px;
  text-align: center;
  color: var(--text-faint);
  font-size: 10px;
}

#storage-panel {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  font-size: 11.5px;
}

#storage-label {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10.5px;
}

#storage-bar-track {
  width: 100%;
  height: 6px;
  background: var(--surface-3);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 6px;
}

#storage-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #a685f5);
  transition: width 0.3s ease;
  border-radius: 6px;
}

#storage-text, #workspace-size-text {
  color: var(--text-faint);
  margin-top: 3px;
}

#content {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
}

#breadcrumb {
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-dim);
}

#breadcrumb span.crumb {
  cursor: pointer;
  color: var(--text-dim);
}

#breadcrumb span.crumb:last-child {
  color: var(--text);
}

#breadcrumb span.crumb:hover {
  color: var(--accent-hover);
}

#breadcrumb span.sep {
  margin: 0 6px;
  color: var(--text-faint);
}

#entries-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#entries-table th, #entries-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px;
}

#entries-table th {
  background: transparent;
  color: var(--text-faint);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10.5px;
}

#entries-table tbody tr:hover {
  background: var(--surface-2);
}

#entries-table tr:last-child td {
  border-bottom: none;
}

.entry-name {
  cursor: pointer;
  color: var(--text);
}

.entry-name.is-dir {
  color: #a9b3ff;
  font-weight: 500;
}

.entry-name:hover {
  color: var(--accent-hover);
}

.row-actions button {
  padding: 3px 8px;
  font-size: 11.5px;
  margin-right: 4px;
}

#empty-state {
  padding: 32px;
  text-align: center;
  color: var(--text-faint);
}

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#modal-overlay[hidden] {
  display: none;
}

#modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(640px, 92vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}

#modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 0 4px;
}

#modal-close:hover {
  color: var(--text);
  background: none;
  border: none;
}

#modal-content {
  padding: 18px;
  overflow: auto;
}

#modal-content textarea {
  width: 100%;
  height: 50vh;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 12.5px;
  padding: 10px;
  resize: vertical;
}

#modal-content input[type="text"] {
  padding: 7px 10px;
}

#modal-content img.preview {
  max-width: 100%;
  max-height: 60vh;
  display: block;
  margin: 0 auto;
  border-radius: var(--radius-sm);
}

#modal-content video.preview {
  max-width: 100%;
  max-height: 60vh;
  display: block;
  margin: 0 auto;
  border-radius: var(--radius-sm);
  background: #000;
}

#modal-content audio.preview {
  width: 100%;
  display: block;
}

#modal-content iframe.pdf-preview {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

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

.modal-tree {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  max-height: 40vh;
  overflow: auto;
  background: var(--surface-2);
}

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 360px;
}

.toast.error {
  border-color: rgba(240, 89, 106, 0.4);
  color: #ff8a96;
}

.toast.success {
  border-color: rgba(53, 201, 140, 0.4);
  color: #6fe3b4;
}
