:root {
  --bg: #0f172a;
  --bg-deep: #0b1120;
  --surface: #1e293b;
  --surface-2: #253349;
  --border: #334155;
  --border-soft: #2a3850;
  --text: #f8fafc;
  --text-dim: #94a3b8;
  --text-faint: #64748b;
  --accent: #22c55e;
  --accent-dim: #16a34a;
  --accent-soft: rgba(34, 197, 94, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --amber: #fbbf24;
  --blue: #60a5fa;
  --radius: 10px;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ═══ LOGIN ═══ */
.login-view {
  height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(34, 197, 94, 0.10), transparent),
    var(--bg-deep);
}

.login-card {
  width: min(380px, 90vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo svg {
  width: 52px; height: 52px;
  color: var(--accent);
  margin-bottom: 16px;
}

.login-card h1 {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.login-sub { color: var(--text-dim); margin: 6px 0 28px; }

.login-card input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 14px;
  transition: border-color 0.2s;
}

.login-card input:focus { outline: none; border-color: var(--accent); }

.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #052e16;
  font-weight: 600;
  font-size: 15px;
  border: none;
  border-radius: var(--radius);
  transition: background 0.2s;
}

.login-card button:hover { background: #4ade80; }
.login-card button:disabled { opacity: 0.6; cursor: wait; }

.login-error { color: var(--danger); margin-top: 12px; font-size: 13px; }

/* ═══ LAYOUT ═══ */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

/* ═══ SIDEBAR ═══ */
.sidebar {
  background: var(--bg-deep);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.logo-icon { width: 26px; height: 26px; color: var(--accent); flex-shrink: 0; }

.logo-text {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.5px;
}

.sidebar-search {
  position: relative;
  padding: 12px;
}

.sidebar-search svg {
  position: absolute;
  left: 24px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--text-faint);
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.2s;
}

.sidebar-search input:focus { outline: none; border-color: var(--accent); }
.sidebar-search input::placeholder { color: var(--text-faint); }

.bucket-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
  min-height: 0;
}

.bucket-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
  transition: background 0.15s;
  overflow: hidden;
}

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

.bucket-item.active { background: var(--accent-soft); }

.bucket-name {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  padding: 8px 4px 8px 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12.5px;
  text-align: left;
  transition: color 0.15s;
}

.bucket-name svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.7; }

.bucket-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bucket-item:hover .bucket-name { color: var(--text); }
.bucket-item.active .bucket-name { color: var(--accent); }

.bucket-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  margin-right: 6px;
  flex-shrink: 0;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.bucket-item:hover .bucket-del { opacity: 1; }
.bucket-del:hover { background: var(--danger-soft); color: var(--danger); }
.bucket-del svg { width: 13px; height: 13px; }

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border-soft);
}

.bucket-count { color: var(--text-faint); font-size: 12px; font-family: var(--font-mono); }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}

.ghost-btn:hover { background: var(--surface); color: var(--text); }
.ghost-btn svg { width: 15px; height: 15px; }

/* ═══ MAIN ═══ */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-faint);
}

.empty-state svg { width: 72px; height: 72px; opacity: 0.35; margin-bottom: 10px; }
.empty-state h2 { color: var(--text-dim); font-size: 18px; font-weight: 600; }

.browser { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border-soft);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
  overflow-x: auto;
  white-space: nowrap;
  min-width: 0;
}

.breadcrumbs .crumb {
  background: none;
  border: none;
  color: var(--text-dim);
  font: inherit;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.breadcrumbs .crumb:hover { background: var(--surface); color: var(--text); }
.breadcrumbs .crumb.current { color: var(--accent); font-weight: 600; }
.breadcrumbs .sep { color: var(--text-faint); }

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

.primary-btn, .secondary-btn, .danger-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  border: none;
  transition: background 0.2s, border-color 0.2s;
}

.primary-btn { background: var(--accent); color: #052e16; }
.primary-btn:hover { background: #4ade80; }

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.secondary-btn:hover { background: var(--surface-2); border-color: var(--text-faint); }

.danger-btn { background: var(--danger-soft); color: var(--danger); }
.danger-btn:hover { background: rgba(248, 113, 113, 0.22); }

.primary-btn svg, .secondary-btn svg, .danger-btn svg { width: 15px; height: 15px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

/* ═══ TOOLBAR ═══ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
}

.toolbar-search { position: relative; width: 300px; }

.toolbar-search svg {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--text-faint);
  pointer-events: none;
}

.toolbar-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.2s;
}

.toolbar-search input:focus { outline: none; border-color: var(--accent); }
.toolbar-search input::placeholder { color: var(--text-faint); }

.selection-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ═══ TABLE ═══ */
.table-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
  padding: 0 24px 24px;
  min-height: 0;
}

.file-table { width: 100%; border-collapse: collapse; }

.file-table th {
  position: sticky;
  top: 0;
  background: var(--bg);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  z-index: 2;
}

.file-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.file-table tbody tr { transition: background 0.12s; }
.file-table tbody tr:hover { background: var(--surface); }
.file-table tbody tr.selected { background: var(--accent-soft); }

.col-check { width: 36px; }
.col-size { width: 110px; }
.col-class { width: 130px; }
.col-date { width: 170px; }
.col-actions { width: 150px; }

.file-table input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.name-cell svg { width: 17px; height: 17px; flex-shrink: 0; }
.name-cell .icon-folder { color: var(--amber); }
.name-cell .icon-file { color: var(--text-faint); }
.name-cell .icon-img { color: var(--blue); }
.name-cell .icon-archive { color: #c084fc; }

.name-cell .obj-name {
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr.row-folder .obj-name { color: var(--text); cursor: pointer; }
tr.row-folder .obj-name:hover { color: var(--accent); text-decoration: underline; }

.cell-dim { color: var(--text-dim); font-size: 12.5px; font-family: var(--font-mono); }

.storage-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  background: var(--surface-2);
  color: var(--text-dim);
}

.storage-badge.glacier { background: rgba(96, 165, 250, 0.15); color: var(--blue); }

.row-actions {
  display: flex;
  gap: 2px;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 0.15s;
}

.file-table tbody tr:hover .row-actions,
.file-table tbody tr.selected .row-actions { opacity: 1; }

.row-actions .icon-btn { width: 28px; height: 28px; }
.row-actions .icon-btn svg { width: 14px; height: 14px; }
.row-actions .icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.list-status {
  padding: 18px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.list-status button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  transition: background 0.15s;
}

.list-status button:hover { background: var(--surface-2); color: var(--text); }

/* ═══ DRAG & DROP ═══ */
.drop-overlay {
  position: absolute;
  inset: 8px 16px;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--accent);
  z-index: 5;
  pointer-events: none;
}

.drop-overlay svg { width: 48px; height: 48px; }
.drop-overlay p { color: var(--text-dim); font-size: 15px; }
.drop-overlay strong { color: var(--accent); font-family: var(--font-mono); }

/* ═══ MODALS ═══ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 17, 0.7);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 50;
}

.modal {
  width: min(460px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 24px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.modal-wide { width: min(880px, 94vw); }

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

.modal-header h3 {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal h3.modal-title { font-size: 16px; margin-bottom: 6px; }
.modal p.modal-desc { color: var(--text-dim); font-size: 13px; margin-bottom: 18px; line-height: 1.55; }
.modal p.modal-desc code {
  font-family: var(--font-mono);
  color: var(--amber);
  font-size: 12px;
  word-break: break-all;
}

.modal input[type="text"], .modal select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font-mono);
  margin-bottom: 16px;
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions .plain-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  transition: background 0.15s;
}

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

.share-url-row { display: flex; gap: 8px; margin-bottom: 4px; }
.share-url-row input { flex: 1; margin-bottom: 0; font-size: 11.5px; }

.preview-body {
  overflow: auto;
  min-height: 120px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.preview-body img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 8px;
}

.preview-body pre {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 16px;
  overflow: auto;
  max-height: 68vh;
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-body .preview-note { color: var(--text-faint); padding: 30px; }

/* ═══ UPLOAD PANEL ═══ */
.upload-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 40;
  overflow: hidden;
}

.upload-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
  font-weight: 600;
}

#upload-items { max-height: 260px; overflow-y: auto; padding: 8px 16px 12px; }

.upload-item { padding: 7px 0; }

.upload-item .u-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  margin-bottom: 5px;
}

.upload-item .u-name {
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}

.upload-item .u-pct { color: var(--text-faint); font-family: var(--font-mono); flex-shrink: 0; }
.upload-item.done .u-pct { color: var(--accent); }
.upload-item.error .u-pct { color: var(--danger); }

.u-bar {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}

.u-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.upload-item.error .u-bar-fill { background: var(--danger); }

/* ═══ TOASTS ═══ */
.toasts {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 60;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
  max-width: 480px;
}

.toast.success { border-color: var(--accent-dim); }
.toast.error { border-color: var(--danger); }

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

.spinner {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 8px;
}

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

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 40vh; }
  .col-class, .col-date { display: none; }
  .toolbar-search { width: 100%; }
}
