:root {
  --bg: #e8eef4;
  --bg-accent: #d5e2ec;
  --surface: #ffffff;
  --ink: #142033;
  --muted: #5a6b7d;
  --line: #d0dae4;
  --brand: #0b5f7a;
  --brand-2: #0a4a5f;
  --brand-soft: #e3f1f6;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --ok: #067647;
  --shadow: 0 10px 30px rgba(20, 32, 51, 0.08);
  --radius: 14px;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #c9dde8 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #d9e7c8 0%, transparent 45%),
    linear-gradient(180deg, var(--bg), var(--bg-accent));
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-body { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.brand-text {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip, .meta-chip {
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--brand-soft);
  border: 1px solid #c5dde6;
  padding: 6px 10px;
  border-radius: 999px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar {
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.breadcrumb {
  color: var(--muted);
  font-size: 0.95rem;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.bc-sep { opacity: 0.5; }

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.search-input, .select, .field input, input[type="file"], input[type="email"], input[type="password"], input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.search-input { min-width: 180px; flex: 1; }

.select { background: #fff; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-2); color: #fff; }

.btn-secondary {
  background: var(--brand-soft);
  color: var(--brand-2);
  border-color: #c5dde6;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn-ghost.is-active {
  background: var(--brand-soft);
  border-color: #b7d4df;
  color: var(--brand-2);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f3c4bf;
}

.btn-sm { padding: 6px 10px; font-size: 0.85rem; }
.btn-block { width: 100%; }

.view-toggle { display: inline-flex; gap: 4px; }

.drop-zone {
  position: relative;
  min-height: 280px;
  overflow: hidden;
}

.drop-zone.is-dragover {
  outline: 2px dashed var(--brand);
  outline-offset: -8px;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 95, 122, 0.12);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--brand-2);
  z-index: 5;
  pointer-events: none;
}

.file-list {
  display: flex;
  flex-direction: column;
}

.file-list[data-view="grid"] {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px;
}

.file-item {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  cursor: default;
  user-select: none;
}

.file-item:last-child { border-bottom: none; }
.file-item:hover { background: #f7fafc; }
.file-item.is-hidden { display: none; }
.file-item.is-selected { background: var(--brand-soft); }
.file-item.is-dragging { opacity: 0.45; }
.file-item.is-cut { opacity: 0.55; outline: 1px dashed var(--muted); }
.file-item.is-drop-hover,
.drop-target.is-drop-hover {
  background: #d7eef5 !important;
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.breadcrumb .drop-target {
  padding: 2px 6px;
  border-radius: 6px;
}
.breadcrumb .drop-target.is-drop-hover {
  background: var(--brand-soft);
}

.file-list[data-view="grid"] .file-item {
  grid-template-columns: 1fr;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: center;
  padding: 16px 12px;
  position: relative;
}

.file-list[data-view="grid"] .check-wrap {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
}

.file-list[data-view="grid"] .file-actions {
  justify-content: center;
  flex-wrap: wrap;
}

.file-list[data-view="grid"] .file-icon { font-size: 2rem; margin: 0 auto; }

.check-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
  position: relative;
  z-index: 2;
  cursor: pointer;
}

.check-wrap .item-check {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.file-icon { font-size: 1.4rem; width: 28px; text-align: center; }

.file-name { font-weight: 600; word-break: break-word; }

.item-open-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: inherit;
  cursor: pointer;
  text-align: inherit;
  max-width: 100%;
  word-break: break-word;
}
.item-open-btn:hover { color: var(--brand); text-decoration: underline; }

.file-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.file-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.drop-zone.is-internal-drag .drop-overlay { display: none !important; }

.field-hint {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: var(--muted);
}

.ctx-menu {
  position: fixed;
  z-index: 90;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ctx-menu[hidden] { display: none !important; }

.ctx-item {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
}
.ctx-item:hover:not(:disabled) { background: var(--brand-soft); }
.ctx-item:disabled { opacity: 0.45; cursor: default; }
.ctx-item.is-danger { color: var(--danger); }
.ctx-sep {
  height: 1px;
  background: var(--line);
  margin: 4px 2px;
}

.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--muted);
}

.empty-state h3 { color: var(--ink); margin: 0 0 8px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.bulk-bar {
  position: sticky;
  bottom: 16px;
  margin-top: 16px;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.bulk-bar .btn-ghost { color: #fff; border-color: rgba(255,255,255,0.25); }

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
}

.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 480px;
  width: calc(100% - 32px);
}

.modal::backdrop { background: rgba(20, 32, 51, 0.45); }

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head, .modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  border-bottom: none;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span { font-weight: 600; font-size: 0.9rem; }

.upload-progress { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  font-size: 0.85rem;
}

.progress-track {
  grid-column: 1 / -1;
  height: 8px;
  background: #e8eef4;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--brand);
  transition: width 0.15s linear;
}

/* Auth */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .brand-mark { margin: 0 auto 12px; width: 48px; height: 48px; font-size: 15px; }
.auth-brand h1 { margin: 0 0 6px; font-size: 1.5rem; }
.auth-brand p { margin: 0; color: var(--muted); }

.auth-hint {
  margin: 16px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.alert {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 0.92rem;
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f3c4bf;
}

/* Viewer */
.viewer-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
  min-height: calc(100vh - 80px);
  display: grid;
  place-items: center;
}

.viewer-media {
  max-width: 100%;
  max-height: calc(100vh - 140px);
  border-radius: 12px;
  box-shadow: var(--shadow);
  background: #000;
}

.viewer-frame {
  width: 100%;
  height: calc(100vh - 140px);
  border: 0;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.viewer-text {
  width: 100%;
  max-height: calc(100vh - 140px);
  overflow: auto;
  background: #0f1720;
  color: #e8eef4;
  padding: 20px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.viewer-audio {
  background: var(--surface);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Activity table */
.table-wrap { overflow: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.data-table th {
  background: #f7fafc;
  color: var(--muted);
  font-weight: 600;
}
.path-cell { word-break: break-all; color: var(--muted); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-2);
  font-size: 0.8rem;
  font-weight: 600;
}

@media (max-width: 720px) {
  .file-item {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "check icon"
      "check info"
      "actions actions";
  }
  .check-wrap { grid-area: check; align-self: start; }
  .file-icon { grid-area: icon; }
  .file-info { grid-area: info; }
  .file-actions { grid-area: actions; justify-content: flex-start; }
  .user-chip { display: none; }
  .brand-text { font-size: 0.95rem; }
}
