:root {
  --bg: #fffdf2;
  --panel: #fff8dc;
  --panel-2: #fceeb0;
  --border: #e9d98a;
  --text: #3a2e0a;
  --text-dim: #8a7a42;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --danger: #d2304a;
  --success: #1f9d6b;
  --radius: 10px;
  --overlay-hover: rgba(58, 46, 10, 0.06);
  --overlay-hover-strong: rgba(58, 46, 10, 0.1);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

/* ---------- Landing page ---------- */

#landing {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 209, 102, 0.55), transparent 45%),
    radial-gradient(circle at 85% 75%, rgba(255, 226, 140, 0.55), transparent 50%),
    linear-gradient(160deg, #fffef6 0%, #fffae0 45%, #fff3c4 100%);
  overflow: hidden;
}

#landing::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(58,46,10,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(58,46,10,0.05) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse at 50% 40%, black 30%, transparent 75%);
  pointer-events: none;
}

.landing-topbar {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 40px;
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 24px rgba(91, 140, 255, 0.35);
}
.btn-primary:hover { box-shadow: 0 10px 30px rgba(91, 140, 255, 0.5); }

.btn-ghost {
  background: rgba(58,46,10,0.04);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--overlay-hover-strong); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 6px 12px; font-size: 13px; }

.landing-hero {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 64px;
  padding: 0 60px 40px;
  z-index: 2;
}

.landing-copy { max-width: 560px; }

.landing-copy h1 {
  font-size: 46px;
  line-height: 1.15;
  margin: 0 0 20px;
  background: linear-gradient(120deg, #3a2e0a, #5b8cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.landing-copy p {
  font-size: 17px;
  line-height: 1.6;
  color: var(--text-dim);
  margin: 0 0 28px;
}

.feature-list {
  list-style: none;
  margin: 0 0 32px;
  padding: 0;
  display: grid;
  gap: 12px;
}

.feature-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  color: var(--text);
}

.feature-list .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  flex-shrink: 0;
}

.landing-art { width: 420px; max-width: 40vw; flex-shrink: 0; }
.landing-art svg { width: 100%; height: auto; filter: drop-shadow(0 20px 60px rgba(91,140,255,0.25)); }

@media (max-width: 900px) {
  .landing-hero { flex-direction: column; padding: 20px 24px 40px; gap: 24px; }
  .landing-art { width: 260px; max-width: 70vw; }
  .landing-copy h1 { font-size: 32px; }
}

/* ---------- Modal ---------- */

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

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 380px;
  max-width: 92vw;
  padding: 28px;
  box-shadow: 0 24px 80px rgba(58,46,10,0.18);
}

.modal.modal-wide { width: 520px; }

.modal-resizable {
  resize: both;
  overflow: auto;
  min-width: 340px;
  min-height: 280px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal h2 { margin: 0 0 6px; font-size: 20px; }
.modal .modal-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 20px; }

/* The description/content textarea stretches to fill the modal when it's been maximized,
   instead of staying a small fixed-height box inside a lot of empty space. */
#item-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#field-description:not(.hidden), #field-content:not(.hidden) {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
#field-description textarea, #field-content textarea {
  flex: 1; min-height: 0; resize: none;
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }

.field input[type=text],
.field input[type=email],
.field input[type=password],
.field input[type=url],
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 100px; font-family: inherit; }

.field-error {
  color: var(--danger);
  font-size: 13px;
  margin: -8px 0 14px;
  min-height: 1em;
}

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

.modal-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-dim);
}
.modal-switch a { color: var(--accent); text-decoration: none; cursor: pointer; }

.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none; color: var(--text-dim);
  font-size: 20px; line-height: 1;
}

.modal { position: relative; }

/* ---------- App shell ---------- */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.app-topbar .brand { font-size: 16px; }
.app-topbar .brand-icon { width: 24px; height: 24px; }

.tabs { display: flex; gap: 4px; margin-left: 24px; }
.tab-btn {
  background: none; border: 1px solid transparent; color: var(--text-dim);
  padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 500;
}
.tab-btn:hover { background: var(--overlay-hover); color: var(--text); }
.tab-btn.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-email { color: var(--text-dim); font-size: 13px; }

.app-body { flex: 1; display: flex; min-height: 0; }

/* ---------- Explorer ---------- */

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px;
}
.sidebar-header span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }

.sidebar-search { padding: 0 16px 10px; }
.sidebar-search input {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); font-size: 13px; outline: none;
}
.sidebar-search input:focus { border-color: var(--accent); }

.icon-btn {
  background: rgba(58,46,10,0.05);
  border: 1px solid var(--border);
  color: var(--text);
  width: 26px; height: 26px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.icon-btn:hover { background: var(--overlay-hover-strong); }

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
}

.tree-node { user-select: none; }

.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
}
.tree-row:hover { background: var(--overlay-hover); }
.tree-row.selected { background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--border); }

.tree-caret {
  width: 14px; text-align: center; color: var(--text-dim); font-size: 10px;
  flex-shrink: 0;
}
.tree-caret.empty { visibility: hidden; }

.tree-menu-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 15px; line-height: 1; padding: 3px 5px; border-radius: 5px;
  margin-left: auto; flex-shrink: 0; opacity: 0.55;
}
.tree-menu-btn:hover { background: var(--overlay-hover-strong); color: var(--text); opacity: 1; }

.tree-children { margin-left: 16px; border-left: 1px dashed var(--border); padding-left: 4px; }

.empty-hint { color: var(--text-dim); font-size: 13px; padding: 12px 8px; line-height: 1.5; }

/* ---------- Main content pane ---------- */

.content-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.content-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 10px;
}

.breadcrumb {
  display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-dim); flex-wrap: wrap;
}
.breadcrumb .crumb { cursor: pointer; color: var(--text); }
.breadcrumb .crumb:hover { color: var(--accent); }
.breadcrumb .sep { color: var(--text-dim); }

.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.view-mode-toggle {
  display: flex; gap: 2px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 2px;
}
.view-mode-btn {
  background: none; border: none; color: var(--text-dim);
  height: 28px; padding: 0 10px; border-radius: 6px; font-size: 13px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap;
}
.view-mode-btn:hover { background: var(--overlay-hover); color: var(--text); }
.view-mode-btn.active { background: var(--panel); color: var(--accent); box-shadow: inset 0 0 0 1px var(--border); }

.content-grid {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  align-content: start;
}

.content-grid.list-mode {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.content-grid.is-empty {
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  position: relative;
  transition: border-color .12s ease, transform .12s ease;
}
.item-card:hover { border-color: var(--accent); }

.list-mode .item-card {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 8px 40px 8px 12px;
  border-radius: 8px;
}

.item-icon { font-size: 26px; }
.list-mode .item-icon { font-size: 16px; }

.item-name {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-mode .item-name { font-weight: 500; }

.item-desc {
  font-size: 12px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  min-height: 2.6em;
}
.list-mode .item-desc { display: none; }

.item-menu-btn {
  position: absolute; top: 10px; right: 10px;
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; padding: 2px 6px; border-radius: 6px;
}
.item-menu-btn:hover { background: var(--overlay-hover-strong); color: var(--text); }

.context-menu {
  position: fixed;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 170px;
  box-shadow: 0 12px 40px rgba(58,46,10,0.18);
  z-index: 200;
}
.context-menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  padding: 8px 10px; border-radius: 6px; font-size: 13px;
}
.context-menu button:hover { background: var(--overlay-hover); }
.context-menu button.danger { color: var(--danger); }
.context-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-dim); gap: 10px; text-align: center; padding: 40px;
}
.empty-state .big-icon { font-size: 44px; opacity: 0.6; }

/* ---------- Admin panel ---------- */

.panel-view { flex: 1; overflow-y: auto; padding: 24px 32px; }
.panel-view h2 { margin: 0 0 4px; }
.panel-view .panel-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 24px; }

table.data-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.data-table th, table.data-table td { padding: 12px 16px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--border); }
table.data-table th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; background: var(--panel-2); }
table.data-table tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-admin { background: rgba(91,140,255,0.16); color: #2f5fd6; }
.badge-user { background: rgba(147,160,189,0.15); color: var(--text-dim); }

.file-drop {
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  margin: 20px 0;
}
.file-drop input { display: none; }

.section-title { margin: 36px 0 12px; font-size: 16px; }
.section-title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin: 36px 0 12px; flex-wrap: wrap; gap: 10px;
}

.files-toolbar {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0 4px;
}
.files-path {
  flex: 1; font-family: 'SF Mono', Consolas, monospace; font-size: 13px;
  color: var(--text-dim); background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px; overflow-x: auto; white-space: nowrap;
}
.files-table-row-dir { cursor: pointer; }
.files-table-row-dir:hover td { color: var(--accent); }

/* ---------- Notepad ---------- */

.notepad-view { flex: 1; display: flex; flex-direction: column; padding: 24px 32px; min-height: 0; }
.notepad-view textarea {
  flex: 1; resize: none; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); padding: 20px; font-size: 15px; line-height: 1.6; font-family: 'SF Mono', Consolas, monospace;
  outline: none;
}
.notepad-view textarea:focus { border-color: var(--accent); }
.notepad-status { margin-top: 10px; font-size: 12px; color: var(--text-dim); }

/* ---------- Terminal ---------- */

.terminal-view { flex: 1; display: flex; flex-direction: column; padding: 24px 32px; min-height: 0; }
.terminal-header { display: flex; align-items: baseline; gap: 14px; margin-bottom: 14px; }
.terminal-status { font-size: 12px; color: var(--text-dim); }
.terminal-status.connected { color: var(--success); }
.terminal-status.error { color: var(--danger); }

#terminal-container {
  flex: 1;
  min-height: 0;
  background: #14120a;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  overflow: hidden;
}

/* ---------- Toast ---------- */

#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 300;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 12px 30px rgba(58,46,10,0.15);
  animation: toast-in .15s ease;
}
.toast.error { border-color: var(--danger); color: #a3223a; }
.toast.success { border-color: var(--success); color: #157a53; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
