:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #627083;
  --line: #d9e0ea;
  --primary: #1463ff;
  --primary-hover: #0c4fd0;
  --secondary: #eef3f8;
  --secondary-hover: #e0e8f1;
  --error-bg: #fff1f2;
  --error-text: #9f1239;
  --success-bg: #ecfdf5;
  --success-text: #047857;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 20px 70px rgba(24, 33, 47, 0.1);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

input[type="text"],
input[type="password"],
input:not([type]) {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

input:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(20, 99, 255, 0.22);
  outline-offset: 2px;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

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

.secondary-button {
  background: var(--secondary);
  color: var(--text);
  font-weight: 700;
}

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

.danger-button {
  background: #fee2e2;
  color: #991b1b;
  font-weight: 800;
}

.danger-button:hover {
  background: #fecaca;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.ghost-button:hover {
  color: var(--text);
  background: #fff;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 48px;
}

.topbar,
.pathbar,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  min-height: 58px;
}

.app-title {
  font-weight: 800;
  text-decoration: none;
  font-size: 18px;
}

.account {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.pathbar {
  min-height: 56px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  color: var(--muted);
}

.breadcrumbs a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

.breadcrumbs span:last-child {
  color: var(--text);
  font-weight: 700;
}

.alert {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 700;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-text);
}

.auth-switch {
  margin-top: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.auth-switch a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.actions {
  align-items: stretch;
  margin: 18px 0;
  flex-wrap: wrap;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.upload-form {
  flex: 1 1 auto;
}

.mkdir-form {
  flex: 0 1 390px;
}

.selection-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.selection-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

.file-picker {
  min-height: 42px;
  border: 1px dashed #9eacbf;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 160px;
}

.file-picker input {
  width: 1px;
  height: 1px;
  position: absolute;
  opacity: 0;
}

.selected-file-list {
  flex: 1 0 100%;
  max-height: 94px;
  overflow: auto;
  display: none;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.selected-file-list.is-visible {
  display: block;
}

.selected-file-list ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.selected-file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-top: 1px solid #edf1f6;
  word-break: break-all;
}

.selected-file-list li:first-child {
  border-top: 0;
}

.selected-file-list li span {
  min-width: 0;
}

.selected-file-list strong {
  color: var(--text);
}

.selected-file-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.selected-file-clear,
.selected-file-remove {
  border: 0;
  border-radius: 6px;
  background: #eef3f8;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 7px;
  white-space: nowrap;
}

.selected-file-clear:hover,
.selected-file-remove:hover {
  background: #fee2e2;
  color: #991b1b;
}

.upload-progress {
  flex: 1 0 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.upload-progress[hidden] {
  display: none;
}

.upload-progress-bar {
  height: 10px;
  border-radius: 999px;
  background: #e7edf5;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.18s ease;
}

.upload-progress-active .upload-progress-fill {
  background: #2563eb;
}

.upload-progress-complete .upload-progress-fill {
  background: #16a34a;
}

.upload-progress-error .upload-progress-fill {
  background: #dc2626;
}

.upload-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  flex-wrap: wrap;
}

.upload-progress-status {
  color: var(--text);
  font-weight: 800;
}

.upload-progress-detail {
  text-align: right;
}

.browser-layout {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.tree-panel {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.folder-tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.folder-tree ul ul {
  margin-left: 10px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.tree-node {
  min-width: 0;
}

.tree-node details {
  min-width: 0;
}

.tree-node summary {
  display: flex;
  align-items: center;
  min-width: 0;
  list-style: none;
}

.tree-node summary::-webkit-details-marker {
  display: none;
}

.tree-node summary::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid #7a8798;
  margin: 0 7px 0 4px;
  flex: 0 0 auto;
  transform: rotate(0deg);
}

.tree-node details[open] > summary::before {
  transform: rotate(90deg);
}

.tree-link {
  min-width: 0;
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 7px;
  padding: 6px 8px;
  color: var(--text);
  text-decoration: none;
  flex: 1 1 auto;
}

.tree-link:hover {
  background: #eef3f8;
}

.tree-node.is-current > .tree-link,
.tree-node.is-current > details > summary .tree-link {
  background: #e9f1ff;
  color: var(--primary);
  font-weight: 800;
}

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

.tree-icon {
  width: 17px;
  height: 13px;
  position: relative;
  flex: 0 0 auto;
  border-radius: 3px;
  background: #f6c85f;
  box-shadow: inset 0 -3px 0 rgba(120, 82, 18, 0.08);
}

.tree-icon::before {
  content: "";
  position: absolute;
  left: 0;
  top: -4px;
  width: 8px;
  height: 5px;
  border-radius: 3px 3px 0 0;
  background: #eab84c;
}

.selection-form {
  min-width: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 200px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
}

.selectable-item {
  position: relative;
}

.item-check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(98, 112, 131, 0.24);
  cursor: pointer;
}

.item-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.item-check span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.folder-item {
  display: block;
  padding: 0;
}

.folder-main {
  min-height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 14px;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}

.folder-thumb {
  min-height: 126px;
  display: grid;
  place-items: center;
  background: #eef3f8;
  border-radius: 8px;
}

.folder-thumb span {
  width: 86px;
  height: 62px;
  position: relative;
  border-radius: 7px;
  background: #f6c85f;
  box-shadow: inset 0 -12px 0 rgba(120, 82, 18, 0.08);
}

.folder-thumb span::before {
  content: "";
  position: absolute;
  left: 0;
  top: -16px;
  width: 42px;
  height: 20px;
  border-radius: 7px 7px 0 0;
  background: #eab84c;
}

.folder-item strong,
.file-meta strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.folder-zip-link {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  padding: 5px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
}

.file-item {
  display: grid;
  grid-template-rows: minmax(144px, 1fr) auto;
}

.preview-button,
.file-static {
  position: relative;
  width: 100%;
  min-height: 144px;
  border: 0;
  padding: 0;
  background: #e8eef5;
}

.preview-button {
  cursor: zoom-in;
}

.file-static {
  display: block;
}

.preview-button img,
.file-static img {
  width: 100%;
  height: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

.file-static img {
  object-fit: contain;
  padding: 18px;
}

.kind-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(24, 33, 47, 0.82);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.file-meta {
  min-height: 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
}

.download-link {
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 180px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.preview-dialog {
  width: min(1040px, calc(100% - 28px));
  max-height: min(860px, calc(100% - 28px));
  border: 0;
  padding: 0;
  border-radius: 8px;
  background: #0f172a;
  color: #fff;
}

.preview-dialog::backdrop {
  background: rgba(15, 23, 42, 0.74);
}

.preview-header {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.preview-header strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-body {
  min-height: 240px;
  display: grid;
  place-items: center;
  padding: 12px;
}

.preview-body img,
.preview-body video {
  max-width: 100%;
  max-height: calc(100vh - 130px);
  display: block;
}

.preview-body video {
  width: 100%;
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
  }

  .topbar,
  .pathbar,
  .actions,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .account,
  .preview-header {
    align-items: stretch;
  }

  .account {
    width: 100%;
    justify-content: space-between;
  }

  .mkdir-form {
    flex-basis: auto;
  }

  .browser-layout {
    grid-template-columns: 1fr;
  }

  .tree-panel {
    position: static;
    max-height: 260px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
    gap: 10px;
  }

  .item {
    min-height: 176px;
  }

  .preview-header {
    flex-direction: column;
  }

  .preview-actions {
    width: 100%;
  }

  .preview-actions .secondary-button,
  .preview-actions .ghost-button {
    flex: 1 1 0;
  }
}
