:root {
  --bg: #f4f7fb;
  --bg-accent: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fbfd;
  --text: #142132;
  --muted: #5a6b7f;
  --border: #d8e1ea;
  --accent: #2f6fed;
  --accent-strong: #1f57c7;
  --danger: #c53a3a;
  --danger-strong: #9f2f2f;
  --shadow: 0 10px 24px rgba(17, 35, 68, 0.06);
  --radius: 10px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Inter", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg-accent);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.webui-nav, .page, .auth-card, .panel, .resource-table, .flash, .btn, input {
  /* later tasks extend these selectors; keep the token names stable */
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.auth-card,
.panel,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.webui-shell {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(216, 225, 234, 0.9);
  backdrop-filter: blur(18px);
}

.webui-nav {
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 1.75rem;
}

.webui-nav a {
  color: var(--text);
}

.webui-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 160px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-mark {
  width: 1.7rem;
  height: 1.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.brand-mark svg,
.sidebar-icon svg,
.icon-button svg,
.bucket-hero-icon svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}

.webui-brand:hover,
.webui-nav-links a:hover,
.resource-link:hover {
  text-decoration: none;
}

.webui-nav-links {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.webui-nav-links a {
  color: var(--muted);
  font-weight: 600;
}

.webui-nav-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.app-sidebar {
  position: fixed;
  top: 4.7rem;
  left: 0;
  bottom: 0;
  width: 230px;
  padding: 1.75rem 1.25rem 8rem;
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.55);
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3rem;
  padding: 0 1rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 650;
  min-width: 0;
}

.sidebar-link:hover {
  text-decoration: none;
}

.sidebar-link.active {
  background: #eef3ff;
  color: var(--accent);
}

.sidebar-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-section {
  display: grid;
  gap: 0.25rem;
  margin-top: 1.25rem;
}

.sidebar-section-title {
  padding: 0 1rem 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-bucket {
  min-height: 2.55rem;
  font-size: 0.92rem;
}

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

.sidebar-empty {
  margin: 0;
  padding: 0.75rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.storage-card {
  position: absolute;
  left: 1.25rem;
  right: 1.25rem;
  bottom: 1.75rem;
  display: grid;
  gap: 0.25rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.storage-card span {
  color: var(--muted);
  font-size: 0.85rem;
}

.storage-card strong {
  font-size: 1.15rem;
}

.page {
  max-width: 980px;
  margin: 0 2rem 0 260px;
  padding: 2.25rem 0 3rem;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1,
.auth-copy h1 {
  margin: 0;
  font-size: 2.25rem;
  line-height: 1.12;
  text-wrap: balance;
}

.page-header p:last-child,
.auth-copy p:last-child {
  max-width: 42rem;
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-weight: 700;
}

.auth-card {
  width: min(460px, 100%);
  padding: 2rem;
}

.auth-copy {
  margin-bottom: 1.5rem;
}

.auth-form,
.stack-form {
  display: grid;
  gap: 0.9rem;
}

label {
  font-weight: 600;
  font-size: 0.95rem;
}

input[type="text"],
input[type="password"],
input[type="file"],
input:not([type]) {
  width: 100%;
  min-height: 3rem;
  padding: 0.75rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(47, 111, 237, 0.18);
  outline-offset: 2px;
  border-color: var(--accent);
}

.panel {
  padding: 1.25rem;
}

.card {
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.panel + .panel,
.page-header + .flash,
.flash + .panel {
  margin-top: 1.25rem;
}

.panel-form {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfd 100%);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.input-row input {
  flex: 1 1 auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.65rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-secondary {
  background: var(--surface-soft);
  border-color: var(--border);
  color: var(--text);
}

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

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--danger-strong);
}

.btn-quiet {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-quiet:hover {
  background: var(--surface);
  color: var(--text);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 2.35rem;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
}

.btn-nowrap {
  flex: 0 0 auto;
  white-space: nowrap;
}

.flash {
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.flash-error {
  border-color: rgba(197, 58, 58, 0.2);
  background: #fff3f3;
  color: #8f2424;
}

.flash-success {
  border-color: rgba(47, 111, 237, 0.18);
  background: #eef4ff;
  color: var(--accent-strong);
}

.resource-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

.resource-table,
table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

.resource-table th,
.resource-table td {
  padding: 0.95rem 1.15rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.resource-table th,
.resource-table td,
th,
td {
  padding: 0.95rem 1.15rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.resource-table th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.resource-table th,
th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.resource-table tbody tr:last-child td {
  border-bottom: none;
}

.resource-table tbody tr:last-child td,
tr:last-child td {
  border-bottom: none;
}

.resource-link {
  font-weight: 700;
  color: var(--text);
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.empty-state {
  padding: 1rem 0;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: 1.2rem;
}

.empty-state p {
  margin: 0.65rem auto 0;
  max-width: 34rem;
  color: var(--muted);
}

.empty {
  padding: 1rem 0;
  color: var(--muted);
  text-align: center;
}

.breadcrumbs {
  margin-bottom: 1rem;
  color: var(--muted);
}

.breadcrumbs a {
  margin-right: 0.25rem;
}

.workspace-header {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.workspace-header h1 {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.workspace-header p:last-child {
  max-width: 44rem;
  margin: 0.45rem 0 0;
  color: var(--muted);
}

.bucket-heading {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.bucket-hero-icon {
  width: 4.5rem;
  height: 4.5rem;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #eaf1ff;
  color: var(--accent);
}

.bucket-hero-icon svg {
  width: 2rem;
  height: 2rem;
}

.form-title {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.bucket-create-row {
  margin-top: 0.4rem;
}

.file-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  margin-bottom: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.toolbar-primary,
.toolbar-upload-form,
.toolbar-folder-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.new-folder-menu {
  position: relative;
  margin-left: auto;
}

.new-folder-menu summary {
  list-style: none;
}

.new-folder-menu summary::-webkit-details-marker {
  display: none;
}

.new-folder-form {
  position: absolute;
  z-index: 8;
  top: calc(100% + 0.5rem);
  right: 0;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 0.6rem;
  width: min(390px, calc(100vw - 2rem));
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.new-folder-form input {
  min-height: 2.35rem;
}

.file-drop-target {
  position: relative;
}

.file-drop-target > .panel {
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: none;
}

.upload-queue + .file-drop-target > .panel {
  border-top: none;
}

.file-drop-target[data-drag-active="true"] .panel {
  border-color: var(--accent);
  background: #f7faff;
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.12);
}

.toolbar-hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.upload-queue {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0;
  padding: 1rem 1.1rem;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #fbfcfe;
}

.upload-queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.upload-queue-title {
  font-size: 0.95rem;
  font-weight: 700;
}

.upload-queue-summary {
  color: var(--muted);
  font-size: 0.85rem;
}

.upload-queue-list {
  display: grid;
  gap: 0.6rem;
}

.upload-item {
  display: grid;
  gap: 0.45rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.96);
}

.upload-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
}

.upload-item-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.upload-item-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
}

.upload-item-status[data-state="uploading"] {
  color: var(--accent);
}

.upload-item-status[data-state="done"] {
  color: #16775a;
}

.upload-item-status[data-state="failed"] {
  color: var(--danger);
}

.upload-item-progress {
  height: 0.45rem;
  overflow: hidden;
  border-radius: 999px;
  background: #e7edf5;
}

.upload-item-progress > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0%, #5c92ff 100%);
  transition: width 140ms ease-out;
}

.upload-item[data-state="done"] .upload-item-progress > span {
  background: linear-gradient(90deg, #16775a 0%, #2ea67f 100%);
}

.upload-item[data-state="failed"] .upload-item-progress > span {
  background: linear-gradient(90deg, var(--danger) 0%, #ef6b6b 100%);
}

.file-table td {
  vertical-align: middle;
}

.file-table tbody tr {
  transition: background-color 120ms ease;
}

.file-table tbody tr:hover {
  background: #f8fbfd;
}

.file-table .row-actions {
  display: grid;
  grid-template-columns: repeat(3, 2.35rem);
  justify-content: end;
  align-items: center;
  gap: 0.5rem;
}

.file-cell {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 0.75rem;
}

.item-icon {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--muted);
}

.item-icon svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}

.folder-icon {
  background: #eef5ff;
  color: var(--accent-strong);
}

.bucket-icon {
  background: #edf7f3;
  color: #16775a;
}

.file-icon {
  background: #f3f6fa;
  color: #526274;
}

.parent-icon {
  background: #eef4ff;
  color: var(--accent);
}

.file-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 650;
  color: var(--text);
}

.numeric-cell,
.muted-cell {
  color: var(--muted);
  white-space: nowrap;
}

.actions-cell {
  text-align: right;
}

.icon-button {
  width: 2.35rem;
  height: 2.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

.icon-button:hover {
  background: var(--surface-soft);
  text-decoration: none;
}

.icon-button.primary {
  border-color: rgba(47, 111, 237, 0.28);
  color: var(--accent);
}

.icon-button.danger {
  border-color: rgba(197, 58, 58, 0.28);
  color: var(--danger);
}

.placeholder-action {
  visibility: hidden;
  pointer-events: none;
}

.rename-menu {
  position: relative;
}

.rename-menu summary {
  list-style: none;
}

.rename-menu summary::-webkit-details-marker {
  display: none;
}

.rename-form {
  position: absolute;
  z-index: 5;
  bottom: calc(100% + 0.4rem);
  right: 0;
  display: flex;
  gap: 0.5rem;
  width: min(340px, calc(100vw - 2rem));
  padding: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.rename-form input {
  min-height: 2.35rem;
}

.empty-state-inline {
  padding: 2rem 1rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[data-busy-target][data-busy="true"] {
  opacity: 0.7;
  transition: opacity 120ms ease-out;
}

@media (max-width: 720px) {
  .auth-shell {
    padding: 1rem;
  }

  .auth-card,
  .panel {
    padding: 1.25rem;
  }

  .webui-nav {
    width: calc(100% - 1.5rem);
    flex-wrap: wrap;
    padding-left: 0;
    padding-right: 0;
  }

  .app-sidebar {
    display: none;
  }

  .webui-nav-actions {
    width: 100%;
    margin-left: 0;
  }

  .page {
    width: calc(100% - 1.5rem);
    margin-left: auto;
    padding: 1.5rem 0 2rem;
  }

  .input-row,
  .inline-form {
    flex-wrap: wrap;
  }

  .file-toolbar,
  .upload-queue-header,
  .upload-item-header,
  .toolbar-primary,
  .toolbar-upload-form,
  .toolbar-folder-form,
  .new-folder-menu {
    align-items: stretch;
    width: 100%;
  }

  .upload-queue-header,
  .upload-item-header {
    justify-content: flex-start;
  }

  .new-folder-menu {
    margin-left: 0;
  }

  .new-folder-menu .btn,
  .toolbar-upload-form .btn {
    width: 100%;
  }

  .input-row .btn,
  .webui-nav-actions .btn,
  .inline-form .btn {
    width: 100%;
  }

  .resource-table,
  table,
  .resource-table thead,
  thead,
  .resource-table tbody,
  tbody,
  .resource-table tr,
  tr,
  .resource-table th,
  th,
  .resource-table td,
  td {
    display: block;
  }

  .resource-table thead {
    display: none;
  }

  thead {
    display: none;
  }

  .resource-table tr + tr {
    border-top: 1px solid var(--border);
  }

  tr + tr {
    border-top: 1px solid var(--border);
  }

  .resource-table td {
    padding: 0.75rem 0;
    border-bottom: none;
  }

  td {
    padding: 0.75rem 0;
    border-bottom: none;
  }

  .file-table .row-actions {
    justify-content: start;
  }

  .actions-cell {
    text-align: left;
  }

  .rename-form,
  .new-folder-form {
    position: static;
    width: 100%;
    margin-top: 0.5rem;
    box-shadow: none;
  }

  .new-folder-form {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .file-drop-target[data-drag-active="true"] .panel {
    transform: none;
  }
}
