/* =========================================================================
   Lucas Workspace \u2014 interface
   Single stylesheet, no external dependencies (CSP: default-src 'none').
   ========================================================================= */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --border: #dde2ee;
  --text: #16203a;
  --muted: #6a7691;
  --accent: #2fa36b;
  --accent-hover: #268a5a;
  --danger: #d9455f;
  --danger-soft: #fdecef;
  --ok: #1f9d6b;
  --warn: #c47b16;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,26,52,.06), 0 8px 24px rgba(16,26,52,.08);
  --shadow-lg: 0 12px 48px rgba(16,26,52,.18);
  --topbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1320;
    --surface: #161d2e;
    --surface-2: #1e263a;
    --border: #2a3550;
    --text: #e8ecf7;
    --muted: #94a1bd;
    --accent: #43c98a;
    --accent-hover: #57d69b;
    --danger: #ff6b83;
    --danger-soft: #2c1a22;
    --ok: #35c98c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    --shadow-lg: 0 16px 56px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- Views -------------------------------------------------------- */
.view { min-height: 100%; }
.view.centered {
  display: grid;
  place-items: center;
  padding: 24px;
  min-height: 100dvh;
}

/* ---------- Login -------------------------------------------------------- */
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 24px;
  text-align: center;
}
.brand.small {
  flex-direction: row;
  gap: 8px;
  margin: 0;
  font-weight: 650;
  letter-spacing: -.01em;
}
.brand-icon {
  width: 40px;
  height: 40px;
  fill: var(--accent);
  stroke: none;
}
.brand.small .brand-icon { width: 26px; height: 26px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
select {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.pw-wrap { position: relative; }
.pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
  padding: 4px 6px;
}

/* ---------- Buttons ------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 15px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px; height: 38px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.avatar {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}

.error {
  margin: 0 0 14px;
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
}

/* ---------- Topbar ------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 14px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 520px;
  margin: 0 auto;
}
.search input { border-radius: 999px; padding-left: 16px; }

.storage-pill {
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- User menu ---------------------------------------------------- */
.menu {
  position: absolute;
  top: calc(var(--topbar-h) - 6px);
  right: 12px;
  min-width: 220px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
}
.menu-head {
  display: flex;
  flex-direction: column;
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.menu button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }

/* ---------- Upload progress --------------------------------------------- */
.upload-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 35;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}
.upload-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  font-size: 13px;
}
.upload-inner span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .18s ease;
}

/* ---------- Content ------------------------------------------------------ */
.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px 96px;
}

.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  list-style: none;
  margin: 8px 0 14px;
  padding: 0;
  font-size: 14px;
}
.crumbs li { display: flex; align-items: center; gap: 2px; }
.crumbs button {
  padding: 4px 8px;
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.crumbs button:hover { background: var(--surface-2); color: var(--text); }
.crumbs li:last-child button { color: var(--text); font-weight: 650; }
.crumbs .sep { color: var(--muted); opacity: .55; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }

/* ---------- File list ---------------------------------------------------- */
.dropzone {
  position: relative;
  border-radius: var(--radius);
  transition: outline-color .15s;
  outline: 2px dashed transparent;
  outline-offset: 6px;
}
.dropzone.dragover { outline-color: var(--accent); }

.file-list { display: flex; flex-direction: column; gap: 6px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: default;
  transition: border-color .12s, background .12s;
  user-select: none;
}
.row:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.row.drag-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.row.selected { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }

.thumb {
  width: 42px; height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb svg { width: 22px; height: 22px; color: var(--muted); }
.thumb.folder svg { color: var(--accent); }

.row-main { min-width: 0; flex: 1; }
.row-name {
  display: block;
  width: 100%;
  padding: 0;
  font: inherit;
  font-weight: 550;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-meta {
  display: flex;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.row-actions { display: flex; align-items: center; gap: 2px; opacity: .0; transition: opacity .12s; }
.row:hover .row-actions, .row:focus-within .row-actions, .row.selected .row-actions { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }

/* ---------- Empty state -------------------------------------------------- */
.empty {
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 64px 20px;
  text-align: center;
  color: var(--muted);
}
.empty svg { width: 44px; height: 44px; opacity: .5; }
.empty p { margin: 0; }

/* ---------- FAB ---------------------------------------------------------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 45;
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

/* ---------- Modal -------------------------------------------------------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(8,12,24,.55); backdrop-filter: blur(2px); }
.modal {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.modal-body { padding: 16px; overflow: auto; }
.modal-body p { margin: 0 0 12px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
}
.modal span.hint { display: block; margin-top: 8px; font-size: 12.5px; color: var(--muted); }

/* ---------- Context menu ------------------------------------------------- */
.context-menu {
  position: fixed;
  min-width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 90;
}
.context-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}
.context-menu button:hover { background: var(--surface-2); }
.context-menu button.danger { color: var(--danger); }
.context-menu button svg { width: 17px; height: 17px; }

/* ---------- Lightbox ----------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6,9,18,.92);
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lightbox-close { position: absolute; top: 16px; right: 16px; color: #fff; }

/* ---------- Toasts ------------------------------------------------------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  padding: 11px 16px;
  font-size: 14px;
  color: #fff;
  background: #1b2540;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  animation: rise .2s ease-out;
  max-width: min(90vw, 480px);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Statistics --------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }

.bar-row { display: grid; grid-template-columns: 110px 1fr 76px; align-items: center; gap: 10px; margin-bottom: 7px; font-size: 13px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- Responsive --------------------------------------------------- */
.only-mobile { display: none; }

@media (max-width: 720px) {
  .only-mobile { display: inline-grid; }
  .topbar { gap: 6px; padding: 0 8px; }
  .brand.small span { display: none; }
  .storage-pill { display: none; }
  .search { order: 3; flex-basis: 100%; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px; }
  .content { padding: 12px 10px 96px; }
  .row { padding: 10px; gap: 10px; }
  .thumb { width: 44px; height: 44px; }
  .btn span { display: none; }
  .modal { max-height: 92dvh; }
  .bar-row { grid-template-columns: 84px 1fr 64px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Show a "drop" hint over the whole window while dragging files in. */
body.dragging .dropzone { outline-color: var(--accent); }
