/* Buttons, chips, file grid/list, menus, modals, toasts, upload panel. */

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), opacity 0.15s var(--ease);
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

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

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

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.2);
}

.btn-icon {
  width: 36px;
  padding: 0;
  flex-shrink: 0;
}

.btn-sm {
  height: 30px;
  padding: 0 var(--sp-3);
  font-size: 12px;
}

.btn-sm.btn-icon {
  width: 30px;
}

/* Segmented control (grid/list toggle) */
.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border-radius: var(--r-md);
}

.segmented button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.segmented button:hover {
  color: var(--text);
}

.segmented button.active {
  background: var(--surface-3);
  color: var(--text);
}

/* --- Filter chips --- */
.chip {
  height: 30px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.chip:hover {
  background: var(--surface-2);
  color: var(--text);
}

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-hover);
}

/* --- Dropdown --- */
.dropdown {
  position: relative;
}

.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  padding: var(--sp-1);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  animation: menu-in 0.12s var(--ease);
}

.menu[hidden] {
  display: none;
}

@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 8px var(--sp-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s var(--ease);
}

.menu-item i {
  width: 15px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

.menu-item:hover {
  background: var(--surface-3);
}

.menu-item.danger {
  color: var(--danger);
}

.menu-item.danger i {
  color: var(--danger);
}

.menu-item.danger:hover {
  background: var(--danger-soft);
}

.menu-item .check {
  margin-left: auto;
  color: var(--accent);
  font-size: 11px;
}

.menu-sep {
  height: 1px;
  margin: var(--sp-1) 0;
  background: var(--border);
}

/* Context menu reuses .menu, positioned by JS */
.context-menu {
  position: fixed;
  top: 0;
  left: 0;
}

/* --- File grid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: var(--sp-3);
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: var(--sp-3);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.card:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.card.selected {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.card-thumb {
  display: grid;
  place-items: center;
  height: 82px;
  margin-bottom: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: 30px;
  overflow: hidden;
}

.card.selected .card-thumb {
  background: rgba(0, 0, 0, 0.18);
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-name {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  margin-top: var(--sp-1);
  color: var(--text-dim);
  font-size: 11.5px;
}

/* Selection checkbox + kebab: always visible on touch, on hover for mouse */
.card-check {
  position: absolute;
  top: 8px;
  left: 8px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: transparent;
  font-size: 10px;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s var(--ease);
}

.card:hover .card-check,
.card.selected .card-check,
.card-check:focus-visible {
  opacity: 1;
}

.card.selected .card-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.card-kebab {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s var(--ease), background 0.15s var(--ease);
}

.card:hover .card-kebab,
.card-kebab:focus-visible {
  opacity: 1;
}

.card-kebab:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* Touch devices have no hover, so controls must stay visible */
@media (hover: none) {
  .card-check,
  .card-kebab,
  .row-kebab {
    opacity: 1;
  }
}

.badge-shared {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: var(--r-full);
  background: var(--success);
  color: #06281c;
  font-size: 9px;
}

/* --- File list --- */
.list {
  display: flex;
  flex-direction: column;
}

.list-head {
  display: grid;
  grid-template-columns: 1fr 110px 150px 40px;
  gap: var(--sp-3);
  padding: 0 var(--sp-3) var(--sp-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.list-head button {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.list-head button:hover {
  color: var(--text);
}

.list-head .sort-arrow {
  font-size: 9px;
  opacity: 0;
}

.list-head button.sorted .sort-arrow {
  opacity: 1;
  color: var(--accent);
}

.row {
  display: grid;
  grid-template-columns: 1fr 110px 150px 40px;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s var(--ease);
}

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

.row.selected {
  background: var(--accent-soft);
}

.row-name {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.row-icon {
  width: 20px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}

.row-label {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-meta {
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.row-kebab {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  opacity: 0;
  cursor: pointer;
}

.row:hover .row-kebab,
.row-kebab:focus-visible {
  opacity: 1;
}

.row-kebab:hover {
  background: var(--surface-3);
  color: var(--text);
}

@media (max-width: 700px) {
  .list-head,
  .row {
    grid-template-columns: 1fr 90px 40px;
  }

  .col-modified {
    display: none;
  }
}

@media (max-width: 460px) {
  .list-head,
  .row {
    grid-template-columns: 1fr 40px;
  }

  .col-size {
    display: none;
  }
}

/* File type colors */
.t-folder { color: var(--type-folder); }
.t-image { color: var(--type-image); }
.t-video { color: var(--type-video); }
.t-audio { color: var(--type-audio); }
.t-document { color: var(--type-document); }
.t-archive { color: var(--type-archive); }
.t-text { color: var(--type-text); }
.t-other { color: var(--type-other); }

/* --- Status (uploading / error) --- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
}

.status-processing { color: var(--accent-hover); }
.status-error { color: var(--danger); }
.status-stopped { color: var(--warning); }

.mini-bar {
  height: 3px;
  margin-top: 6px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}

.mini-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-full);
  transition: width 0.3s var(--ease);
}

/* --- Selection toolbar --- */
.selection-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-4);
}

.selection-count {
  font-size: 13px;
  font-weight: 600;
  margin-right: var(--sp-2);
}

.selection-bar .spacer {
  flex: 1;
}

/* --- Empty / loading states --- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-7) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 24px;
}

.empty h3 {
  color: var(--text);
  font-size: 15px;
}

.empty p {
  margin: 0;
  font-size: 13px;
  max-width: 380px;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: var(--r-lg);
  height: 152px;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* --- Modal --- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: rgba(6, 8, 14, 0.7);
  z-index: var(--z-modal);
  animation: fade-in 0.15s var(--ease);
}

.overlay[hidden] {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s var(--ease);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  flex: 1;
  font-size: 15px;
}

.modal-body {
  padding: var(--sp-5);
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5) var(--sp-5);
}

.field {
  margin-bottom: var(--sp-4);
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  margin-bottom: var(--sp-2);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}

.input,
.select {
  width: 100%;
  height: 40px;
  padding: 0 var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  transition: border-color 0.15s var(--ease);
}

.select {
  cursor: pointer;
}

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

.input-copy {
  display: flex;
  gap: var(--sp-2);
}

.input-copy .input {
  font-family: var(--mono);
  font-size: 12px;
}

.hint {
  color: var(--text-dim);
  font-size: 12px;
  margin: var(--sp-2) 0 0;
}

/* --- Preview modal --- */
.preview-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: rgba(6, 8, 14, 0.94);
  z-index: var(--z-modal);
  animation: fade-in 0.15s var(--ease);
}

.preview-overlay[hidden] {
  display: none;
}

.preview-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-body {
  flex: 1;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  overflow: auto;
  min-height: 0;
}

.preview-body img,
.preview-body video {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--r-md);
  object-fit: contain;
}

.preview-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: var(--r-md);
  background: #fff;
}

.preview-body pre {
  width: 100%;
  max-width: 900px;
  max-height: 100%;
  margin: 0;
  padding: var(--sp-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
}

.preview-body audio {
  width: min(520px, 100%);
}

/* --- Upload panel --- */
.uploads {
  position: fixed;
  right: var(--sp-5);
  bottom: var(--sp-5);
  width: 340px;
  max-width: calc(100vw - var(--sp-5) * 2);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-uploads);
  overflow: hidden;
  animation: panel-in 0.2s var(--ease);
}

.uploads[hidden] {
  display: none;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.uploads-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-3);
  font-size: 13px;
  font-weight: 600;
}

.uploads-head .spacer {
  flex: 1;
}

.uploads-list {
  max-height: 280px;
  overflow-y: auto;
}

.uploads.collapsed .uploads-list {
  display: none;
}

.upload-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
}

.upload-info {
  flex: 1;
  min-width: 0;
}

.upload-name {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-phase {
  margin-top: 3px;
  color: var(--text-dim);
  font-size: 11px;
}

.upload-bar {
  height: 3px;
  margin-top: 6px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}

.upload-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-full);
  transition: width 0.3s var(--ease);
}

.upload-state {
  font-size: 13px;
  flex-shrink: 0;
}

/* --- Toasts --- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: var(--sp-5);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 260px;
  max-width: 440px;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  pointer-events: auto;
  animation: toast-in 0.2s var(--ease);
}

.toast.leaving {
  animation: toast-out 0.2s var(--ease) forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(6px); }
}

.toast i {
  font-size: 13px;
}

.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.info i { color: var(--accent-hover); }

/* --- Drag & drop --- */
.drop-veil {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(79, 124, 255, 0.1);
  backdrop-filter: blur(2px);
  border: 3px dashed var(--accent);
  z-index: var(--z-modal);
  pointer-events: none;
}

.drop-veil[hidden] {
  display: none;
}

.drop-veil-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-7);
  background: var(--surface-2);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  font-size: 15px;
  font-weight: 600;
}

.drop-veil-inner i {
  font-size: 32px;
  color: var(--accent);
}

@media (max-width: 560px) {
  .uploads {
    right: var(--sp-3);
    left: var(--sp-3);
    bottom: var(--sp-3);
    width: auto;
  }

  .toasts {
    left: var(--sp-3);
    right: var(--sp-3);
    transform: none;
  }

  .toast {
    min-width: 0;
  }
}
