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

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-subtle: #fff7ed;
  --accent-subtle-border: #fed7aa;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
  --z-sticky: 10;
  --z-overlay: 100;
  --z-dropdown: 200;
  --z-modal: 300;
  --z-toast: 500;
  --page-px: 14px;
  --btn-px: 10px;
  --content-max-w: 960px;
  --editor-max-w: 740px;
  --transition: 0.1s;
}

@media (min-width: 769px) {
  :root {
    --page-px: 22px;
  }
}

@media (min-width: 1025px) {
  :root {
    --btn-px: 14px;
  }
}

@media (min-width: 1280px) {
  :root {
    --page-px: 32px;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Login ── */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 0 var(--page-px);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s;
}

.login-card input[type="password"]:focus {
  border-color: var(--accent);
}

#login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 10px;
  display: none;
}

/* ── Buttons ── */
.btn-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px var(--btn-px);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition:
    background var(--transition),
    opacity var(--transition);
  white-space: nowrap;
}

@media (min-width: 1025px) {
  .btn {
    padding: 8px var(--btn-px);
  }
}

.btn-lg {
  padding: 8px 14px;
  font-size: 14px;
}

@media (min-width: 1025px) {
  .btn-lg {
    padding: 10px 16px;
  }
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:not(:disabled):hover {
  background: var(--bg);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:not(:disabled):hover {
  background: var(--danger-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:not(:disabled):hover {
  background: var(--bg);
  color: var(--text);
}
.btn-ghost.active,
.btn-ghost.active:hover {
  background: var(--accent-subtle);
  color: var(--accent);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Layout ── */
#app-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px var(--page-px);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

@media (min-width: 1025px) {
  .topbar {
    padding-top: 13px;
    padding-bottom: 13px;
  }
}

#logout-btn {
  margin-right: calc(-1 * var(--btn-px));
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}

.topbar-logo {
  display: block;
}

/* ── Breadcrumbs ── */
.breadcrumb-row {
  display: flex;
  align-items: center;
  background: var(--surface);
  padding-right: var(--page-px);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px var(--page-px) 5px;
  font-size: 14px;
  line-height: 1.4;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.breadcrumb-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  font-family: monospace;
  color: var(--text);
  padding: 0;
  min-width: 0;
  width: 100%;
  height: 1.4em;
  line-height: 1.4;
}

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

.breadcrumb a:hover {
  text-decoration: underline;
}
.breadcrumb span.sep,
.breadcrumb span.current {
  color: var(--text-muted);
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px var(--page-px) 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar .btn-label {
  display: none;
}

@media (min-width: 1025px) {
  .toolbar .btn-label {
    display: inline;
  }
}

.toolbar-right {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.toolbar-end {
  width: 100%;
  display: flex;
  align-items: center;
}

@media (min-width: 480px) {
  .toolbar-end {
    width: auto;
    flex-grow: 1;
    justify-content: space-between;
  }
}

.view-toggle {
  display: flex;
  gap: 4px;
  margin: -5px calc(-1 * var(--btn-px)) -5px auto;
}

@media (min-width: 480px) {
  .view-toggle {
    margin: 0 0 0 auto;
  }
}

#selection-info {
  min-width: 78px;
}

#delete-btn {
  margin-right: 8px;
}

.toolbar-sep {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  margin: 0 4px;
}

/* ── New dropdown ── */
.new-dropdown-wrap {
  position: relative;
}

.new-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  z-index: var(--z-dropdown);
  padding: 4px 0;
}

.new-dropdown.open {
  display: block;
}

.new-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
}

.new-dropdown-item:hover {
  background: var(--accent-subtle);
  color: var(--accent);
}

.new-dropdown-item .btn-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

.new-dropdown-item:hover .btn-icon {
  color: var(--accent);
}

/* ── File list ── */
.files-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px var(--page-px);
}

/* List view */
.file-list {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  max-width: var(--content-max-w);
  margin: 0 auto;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  position: relative;
  user-select: none;
  -webkit-touch-callout: none;
  background: var(--surface);
  transition: background var(--transition);
}

@media (min-width: 1025px) {
  .file-item {
    gap: 12px;
  }
}

.file-item:last-child {
  border-bottom: none;
}

.file-item:hover {
  background: #eaeaea;
}
.file-item.selected {
  background: var(--accent-subtle);
}
.file-item.selected::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
}

.file-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 26px;
  text-align: center;
}
.file-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 1025px) {
  .file-name {
    font-size: 14px;
  }
}

.file-meta {
  display: flex;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
  margin-left: 8px;
}

@media (min-width: 1025px) {
  .file-meta {
    font-size: 13px;
    gap: 20px;
    margin-left: 12px;
  }
}

/* Grid view */
.file-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: var(--content-max-w);
  margin: 0 auto;
}

@media (min-width: 480px) {
  .file-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 769px) {
  .file-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1025px) {
  .file-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.file-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-align: center;
  user-select: none;
  -webkit-touch-callout: none;
  transition: background var(--transition);
}

.file-card:hover {
  background: #ececec;
}
.file-card.selected {
  background: var(--accent-subtle);
  border-color: var(--accent-subtle-border);
}
.file-card-media {
  width: 100%;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.file-card .file-icon {
  font-size: 70px;
  width: auto;
}
.file-card .file-thumb {
  max-width: 100%;
  max-height: 120px;
  width: auto;
  height: auto;
  border-radius: 4px;
}
.file-card .file-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

/* ── Upload zone ── */
.drop-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(234, 88, 12, 0.08);
  border: 3px dashed var(--accent);
  z-index: var(--z-overlay);
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

/* ── Drag to move ── */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-toast);
  pointer-events: none;
  max-width: 240px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.95;
}

body.dragging {
  cursor: grabbing;
  user-select: none;
}

/* Item picked up by a touch long-press, before movement. */
.file-item.drag-armed,
.file-card.drag-armed {
  opacity: 0.6;
}

/* Folder / breadcrumb currently under the dragged item. */
.file-item.drop-target,
.file-card.drop-target {
  background: var(--accent-subtle);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
#breadcrumb a.drop-target {
  background: var(--accent-subtle);
  outline: 2px solid var(--accent);
  border-radius: var(--radius-sm);
}

/* ── Upload progress ── */
.upload-progress {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 14px 16px;
  min-width: 260px;
  z-index: var(--z-dropdown);
  display: none;
}

.upload-progress.active {
  display: block;
}
.upload-progress-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
}
.progress-bar-bg {
  background: var(--bg);
  border-radius: 3px;
  height: 6px;
  overflow: hidden;
}
.progress-bar-fill {
  background: var(--accent);
  height: 100%;
  width: 0%;
  transition: width 0.2s;
  border-radius: 3px;
}
.progress-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  margin: 20px;
}

.modal h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}
.modal input,
.modal select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
  outline: none;
}
.modal input:focus,
.modal select:focus {
  border-color: var(--accent);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-message {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

/* ── Editor ── */
#editor-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.view-topbar {
  padding: 10px var(--page-px);
  display: flex;
  align-items: center;
  gap: 6px;
}

@media (min-width: 769px) {
  .view-topbar {
    gap: 10px;
  }
}

.editor-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#editor-back-btn {
  margin-left: calc(-1 * var(--btn-px));
}

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

.editor-status {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

@media (min-width: 769px) {
  .editor-status {
    margin-right: 8px;
  }
}

.editor-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Plain text editor */
#text-editor {
  width: 100%;
  max-width: var(--editor-max-w);
  align-self: center;
  flex: 1;
  border: none;
  outline: none;
  padding: 20px var(--page-px);
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: none;
  background: var(--surface);
}

/* Markdown editor (Toast UI) */
#md-editor-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--editor-max-w);
  margin: 0 auto;
}
#md-editor-wrap .toastui-editor-defaultUI {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: none;
}
#md-editor-wrap .toastui-editor-main {
  flex: 1;
}
.toastui-editor-toolbar {
  height: auto !important;
  background-color: var(--surface) !important;
}
.toastui-editor-defaultUI-toolbar {
  padding: 0 var(--page-px) !important;
  background-color: var(--surface) !important;
  border-bottom: 1px solid var(--border) !important;
  border-radius: 0 !important;
  height: auto !important;
}
.toastui-editor-toolbar-group {
  margin-left: -8px !important;
}
.toastui-editor-ww-container .toastui-editor-contents {
  padding: 12px var(--page-px) 0 !important;
}

@media (min-width: 769px) {
  .toastui-editor-ww-container .toastui-editor-contents {
    padding-top: 14px !important;
  }
}

@media (min-width: 1025px) {
  .toastui-editor-ww-container .toastui-editor-contents {
    font-size: 14px !important;
  }
}

@media (min-width: 1280px) {
  .toastui-editor-ww-container .toastui-editor-contents {
    padding-top: 20px !important;
  }
}
.toastui-editor-defaultUI-toolbar button {
  border-color: var(--surface) !important;
  margin: 7px 2px !important;
}
.toastui-editor-defaultUI-toolbar button:hover {
  background-color: var(--bg) !important;
  border-color: var(--border) !important;
}
.toastui-editor-toolbar-divider {
  background-color: var(--border) !important;
}

/* "More" overflow button: replace bleeding sprite icon with a clean SVG */
.toastui-editor-toolbar-icons.more {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23585858'%3E%3Ccircle cx='5' cy='12' r='2'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3Ccircle cx='19' cy='12' r='2'/%3E%3C/g%3E%3C/svg%3E")
    center / 18px 18px no-repeat !important;
  margin-left: 8px !important;
}

/* "More" popover: theme it and stop the global group offset from clipping it */
.toastui-editor-dropdown-toolbar {
  background-color: var(--surface) !important;
  border-color: var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
  height: auto !important;
  padding: 0 4px !important;
}
.toastui-editor-dropdown-toolbar .toastui-editor-toolbar-group {
  margin-left: 0 !important;
}
/* Color picker popup */
.toastui-editor-popup {
  margin-left: -40px !important;
}

@media (min-width: 480px) {
  .toastui-editor-popup {
    margin-left: 0 !important;
  }
}

.tui-colorpicker-container,
.tui-colorpicker-palette-container {
  width: 190px !important;
}
.tui-colorpicker-palette-toggle-slider {
  float: none !important;
}
.tui-colorpicker-slider-container {
  width: 152px !important;
}
.tui-colorpicker-palette-preview {
  display: none !important;
}
.tui-colorpicker-clearfix {
  width: auto !important;
  overflow: visible !important;
}
.tui-colorpicker-palette-hex {
  width: 136px !important;
  height: 32px !important;
}
.toastui-editor-popup-color button {
  top: 49px !important;
  right: 15px !important;
}

/* ── Media preview ── */
#preview-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #111;
}

.preview-content-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.preview-topbar {
  background: #1a1a1a;
}

#preview-back-btn {
  margin-left: calc(-1 * var(--btn-px));
}

.preview-topbar .file-name {
  color: #eee;
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-topbar .btn-ghost {
  color: #bbb;
}
.preview-topbar .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
#preview-download-btn:hover {
  background: #e8e8e8;
  border-color: #ccc;
}
.preview-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(60, 60, 60, 0.75);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 12px 10px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--transition),
    opacity var(--transition);
}

@media (min-width: 1025px) {
  .preview-nav-btn {
    padding: 20px 14px;
  }
}

.preview-nav-btn svg {
  width: 24px;
  height: 24px;
  display: block;
}

@media (min-width: 1025px) {
  .preview-nav-btn svg {
    width: 28px;
    height: 28px;
  }
}

.preview-nav-btn:not(:disabled):hover {
  background: rgba(60, 60, 60, 0.95);
}
.preview-nav-btn:disabled {
  opacity: 0;
  pointer-events: none;
}
#preview-prev-btn {
  left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding-left: 8px;
  padding-right: 10px;
}

@media (min-width: 1025px) {
  #preview-prev-btn {
    padding-left: 10px;
    padding-right: 14px;
  }
}

#preview-next-btn {
  right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  padding-right: 8px;
  padding-left: 10px;
}

@media (min-width: 1025px) {
  #preview-next-btn {
    padding-right: 10px;
    padding-left: 14px;
  }
}

.preview-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 20px;
}

.preview-body img,
.preview-body video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
}

.preview-body img {
  object-fit: contain;
}

.preview-body:has(iframe) {
  padding: 0;
  align-items: stretch;
}

.preview-body iframe {
  flex: 1;
  border: none;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  transition:
    opacity 0.2s,
    transform 0.2s;
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error {
  background: var(--danger);
}

/* ── Utilities ── */
.hidden {
  display: none !important;
}
.text-muted {
  color: var(--text-muted);
}
.flex {
  display: flex;
}
.gap-2 {
  gap: 8px;
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.empty-state p {
  font-size: 14px;
}
