:root {
  --bg-dark: #08111a;
  --panel: rgba(14, 24, 35, 0.96);
  --panel-soft: rgba(17, 28, 40, 0.92);
  --panel-heavy: rgba(9, 17, 25, 0.98);
  --line: rgba(140, 194, 220, 0.15);
  --line-strong: rgba(140, 194, 220, 0.28);
  --text: #e8f1f5;
  --muted: #b7cad4;
  --soft: #93acb8;
  --accent: #9ad9f0;
  --accent-2: #6ec1e4;
  --danger: #ff7b72;
  --success: #77d8a1;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.34);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  background: var(--bg-dark);
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Rubik", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(110, 193, 228, 0.12), transparent 24%),
    linear-gradient(180deg, #0b1520 0%, #08111a 100%);
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: rgba(9, 17, 25, 0.78);
  color: var(--text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 4px rgba(110, 193, 228, 0.12);
  background: rgba(10, 18, 27, 0.92);
}

textarea {
  resize: vertical;
  font-family: "JetBrains Mono", monospace;
  line-height: 1.55;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: rgba(8, 17, 26, 0.5);
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(111, 191, 225, 0.52), rgba(80, 150, 186, 0.72));
  border: 2px solid rgba(8, 17, 26, 0.82);
  border-radius: 999px;
}

.login-body,
.app-body {
  position: relative;
  min-height: 100vh;
}

.login-shell,
.app-shell {
  height: 100%;
}

.login-shell {
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.login-card,
.header-card,
.view-card,
.sidebar-panel,
.sidebar-section,
.modal-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(17, 28, 40, 0.96), rgba(10, 18, 27, 0.96));
  box-shadow: var(--shadow);
}

.login-card {
  width: min(100%, 480px);
  padding: 32px;
}

.login-brand h1,
.sidebar-brand h1,
.header-card h2,
.card-head h3,
.sidebar-heading h2 {
  margin: 0;
  font-family: "Exo 2", sans-serif;
  letter-spacing: 0.01em;
}

.login-form,
.command-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.login-form label,
.command-form {
  display: grid;
  gap: 8px;
}

button,
.upload-button {
  border: 1px solid rgba(140, 194, 220, 0.14);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(153, 217, 240, 0.96), rgba(110, 193, 228, 0.96));
  color: #0d1a25;
  font-weight: 700;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

button:hover,
.upload-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 34px rgba(110, 193, 228, 0.18);
}

button:disabled,
.upload-button:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ghost-button,
.logout-button,
.menu-item {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
  color: var(--text);
}

.warn-button {
  background: rgba(255, 123, 114, 0.16);
  border-color: rgba(255, 123, 114, 0.28);
  color: #ffd8d5;
}

.form-error {
  color: #ffc9c3;
  font-size: 14px;
}

.captcha-box {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid rgba(140, 194, 220, 0.12);
  border-radius: 10px;
  background: rgba(7, 17, 24, 0.96);
}

.captcha-image {
  display: block;
  width: 220px;
  max-width: 100%;
  height: auto;
}

.error-card {
  text-align: center;
}

.error-code {
  margin-bottom: 14px;
  color: var(--accent);
  font-family: "JetBrains Mono", monospace;
  font-size: clamp(2.8rem, 8vw, 5rem);
  font-weight: 700;
  line-height: 1;
}

.error-text {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.error-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 24px;
  padding: 12px 16px;
  border: 1px solid rgba(140, 194, 220, 0.14);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(153, 217, 240, 0.96), rgba(110, 193, 228, 0.96));
  color: #0d1a25;
  font-weight: 700;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

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

.sidebar-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.sidebar-brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar-top {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.sidebar-section {
  padding: 14px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.sidebar-servers {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sidebar-heading h2 {
  font-size: 0.95rem;
  color: var(--muted);
}

.server-list,
.file-list,
.sidebar-nav {
  display: grid;
  gap: 8px;
}

.server-list {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.server-item,
.file-item,
.nav-item {
  width: 100%;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.025);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  color: var(--text);
  min-width: 0;
}

.server-item strong,
.file-item > span:first-child {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.server-item:hover,
.file-item:hover,
.nav-item:hover {
  border-color: rgba(140, 194, 220, 0.18);
  background: rgba(110, 193, 228, 0.06);
}

.server-item.active {
  border-color: rgba(143, 214, 242, 0.28);
  background: linear-gradient(180deg, rgba(110, 193, 228, 0.12), rgba(110, 193, 228, 0.04));
}

.nav-item.active {
  border-color: rgba(110, 193, 228, 0.24);
  background: rgba(110, 193, 228, 0.12);
}

.sidebar-bottom {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(8, 14, 21, 0.28);
}

.logout-button {
  width: 100%;
}

.main-content {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
}

.server-meta,
.inline-actions,
.server-summary,
.modal-actions,
.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.server-meta {
  margin-top: 8px;
  color: var(--soft);
  font-size: 13px;
}

.header-card {
  padding: 20px 22px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-radius: 14px;
}

.header-copy {
  min-width: 0;
}

.header-card h2 {
  font-size: clamp(1.7rem, 2vw, 2.5rem);
}

.header-actions,
.card-head {
  align-items: center;
  justify-content: space-between;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.view-card {
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 14px;
}

.badge {
  max-width: 100%;
  padding: 8px 11px;
  border: 1px solid rgba(140, 194, 220, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.console-output {
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 16px 18px;
  border: 0;
  background: transparent;
  color: #d4e8f8;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.term-line {
  white-space: pre-wrap;
  word-break: break-word;
}

.term-line-command {
  color: #f5d58d;
}

.term-line-info {
  color: #8fd6f2;
}

.term-line-warn {
  color: #f4cd7a;
}

.term-line-error {
  color: #ff9b88;
}

.term-line-prompt {
  color: #9fe0a7;
}

.ansi-red { color: #ff8c7f; }
.ansi-green { color: #8fdf95; }
.ansi-yellow { color: #f2cf72; }
.ansi-blue { color: #82c8ff; }
.ansi-magenta { color: #d2a8ff; }
.ansi-cyan { color: #7ee7ef; }
.ansi-muted { color: #7f95a3; }

.terminal-shell {
  margin-top: 16px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(110, 193, 255, 0.16);
  border-radius: 10px;
  background: rgba(7, 17, 24, 0.96);
}

.terminal-input-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 12px 18px 14px;
  border-top: 1px solid rgba(110, 193, 255, 0.12);
  font-family: "JetBrains Mono", monospace;
}

.terminal-prompt {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}

.terminal-input {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: #d4e8f8;
  font-family: "JetBrains Mono", monospace;
}

.terminal-input:focus {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.editor {
  margin-top: 16px;
  flex: 1 1 auto;
  min-height: 0;
}

.code-editor-shell {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(110, 193, 255, 0.16);
  border-radius: 10px;
  background: rgba(7, 17, 24, 0.96);
}

.code-highlight,
.code-editor {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  padding: 16px 18px;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow: auto;
}

.code-highlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: #d7e8f6;
  background: transparent;
}

.code-editor {
  position: relative;
  z-index: 1;
  resize: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
  caret-color: #eef5fb;
  box-shadow: none;
}

.code-editor:focus {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.tok-comment { color: #6f8b9b; }
.tok-string { color: #9fe0a7; }
.tok-number { color: #f4cd7a; }
.tok-bool { color: #ff9b88; }
.tok-key { color: #8fd6f2; }
.tok-keyword { color: #c1a8ff; }

.path-label {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(140, 194, 220, 0.12);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  font-family: "JetBrains Mono", monospace;
  overflow-wrap: anywhere;
  flex: 0 0 auto;
}

.file-list {
  margin-top: 14px;
  padding-top: 2px;
  padding-right: 2px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 6px;
  align-content: start;
}

.file-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.file-row {
  text-align: left;
}

.file-row.selected {
  border-color: rgba(110, 193, 228, 0.28);
  background: rgba(110, 193, 228, 0.09);
}

.file-main {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.035);
  align-self: center;
  justify-self: center;
}

.file-text {
  display: grid;
  gap: 1px;
  min-width: 0;
  align-content: center;
}

.file-icon {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: #cfe6f5;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.folder-icon {
  fill: rgba(143, 214, 242, 0.2);
  stroke: #9ad9f0;
}

.file-icon-config { stroke: #8fd6f2; }
.file-icon-code { stroke: #c9b3ff; }
.file-icon-archive { stroke: #f5c777; }
.file-icon-image { stroke: #96e0bb; }
.file-icon-generic { stroke: #cfe6f5; }

.file-name {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
}

.file-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--soft);
  font-size: 11px;
  min-width: 0;
  line-height: 1.2;
}

.file-side {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  flex: 0 0 auto;
  white-space: nowrap;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.upload-button input {
  display: none;
}

.menu-wrap {
  position: relative;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 10;
  min-width: min(280px, 90vw);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-heavy);
  box-shadow: var(--shadow);
}

.menu-item {
  width: 100%;
  margin-bottom: 8px;
  text-align: left;
}

.menu-item:last-child {
  margin-bottom: 0;
}

.status-box {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 123, 114, 0.25);
  border-radius: 10px;
  background: rgba(255, 123, 114, 0.08);
  color: #ffd8d5;
  flex: 0 0 auto;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.64);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(100% - 32px, 560px);
  margin: 6vh auto 0;
  padding: 22px;
}

.modal-wide {
  width: min(100% - 32px, 1080px);
}

.modal-editor {
  min-height: min(68vh, 780px);
}

.hidden {
  display: none !important;
}

#promptInput {
  margin-top: 14px;
}

.modal-text {
  margin: 10px 0 0;
  color: var(--muted);
}

.upload-pickers {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.upload-picker {
  min-width: 150px;
}

.context-menu {
  position: fixed;
  z-index: 70;
  min-width: 220px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(10, 18, 27, 0.98);
  box-shadow: var(--shadow);
}

.context-item {
  width: 100%;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  box-shadow: none;
  transform: none;
}

.context-item:hover {
  background: rgba(110, 193, 228, 0.1);
  box-shadow: none;
  transform: none;
}

.context-item.disabled {
  opacity: 0.45;
}

.context-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 13px 14px;
  border: 1px solid rgba(140, 194, 220, 0.16);
  border-radius: 12px;
  background: rgba(10, 18, 27, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  border-color: rgba(119, 216, 161, 0.28);
}

.toast-info {
  border-color: rgba(143, 214, 242, 0.24);
}

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

  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .sidebar {
    order: 1;
  }

  .main-content {
    order: 2;
    grid-template-rows: auto auto;
  }

  .header-card {
    flex-direction: column;
    align-items: stretch;
  }

  .menu-wrap,
  .menu-dropdown {
    width: 100%;
  }

  .menu-dropdown {
    right: auto;
    left: 0;
  }

  .sidebar-panel,
  .view-card {
    height: auto;
  }
}

@media (max-width: 720px) {
  .app-shell,
  .login-shell {
    padding: 16px;
  }

  .login-card,
  .sidebar-panel,
  .header-card,
  .view-card,
  .modal-card {
    padding: 18px;
    border-radius: 22px;
  }

  .sidebar-brand {
    padding: 0 0 14px;
  }

  .sidebar-bottom,
  .sidebar-section {
    padding-left: 0;
    padding-right: 0;
  }

  .command-form,
  .file-item {
    grid-template-columns: 1fr;
  }

  .file-main {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .file-meta-line {
    gap: 4px;
  }

  .file-side {
    display: none;
  }

  .terminal-input-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .inline-actions,
  .header-actions,
  .modal-actions {
    width: 100%;
  }

  .inline-actions > *,
  .header-actions > *,
  .modal-actions > * {
    flex: 1 1 100%;
  }

  .console-output,
  .editor,
  .file-list {
    flex-basis: auto;
    max-height: none;
    min-height: 280px;
  }

  .modal-card {
    margin-top: 3vh;
  }
}
