:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef2f6;
  --line: #d9e0e7;
  --line-strong: #c3ccd6;
  --text: #17202a;
  --muted: #687483;
  --accent: #256f63;
  --accent-strong: #194f46;
  --accent-soft: #e3f2ee;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --shadow: 0 12px 28px rgba(22, 34, 47, .08);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(227, 242, 238, .8), rgba(246, 247, 249, 0) 210px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.upload-box {
  touch-action: manipulation;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, border-color .16s ease, opacity .16s ease;
}

button:active,
.upload-box:active {
  transform: scale(.985);
}

button:disabled {
  cursor: not-allowed;
  opacity: .42;
}

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

button.tiny {
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
}

.app {
  width: min(980px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 66px;
  margin: calc(-1 * max(14px, env(safe-area-inset-top))) -14px 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  background: rgba(246, 247, 249, .92);
  border-bottom: 1px solid rgba(217, 224, 231, .78);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.05;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.meta-row,
.header-actions,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meta-row span {
  display: none;
}

.panel {
  margin-top: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.install-prompt {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 0 0 10px;
  padding: 12px;
  background: #10231f;
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.install-prompt[hidden] {
  display: none;
}

.install-prompt strong {
  display: block;
  margin-bottom: 3px;
  font-size: 15px;
}

.install-prompt p {
  margin: 0;
  color: rgba(255, 255, 255, .78);
  font-size: 13px;
  line-height: 1.35;
}

.install-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.install-actions button {
  background: #fff;
  color: var(--accent-strong);
}

.install-actions .ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, .26);
}

.uploader {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.upload-box {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 12px;
  background: var(--accent-soft);
  border: 1px solid rgba(37, 111, 99, .22);
  border-radius: 8px;
  color: var(--accent-strong);
  font-weight: 800;
  cursor: pointer;
}

.upload-box input {
  display: none;
}

.upload-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

.queue-panel {
  min-width: 0;
}

.muted {
  color: var(--muted);
}

.selected-files {
  min-height: 20px;
  font-size: 14px;
  font-weight: 650;
}

.selected-file-list {
  display: grid;
  gap: 7px;
  max-height: 184px;
  margin: 8px 0 0;
  padding: 0;
  overflow: auto;
  color: var(--muted);
  font-size: 13px;
  list-style: none;
}

.selected-file-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 36px;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 6px 6px 6px 10px;
  background: var(--surface-soft);
  border-radius: 8px;
}

.selected-file-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-file-list strong {
  font-size: 12px;
  white-space: nowrap;
}

.selected-file-list button {
  display: grid;
  min-width: 36px;
  min-height: 36px;
  place-items: center;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border: 0;
  font-size: 22px;
}

.progress {
  height: 8px;
  overflow: hidden;
  background: var(--surface-soft);
  border-radius: 999px;
}

.progress div {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width .2s ease;
}

#uploadStatus {
  min-height: 20px;
  margin: 0;
  font-size: 13px;
}

.toolbar {
  display: grid;
  gap: 10px;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  overflow-x: auto;
  color: var(--muted);
  white-space: nowrap;
  scrollbar-width: none;
}

.breadcrumbs::-webkit-scrollbar {
  display: none;
}

.breadcrumbs button {
  min-height: 34px;
  padding: 0 10px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  border: 1px solid transparent;
}

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

.toolbar-actions button {
  flex: 0 0 auto;
  padding: 0 14px;
}

.toolbar-actions #newFolderBtn {
  flex: 1 1 100%;
}

.toolbar-actions #moveRootBtn {
  flex: 1 1 100%;
}

.sort-select {
  flex: 0 0 auto;
  appearance: none;
  -webkit-appearance: none;
  width: auto;
  min-height: 30px;
  padding: 0 26px 0 10px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 8px center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .16s ease, background-color .16s ease;
}

.sort-select:focus {
  outline: none;
  border-color: rgba(37, 111, 99, .5);
}

.ghost.active {
  background: var(--accent-soft);
  border-color: rgba(37, 111, 99, .26);
  color: var(--accent-strong);
}

.list-panel {
  box-shadow: none;
}

.drag-hint {
  margin-bottom: 10px;
  padding: 11px 12px;
  background: var(--accent-soft);
  border: 1px dashed rgba(37, 111, 99, .35);
  border-radius: 8px;
  color: var(--accent-strong);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.items {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.items.grid-view {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body.dragging-files {
  touch-action: none;
  overflow: hidden;
}

.item.dragging {
  opacity: .45;
}

.item.pending {
  opacity: .74;
}

.item.drop-target {
  outline: 3px solid var(--accent);
  background: var(--accent-soft);
  transform: scale(1.02);
  transition: transform .12s ease;
}

body.dragging-files .item[data-type="folder"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(37, 111, 99, .18);
}

.drag-ghost {
  position: fixed;
  z-index: 9999;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: max-content;
  max-width: 260px;
  padding: 10px 14px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, .22);
  opacity: .96;
  pointer-events: none;
  transform: translate3d(0, 0, 0);
}

.drag-ghost-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  background: var(--surface-soft);
  border-radius: 8px;
  font-size: 20px;
}

.drag-ghost-name {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

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

.item[data-type="folder"] .item-main {
  cursor: pointer;
}

.item-main > span {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  background: var(--surface-soft);
  border-radius: 8px;
  font-size: 20px;
}

.item-name {
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  font-weight: 760;
  line-height: 1.24;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 108px;
  scrollbar-width: none;
}

.actions::-webkit-scrollbar {
  display: none;
}

.actions button {
  min-height: 30px;
  flex: 0 0 auto;
  padding: 0 10px;
  font-size: 12px;
}

.actions .danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.actions .ai-action {
  background: #1d4ed8;
  color: #fff;
  border-color: transparent;
}

.actions .reels-action {
  background: #0f766e;
  color: #fff;
  border-color: transparent;
}

.thumbnail {
  display: grid;
  width: 100%;
  aspect-ratio: 1 / 1;
  place-items: center;
  object-fit: cover;
  background: var(--surface-soft);
  border-radius: 8px;
  color: var(--accent-strong);
  font-size: 38px;
}

.items.grid-view .item {
  grid-template-columns: 1fr;
  align-content: start;
  align-items: stretch;
}

.items.grid-view .item-main {
  grid-template-columns: 1fr;
  gap: 9px;
}

.items.grid-view .item-main > span {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  font-size: 38px;
}

.items.grid-view .actions {
  display: grid;
  grid-template-columns: 1fr;
  min-width: 0;
  overflow: visible;
}

.empty {
  padding: 28px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

dialog {
  width: min(100% - 28px, 420px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(22, 34, 47, .22);
}

#aiDialog {
  width: min(100% - 32px, 760px);
}

#logsDialog {
  width: min(100% - 28px, 920px);
}

dialog::backdrop {
  background: rgba(17, 24, 39, .38);
  backdrop-filter: blur(3px);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.dialog-form h2 {
  margin: 0;
  font-size: 19px;
}

.dialog-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.compression-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.compression-option {
  display: grid;
  min-height: 72px;
  padding: 10px;
  place-items: center;
  background: var(--accent);
}

.compression-option strong {
  font-size: 20px;
  line-height: 1;
}

.compression-option span {
  font-size: 12px;
  font-weight: 700;
  opacity: .9;
}

.compress-dialog-form menu {
  grid-template-columns: 1fr;
}

.logs-dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.logs-dialog-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.logs-dialog-form {
  max-height: min(86dvh, 760px);
}

.logs-content {
  min-height: 240px;
  max-height: 56dvh;
  margin: 0;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #101828;
  color: #f8fafc;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}

.logs-dialog-form menu {
  grid-template-columns: 1fr;
}

.ai-dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 2;
  margin: -16px -16px 0;
  padding: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.ai-dialog-head h2 {
  min-width: 0;
}

.ai-dialog-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.ai-dialog-form {
  max-height: min(86dvh, 760px);
  overflow: auto;
}

.ai-result {
  display: grid;
  gap: 10px;
}

.ai-result-block {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ai-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ai-result-head strong {
  font-size: 13px;
}

.ai-result-block p {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

@media (min-width: 700px) {
  .ai-result {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ai-result-block {
    align-content: start;
  }
}

.dialog-form input,
.login-form input {
  width: 100%;
  min-height: 50px;
  padding: 0 13px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
}

.dialog-form input:focus,
.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 111, 99, .13);
}

menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.login-screen {
  display: grid;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
  margin: 0;
  padding: 18px;
}

.login-panel h1 {
  margin: 4px 0 8px;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: 0;
}

.login-panel .muted {
  margin: 0 0 20px;
  font-size: 14px;
}

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

.login-form button {
  width: 100%;
}

#loginError {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 14px;
  font-weight: 650;
}

@media (max-width: 380px) {
  .items.grid-view {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 699px) {
  dialog[open] {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 12px 12px 0 0;
  }
}

@media (min-width: 700px) {
  body {
    background:
      linear-gradient(180deg, rgba(227, 242, 238, .8), rgba(246, 247, 249, 0) 300px),
      var(--bg);
  }

  .app {
    padding: 24px 24px 36px;
  }

  .topbar {
    position: static;
    min-height: auto;
    margin: 0 0 16px;
    padding: 0;
    background: transparent;
    border: 0;
    backdrop-filter: none;
  }

  .install-prompt {
    display: none;
  }

  .topbar h1 {
    font-size: 34px;
  }

  .meta-row span {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    padding: 0 10px;
    color: var(--muted);
    background: rgba(255, 255, 255, .7);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
  }

  .uploader {
    grid-template-columns: minmax(240px, 1fr) minmax(220px, 1.1fr) auto;
    align-items: start;
  }

  .progress,
  #uploadStatus {
    grid-column: 1 / -1;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

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

  .toolbar-actions #newFolderBtn,
  .toolbar-actions #moveRootBtn {
    flex: 0 0 auto;
  }

  .sort-select {
    width: auto;
    min-width: 110px;
    min-height: 34px;
    font-size: 13px;
    padding: 0 28px 0 12px;
  }

  .actions {
    flex-direction: row;
    align-items: center;
    min-width: 0;
    gap: 7px;
  }

  .actions button {
    min-height: 38px;
    padding: 0 12px;
    font-size: 13px;
  }

  .items.grid-view {
    grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  }

  .items.grid-view .item {
    grid-template-columns: 1fr;
  }

  .items.grid-view .actions {
    display: flex;
    flex-wrap: wrap;
  }
}
