* { box-sizing: border-box; }
body {
  font-family: -apple-system, Segoe UI, Roboto, sans-serif;
  background: #f4f5f7;
  color: #1a1a1a;
  margin: 0;
}

.auth-box {
  max-width: 360px;
  margin: 10vh auto;
  background: #fff;
  padding: 32px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.auth-box h1 { margin-top: 0; font-size: 1.4rem; }

.auth-box form { display: flex; flex-direction: column; gap: 14px; }
.auth-box label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.auth-box input {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}
.auth-box button, .container button {
  padding: 8px 14px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
}
.auth-box button:hover, .container button:hover { background: #1d4ed8; }
.error { color: #dc2626; font-size: 0.9rem; }

.container {
  max-width: 800px;
  margin: 40px auto;
  background: #fff;
  padding: 24px 32px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.area-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.area-switch a {
  padding: 6px 12px;
  border-radius: 999px;
  background: #f4f5f7;
  color: #444;
  text-decoration: none;
  font-size: 0.85rem;
}
.area-switch a:hover { background: #e5e7eb; }
.area-switch a.active {
  background: #2563eb;
  color: #fff;
}

.breadcrumbs {
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: #444;
}
.breadcrumbs a { color: #2563eb; text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs .sep { margin: 0 6px; color: #999; }
.breadcrumbs .current { font-weight: 600; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.upload-form {
  display: flex;
  gap: 10px;
}

#newFolderBtn {
  padding: 8px 14px;
  background: #10b981;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}
#newFolderBtn:hover { background: #059669; }

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.progress-wrap[hidden] { display: none; }

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font-size: 0.85rem;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar button {
  padding: 5px 12px;
  border: none;
  border-radius: 4px;
  background: #e5e7eb;
  cursor: pointer;
  font-size: 0.85rem;
}
.bulk-bar button:hover { background: #d1d5db; }
.bulk-bar button.danger { background: #dc2626; color: #fff; }
.bulk-bar button.danger:hover { background: #b91c1c; }
#bulkCount { margin-right: auto; font-weight: 600; color: #1d4ed8; }

.select-cell { width: 32px; text-align: center; }

.progress-track {
  flex: 1;
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: #2563eb;
  transition: width 0.15s ease;
}

#progressText {
  font-size: 0.85rem;
  color: #444;
  min-width: 60px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #eee; font-size: 0.9rem; }
.name-cell { max-width: 320px; word-break: break-word; }
.entry-link { color: #1a1a1a; text-decoration: none; }
.entry-link:hover { color: #2563eb; text-decoration: underline; }
.actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.actions a, .actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  color: #1a1a1a;
  text-decoration: none;
  font-size: 1rem;
}
.actions a { background: #e5e7eb; border-radius: 4px; }
.actions a:hover { background: #d1d5db; }
.actions form { margin: 0; }
.actions button {
  padding: 4px 8px;
  background: #e5e7eb;
}
.actions button:hover { background: #d1d5db; }
button.danger { background: #dc2626 !important; color: #fff !important; }
button.danger:hover { background: #b91c1c !important; }
.empty { color: #666; }

.table-scroll { overflow-x: auto; }

/* Icon buttons throughout the app need a comfortable tap target and no
   text-button padding assumptions now that labels are gone. */
.logout-form button,
#newFolderBtn,
.bulk-bar button,
.close-btn {
  min-width: 34px;
  min-height: 34px;
}

.select-cell input[type="checkbox"],
.row-check {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* --- Modals --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: 8px;
  max-width: 90vw;
  width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.small-modal { width: 360px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #eee;
  font-weight: 600;
}
.close-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 0 4px;
}
.close-btn:hover { color: #1a1a1a; }
.modal-body {
  padding: 18px;
  overflow: auto;
}

.preview-modal .modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}
.preview-modal img,
.preview-modal video {
  max-width: 100%;
  max-height: 70vh;
}
.preview-modal audio { width: 100%; }
.preview-modal iframe {
  width: 100%;
  height: 65vh;
  border: none;
}
.preview-counter { font-size: 0.8rem; color: #666; }
.preview-loading { padding: 18px; color: #666; }

/* Fullscreen image slideshow */
.modal-overlay.fullscreen { background: #000; }
.modal-overlay.fullscreen .modal {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  background: #000;
}
.modal-overlay.fullscreen .modal-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border-bottom: none;
  z-index: 2;
}
.modal-overlay.fullscreen .close-btn { color: #fff; }
.modal-overlay.fullscreen .preview-counter { color: #ddd; }
.modal-overlay.fullscreen .preview-modal .modal-body { min-height: 100vh; }
.modal-overlay.fullscreen .preview-modal img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}
.preview-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-nav:hover { background: rgba(255, 255, 255, 0.3); }
.preview-nav.prev { left: 16px; }
.preview-nav.next { right: 16px; }
.preview-nav[hidden] { display: none; }

/* Scrollable text preview */
.modal-overlay.text-mode .modal {
  width: 800px;
  max-width: 95vw;
  height: 80vh;
  max-height: 80vh;
}
.modal-overlay.text-mode .preview-modal .modal-body {
  display: block;
  min-height: 0;
  height: 100%;
  padding: 0;
  overflow: auto;
}
.text-preview {
  margin: 0;
  padding: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
}

.folder-form { display: flex; gap: 10px; }
#newFolderName {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}
#createFolderConfirm {
  flex-shrink: 0;
  padding: 8px 14px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.1rem;
}
#createFolderConfirm:hover { background: #1d4ed8; }

.folder-tree {
  max-height: 40vh;
  overflow: auto;
  border: 1px solid #eee;
  border-radius: 4px;
  margin-bottom: 14px;
}
.tree-row {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}
.tree-row:hover { background: #f4f5f7; }
.tree-row.selected { background: #dbeafe; font-weight: 600; }

.picker-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}
#pickerConfirm {
  padding: 8px 16px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
#pickerConfirm:hover { background: #1d4ed8; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
}
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  border-radius: 4px;
  background: #e5e7eb;
  text-decoration: none;
  color: #1a1a1a;
  font-size: 1rem;
}
a.page-btn:hover { background: #d1d5db; }
.page-btn.disabled { opacity: 0.4; cursor: default; }
.page-info { font-size: 0.85rem; color: #444; }
.page-size {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #444;
}
.page-size select {
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background: #fff;
  font-size: 0.85rem;
}

/* --- Music player --- */
.music-player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #1a1a1a;
  color: #fff;
  padding: 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 900;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}
.music-player[hidden] { display: none; }
.mp-info {
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mp-seek { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; color: #ccc; }
.mp-seek input[type="range"] { flex: 1; }
.mp-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mp-controls button {
  background: #333;
  border: none;
  color: #fff;
  min-width: 34px;
  min-height: 34px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}
.mp-controls button:hover { background: #444; }
.mp-controls button.active { background: #2563eb; }
.mp-controls select {
  background: #333;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  min-height: 34px;
}
.mp-controls input[type="range"] { width: 90px; }
body.has-player .container { padding-bottom: 150px; }

/* --- Video player --- */
.video-player {
  background: #1a1a1a;
  color: #fff;
  padding: 14px 16px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.video-player[hidden] { display: none; }
.video-player video {
  width: 100%;
  max-height: 60vh;
  background: #000;
  border-radius: 6px;
}

/* --- Mobile --- */
@media (max-width: 640px) {
  .container {
    margin: 0;
    padding: 16px;
    border-radius: 0;
    max-width: 100%;
    min-height: 100vh;
  }

  header { flex-wrap: wrap; gap: 8px; }
  header h1 { font-size: 1.2rem; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .upload-form { flex-direction: column; align-items: stretch; }
  .upload-form input[type="file"] { max-width: 100%; }
  #newFolderBtn { align-self: flex-start; }

  .bulk-bar { flex-wrap: wrap; }
  #bulkCount { flex-basis: 100%; margin-right: 0; }

  .col-updated { display: none; }

  th, td { padding: 8px 4px; font-size: 0.85rem; }
  .name-cell { max-width: 55vw; }

  .picker-footer { flex-direction: column; align-items: stretch; gap: 10px; }
  #pickerConfirm { width: 100%; }

  .modal { width: 100%; max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; }
  .small-modal { width: 100%; }

  .music-player { padding: 8px 12px; }
  .mp-controls { justify-content: center; }
  body.has-player .container { padding-bottom: 190px; }

  .preview-nav { width: 38px; height: 38px; font-size: 1.4rem; }
  .preview-nav.prev { left: 6px; }
  .preview-nav.next { right: 6px; }
  .modal-overlay.text-mode .modal { width: 100%; height: 100%; max-height: 100%; }
}

/* Text editor */
.editor-modal {
  width: 900px;
  max-width: 95vw;
  height: 85vh;
  max-height: 85vh;
}
.editor-modal .modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
}
.editor-text {
  flex: 1;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-family: Consolas, Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
.editor-text:disabled { background: #f4f5f7; }
.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.editor-status { font-size: 0.85rem; color: #666; }
#editorSaveBtn {
  flex-shrink: 0;
  padding: 8px 16px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.1rem;
}
#editorSaveBtn:hover { background: #1d4ed8; }
#editorSaveBtn:disabled { opacity: 0.6; cursor: default; }

.preview-actions {
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px 0;
}
.preview-actions button {
  padding: 6px 12px;
  background: #f8f9fa;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}
.preview-actions button:hover { background: #eceef1; }
