:root {
  color-scheme: dark;
  --bg: #1e1e1e;
  --side: #252526;
  --side-dark: #1b1b1c;
  --panel: #2d2d30;
  --panel-soft: #333337;
  --line: #3c3c3c;
  --line-soft: #2a2d2e;
  --text: #cccccc;
  --text-strong: #ffffff;
  --muted: #858585;
  --accent: #007acc;
  --accent-strong: #0e639c;
  --danger: #f48771;
  --green: #89d185;
  --editor-bg: #1e1e1e;
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family:
    "Segoe UI",
    "Apple SD Gothic Neo",
    Arial,
    sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  background: #343a40;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(0, 122, 204, 0.16), transparent 42%),
    radial-gradient(circle at 72% 20%, rgba(137, 209, 133, 0.12), transparent 28%),
    var(--bg);
}

.login-form {
  display: grid;
  gap: 14px;
  width: min(100%, 380px);
  padding: 24px;
  border: 1px solid #454545;
  border-radius: 8px;
  background: #252526;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.login-form h1 {
  margin: 0 0 6px;
  color: var(--text-strong);
  font-size: 24px;
  font-weight: 650;
}

.login-form label,
.server-form label,
.server-select-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 12px;
  min-width: 0;
}

.checkbox-label input {
  flex: 0 0 auto;
  width: auto;
  min-height: 0;
  margin: 0;
}

.checkbox-label span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.checkbox-label input:disabled + span {
  opacity: 0.5;
}

.login-form input,
.server-form input:not([type='checkbox']),
.server-form select,
.server-select-label select {
  width: 100%;
  min-height: 34px;
  border: 1px solid #3c3c3c;
  border-radius: 4px;
  padding: 7px 9px;
  color: var(--text);
  background: #1f1f1f;
  outline: none;
}

.login-form input:focus,
.server-form input:not([type='checkbox']):focus,
.server-form select:focus,
.server-select-label select:focus {
  border-color: var(--accent);
}

.login-form button,
.server-form button[type='submit'] {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: #ffffff;
}

#loginStatus {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 12px;
}

.login-description {
  margin: -4px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.app {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: var(--side);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}

.sidebar-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.sidebar h1 {
  margin: 0;
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 650;
  line-height: 1.2;
}

#addServerButton,
#upButton,
#logoutButton {
  border-color: transparent;
  background: #313134;
}

#logoutButton {
  color: #d7ba7d;
}

.icon-button {
  display: grid;
  place-items: center;
  min-width: 34px;
  padding: 0 8px;
  font-size: 14px;
}

.server-form {
  display: grid;
  flex: 0 0 auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #202021;
}

.form-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
}

.server-select-label,
.tree-actions {
  flex: 0 0 auto;
}

.tree-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: -4px;
}

.path-breadcrumb {
  display: grid;
  gap: 2px;
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
}

.path-breadcrumb-row {
  display: block;
}

.breadcrumb-link {
  min-height: 24px;
  padding: 2px 4px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
}

.breadcrumb-link:hover {
  border-color: transparent;
  background: #2a2d2e;
}

.breadcrumb-link.tree-like {
  display: inline-grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 10px);
  text-align: left;
}

.breadcrumb-link.tree-like .entry-icon {
  width: 18px;
  height: 18px;
  font-size: 14px;
}

.breadcrumb-link.tree-like span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumb-link.current {
  color: var(--text-strong);
  background: #2a2d2e;
}

.danger-icon {
  color: #f48771;
}

.danger-icon:hover {
  border-color: #f48771;
  background: #3a2525;
}

.file-tree {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--side-dark);
}

.file-tree::-webkit-scrollbar,
.tabs::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.file-tree::-webkit-scrollbar-thumb,
.tabs::-webkit-scrollbar-thumb {
  background: #454545;
}

.file-entry {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 28px;
  padding: 4px 10px;
  border: 0;
  border-radius: 0;
  text-align: left;
  background: transparent;
  color: var(--text);
}

.file-entry:hover,
.file-entry.loading {
  background: #2a2d2e;
}

.entry-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 15px;
}

.file-entry span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.tree-loading,
.tree-message {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-rows: 36px minmax(0, 1fr) 24px;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--editor-bg);
}

.tabs {
  display: flex;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid #252526;
  background: #181818;
}

.tab {
  position: relative;
  display: grid;
  grid-template-columns: minmax(80px, 190px) 22px;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 7px 0 12px;
  border: 0;
  border-right: 1px solid #252526;
  border-radius: 0;
  color: #969696;
  background: var(--editor-bg);
}

.tab.active {
  color: var(--text-strong);
  background: #2d2d2d;
  box-shadow:
    inset 0 3px 0 var(--accent),
    0 -1px 0 var(--accent);
}

.tab.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
}

.tab:hover {
  border-color: transparent;
  border-right-color: #252526;
  background: var(--editor-bg);
}

.tab.active:hover {
  border-color: transparent;
  border-right-color: #252526;
  background: #2d2d2d;
}

.tab-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.tab-close {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
}

.tab-close:hover {
  background: #3c3c3c;
}

.editor {
  min-width: 0;
  min-height: 0;
}

.empty-state {
  position: absolute;
  inset: 36px 0 24px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--editor-bg);
}

.loading-overlay {
  position: absolute;
  inset: 36px 0 24px;
  z-index: 10;
  display: grid;
  place-items: center;
  gap: 12px;
  align-content: center;
  color: var(--text-strong);
  background: rgba(30, 30, 30, 0.72);
  backdrop-filter: blur(2px);
}

.user-panel {
  position: absolute;
  inset: 36px 0 24px;
  z-index: 9;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  background:
    linear-gradient(180deg, rgba(0, 122, 204, 0.08), transparent 180px),
    var(--editor-bg);
}

.user-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid #303030;
  background: #252526;
}

.user-panel-head h2 {
  margin: 0;
  color: var(--text-strong);
  font-size: 15px;
}

.user-panel-body {
  display: grid;
  align-content: start;
  overflow: auto;
  padding: 22px;
}

.user-dashboard {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(360px, 720px);
  grid-template-areas:
    "hero hero"
    "form list";
  align-items: start;
  gap: 16px;
}

.user-dashboard.narrow {
  grid-template-columns: minmax(300px, 460px);
  grid-template-areas:
    "hero"
    "form";
}

.panel-hero {
  grid-area: hero;
  display: grid;
  gap: 5px;
  padding: 16px 18px;
  border: 1px solid #303d46;
  border-radius: 8px;
  background: #20262c;
}

.panel-hero strong {
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 650;
}

.panel-hero span {
  color: var(--muted);
  font-size: 13px;
}

.panel-form {
  grid-area: form;
  display: grid;
  gap: 14px;
}

.user-create-card,
.user-list {
  border: 1px solid #353b42;
  border-radius: 8px;
  background: #202123;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
}

.user-create-card {
  padding: 16px;
}

.card-head {
  display: grid;
  gap: 4px;
  padding-bottom: 4px;
}

.card-head strong,
.list-head strong {
  color: var(--text-strong);
  font-size: 14px;
}

.card-head span,
.list-head span {
  color: var(--muted);
  font-size: 12px;
}

.panel-form label {
  display: grid;
  gap: 6px;
}

.panel-form label > span {
  color: var(--muted);
  font-size: 12px;
}

.panel-form input,
.panel-form select {
  min-height: 34px;
  border: 1px solid #3c3c3c;
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--text);
  background: #1f1f1f;
  outline: none;
}

.panel-form input:focus,
.panel-form select:focus {
  border-color: var(--accent);
}

.primary-action {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: #ffffff;
}

.user-list {
  grid-area: list;
  display: grid;
  max-width: 720px;
  overflow: hidden;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 14px;
  border-bottom: 1px solid #303030;
  background: #25272a;
}

.user-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.user-row:last-child {
  border-bottom: 0;
}

.user-row:hover {
  background: #262b30;
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid #365062;
  border-radius: 8px;
  color: #9cdcfe;
  background: #162633;
  font-weight: 700;
  font-size: 13px;
}

.user-avatar.admin {
  border-color: #6a5225;
  color: #d7ba7d;
  background: #2b2518;
}

.user-meta {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.user-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.role-badge {
  width: fit-content;
  padding: 2px 7px;
  border: 1px solid #3c3c3c;
  border-radius: 4px;
  color: #c8c8c8;
  background: #2a2d2e;
  font-size: 11px;
}

.role-badge.admin {
  border-color: #6a5225;
  color: #d7ba7d;
  background: #2b2518;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  min-height: 30px;
  white-space: nowrap;
}

.danger-action {
  color: #f48771;
}

.danger-action:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

@media (max-width: 980px) {
  .user-dashboard {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "hero"
      "form"
      "list";
  }

  .user-row {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .row-actions {
    grid-column: 2;
  }
}

.spinner,
.mini-spinner {
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.spinner {
  width: 32px;
  height: 32px;
}

.mini-spinner {
  width: 14px;
  height: 14px;
}

.status {
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  padding: 0 10px;
  color: #ffffff;
  background: var(--accent-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.tab-menu,
.context-menu {
  position: fixed;
  z-index: 20;
  display: grid;
  min-width: 158px;
  padding: 4px;
  border: 1px solid #454545;
  border-radius: 6px;
  background: #252526;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.tab-menu button,
.context-menu button {
  border: 0;
  border-radius: 4px;
  text-align: left;
  padding: 8px 10px;
  background: transparent;
}

.tab-menu button:hover,
.context-menu button:hover {
  background: #094771;
}

.image-modal {
  position: fixed;
  inset: 48px;
  z-index: 30;
  display: grid;
  grid-template-rows: 40px minmax(0, 1fr);
  border: 1px solid #454545;
  border-radius: 8px;
  background: #1e1e1e;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}

.image-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid #303030;
  background: #252526;
}

#imageModalTitle {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-strong);
  font-size: 13px;
}

.image-modal-body {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  background: #111111;
}

#imagePreview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.code-modal {
  position: fixed;
  top: 72px;
  left: 50%;
  z-index: 35;
  display: grid;
  grid-template-rows: 40px auto auto minmax(160px, 1fr);
  width: min(720px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 120px));
  transform: translateX(-50%);
  border: 1px solid #454545;
  border-radius: 8px;
  overflow: hidden;
  background: #202123;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.62);
}

.code-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid #303030;
  background: #252526;
}

.code-modal-head strong {
  color: var(--text-strong);
  font-size: 14px;
}

.code-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.code-search-row input,
.code-form input,
.code-form textarea {
  width: 100%;
  border: 1px solid #3c3c3c;
  border-radius: 4px;
  color: var(--text);
  background: #1f1f1f;
  outline: none;
}

.code-search-row input,
.code-form input {
  min-height: 34px;
  padding: 7px 9px;
}

.code-form textarea {
  min-height: 180px;
  resize: vertical;
  padding: 10px;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.code-search-row input:focus,
.code-form input:focus,
.code-form textarea:focus {
  border-color: var(--accent);
}

.code-search-row button,
.code-form button {
  white-space: nowrap;
}

.code-form {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
  background: #1b1b1c;
}

.code-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.code-form-actions button[type='submit'] {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: #ffffff;
}

.code-list {
  min-height: 0;
  overflow: auto;
  background: #181818;
}

.code-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 9px 10px 9px 14px;
  border-bottom: 1px solid #2a2d2e;
  cursor: pointer;
}

.code-item:hover,
.code-item.selected {
  background: #094771;
}

.code-item-meta {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.code-item-meta strong,
.code-item-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-item-meta strong {
  color: var(--text-strong);
  font-size: 13px;
}

.code-item-meta span {
  color: #b8b8b8;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
}

.code-item-actions {
  display: flex;
  gap: 6px;
}

.code-empty {
  padding: 18px 14px;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none;
}

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

@media (max-width: 780px) {
  html,
  body {
    overflow: auto;
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 42vh) minmax(0, 1fr);
    height: 100vh;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    height: auto;
    min-height: 0;
  }
}
