:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --accent: #2f6feb;
  --accent-hover: #2559c4;
  --danger: #d93025;
  --danger-hover: #b8271d;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2226;
    --border: #2c2f36;
    --text: #eaecef;
    --text-muted: #9aa0aa;
    --accent: #5b8def;
    --accent-hover: #7aa2f5;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

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

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

.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
}

.login-sub {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 14px;
  background: var(--bg);
  color: var(--text);
}

.login-card button {
  width: 100%;
  padding: 11px 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.login-card button:hover { background: var(--accent-hover); }

.login-error {
  background: rgba(217,48,37,0.1);
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  margin-bottom: 14px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 600; font-size: 1.05rem; }

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

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  flex-wrap: wrap;
}

.breadcrumb {
  font-size: 0.9rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.breadcrumb a { color: var(--accent); text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--text-muted); }
.breadcrumb .current { color: var(--text); font-weight: 500; }

.toolbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

#searchBox {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
  min-width: 180px;
}

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

.primary-btn, .secondary-btn, .ghost-btn, .danger-btn {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  border: 1px solid transparent;
  white-space: nowrap;
}

.primary-btn { background: var(--accent); color: #fff; }
.primary-btn:hover { background: var(--accent-hover); }

.secondary-btn { background: var(--surface); color: var(--text); border-color: var(--border); }
.secondary-btn:hover { background: var(--bg); }

.ghost-btn { background: transparent; color: var(--text); border-color: var(--border); text-decoration: none; display: inline-block; }
.ghost-btn:hover { background: var(--bg); }

.danger-btn { background: var(--danger); color: #fff; }
.danger-btn:hover { background: var(--danger-hover); }

/* ---------- File grid ---------- */

.drop-zone {
  position: relative;
  min-height: calc(100vh - 130px);
  padding: 8px 20px 40px;
}

.drop-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(47,111,235,0.12);
  border: 3px dashed var(--accent);
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--accent);
  z-index: 50;
  pointer-events: none;
}

.drop-zone.dragging .drop-overlay { display: flex; }

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.file-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  position: relative;
  user-select: none;
  transition: border-color 0.15s;
}

.file-card:hover { border-color: var(--accent); }

.file-icon {
  font-size: 2.1rem;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.file-icon img {
  max-width: 100%;
  max-height: 52px;
  border-radius: 4px;
  object-fit: cover;
}

.file-name {
  font-size: 0.82rem;
  word-break: break-word;
  line-height: 1.25;
  max-height: 2.5em;
  overflow: hidden;
}

.file-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.file-menu-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  line-height: 1;
  font-size: 1rem;
  color: var(--text-muted);
}

.file-menu-btn:hover { color: var(--text); }

.context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 60;
  min-width: 160px;
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  background: none;
  color: var(--text);
  border-radius: 6px;
  font-size: 0.86rem;
}

.context-menu button:hover { background: var(--bg); }
.context-menu button.danger { color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
  font-size: 0.95rem;
}

/* ---------- Upload queue ---------- */

.upload-queue {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.upload-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
}

.upload-item-name { display: flex; justify-content: space-between; margin-bottom: 6px; }
.upload-item-status { color: var(--text-muted); }
.upload-item-status.error { color: var(--danger); }

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

.upload-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.15s;
}

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

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal[hidden] { display: none; }

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

.modal-box-wide { max-width: 520px; }
.modal-box-preview { max-width: 720px; width: 90vw; }

.modal-box h2 { margin: 0 0 14px; font-size: 1.1rem; }

.modal-text { color: var(--text-muted); font-size: 0.9rem; }

.modal-box input[type="text"],
.modal-box input[type="number"],
.modal-box select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.modal-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.share-result {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.share-result input { margin-bottom: 0; flex: 1; }

.shares-list { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }

.share-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.82rem;
}

.share-row-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; gap: 8px; }
.share-row-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-row-meta { color: var(--text-muted); font-size: 0.78rem; }
.share-row-meta.expired { color: var(--danger); }

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 500;
}

.preview-body {
  max-height: 75vh;
  overflow: auto;
  text-align: center;
}

.preview-body img { max-width: 100%; max-height: 72vh; border-radius: 6px; }
.preview-body iframe { width: 100%; height: 70vh; border: none; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1e21;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.86rem;
  z-index: 200;
  box-shadow: var(--shadow);
}

.toast.error { background: var(--danger); }

@media (max-width: 560px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-actions { justify-content: stretch; }
  #searchBox { flex: 1; min-width: 0; }
}
