:root {
  --bg: #14171c;
  --panel: #1b1f26;
  --panel-alt: #20242c;
  --border: #2a2f38;
  --text: #e6e8eb;
  --text-muted: #8b93a1;
  --accent: #e0a458;
  --accent-soft: rgba(224, 164, 88, 0.14);
  --danger: #d9534f;
  --danger-soft: rgba(217, 83, 79, 0.14);
  --radius: 6px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* The "hidden" attribute must always win over component display rules
   below (e.g. ".modal-backdrop { display: flex }"), otherwise dialogs like
   the delete-confirmation modal stay visible even while hidden is set. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-mark {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}
.login-mark .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border);
}
.login-mark .dot-1 { background: var(--accent); }

.login-card h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.login-sub {
  margin: 0 0 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-card input {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 10px;
  color: var(--text);
}

.login-card button {
  margin-top: 6px;
  background: var(--accent);
  color: #1a1305;
  border: none;
  border-radius: var(--radius);
  padding: 10px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.05); }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
}

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}

.brand {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}
.brand-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.quick-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.quick-link, .pin-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  text-align: left;
  color: var(--text-muted);
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  width: 100%;
}
.quick-link:hover, .pin-item:hover {
  background: var(--panel-alt);
  color: var(--text);
}
.ql-icon { opacity: .8; }

.pins-header {
  margin-top: 18px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 0 8px 6px;
}

.pins { flex: 0 1 auto; overflow-y: auto; }

.pin-item {
  justify-content: space-between;
}
.pin-remove {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 12px; padding: 2px 4px;
}
.pin-remove:hover { color: var(--danger); }

.pin-add {
  margin-top: 8px;
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 7px 8px;
  font-size: 12px;
  cursor: pointer;
}
.pin-add:hover { color: var(--text); border-color: var(--text-muted); }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.usage-label {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 6px;
}
.usage-bar {
  height: 5px;
  background: var(--panel-alt);
  border-radius: 3px;
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  padding: 0;
  font-size: 12px;
  text-decoration: underline;
}
.link-btn:hover { color: var(--text); }

/* ---------- Main ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.breadcrumb {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
}
.breadcrumb button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.breadcrumb button:hover { background: var(--panel-alt); color: var(--text); }
.breadcrumb button.current { color: var(--text); font-weight: 600; }
.breadcrumb .sep { color: var(--border); }

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1305;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: #ffd9d7;
}
.icon-btn { padding: 8px 10px; }
.file-input-label { display: inline-flex; align-items: center; cursor: pointer; }

.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.selection-actions { display: flex; gap: 14px; align-items: center; }

.file-table-wrap {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.file-table {
  width: 100%;
  border-collapse: collapse;
}
.file-table th {
  position: sticky;
  top: 0;
  background: var(--bg);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.col-check { width: 36px; }
.col-size { width: 100px; text-align: right; font-family: var(--font-mono); }
.col-date { width: 170px; font-family: var(--font-mono); }
.col-actions { width: 140px; }

.file-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.file-table tbody tr:hover { background: var(--panel-alt); }
.file-table tbody tr.selected {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-width: 0;
}
.file-name-cell .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-icon {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
  color: var(--text-muted);
}
.file-table td.col-size, .file-table td.col-date {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 12.5px;
}
.col-size { text-align: right; }

.row-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
}
tr:hover .row-actions, tr:focus-within .row-actions { opacity: 1; }
.row-actions button {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 7px;
  border-radius: 4px;
  font-size: 12px;
}
.row-actions button:hover { border-color: var(--border); color: var(--text); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
}

.drop-overlay {
  position: absolute;
  inset: 8px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(224, 164, 88, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-weight: 600;
  pointer-events: none;
}

.status-bar {
  padding: 8px 22px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ---------- Modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 15, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card h2 { margin: 0; font-size: 16px; }
.modal-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.modal-card input {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

/* ---------- Editor panel ---------- */

.editor-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(720px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  box-shadow: -8px 0 24px rgba(0,0,0,0.35);
}
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 13px;
}
.editor-actions { display: flex; gap: 8px; }
.editor-body {
  flex: 1;
  overflow: auto;
  padding: 0;
  display: flex;
}
#editor-textarea {
  flex: 1;
  border: none;
  resize: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 18px;
  line-height: 1.5;
}
#editor-image { max-width: 100%; margin: auto; }
#editor-frame { flex: 1; border: none; background: white; }
#editor-fallback { margin: auto; color: var(--text-muted); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 60;
}
.toast.error { border-color: var(--danger); color: #ffd9d7; }

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .col-date { display: none; }
  .editor-panel { width: 100vw; }
}
