:root {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --surface-alpha: rgba(255, 255, 255, 0.72);
  --ink: #1A1F27;
  --muted: #5B6572;
  --accent: #2A6F97;
  --accent-ink: #FFFFFF;
  --warm: #E4572E;
  --warm-dim: #FCE7E1;
  --line: rgba(20, 30, 45, 0.10);
  --mosaic-base: rgb(226, 232, 240);
  --mosaic-alt: rgb(206, 217, 230);
  --mosaic-glow: rgb(42, 111, 151);
  --radius: 10px;
  --radius-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1D2A52;
    --surface: #253763;
    --surface-alpha: rgba(37, 55, 99, 0.55);
    --ink: #F0F3FA;
    --muted: #AEB9D6;
    --accent: #6FB3E0;
    --accent-ink: #0B142B;
    --warm: #FF8360;
    --warm-dim: rgba(255, 131, 96, 0.18);
    --line: rgba(255, 255, 255, 0.12);
    --mosaic-base: rgb(29, 42, 82);
    --mosaic-alt: rgb(41, 58, 108);
    --mosaic-glow: rgb(111, 179, 224);
  }
}

:root[data-theme="dark"] {
  --bg: #1D2A52;
  --surface: #253763;
  --surface-alpha: rgba(37, 55, 99, 0.55);
  --ink: #F0F3FA;
  --muted: #AEB9D6;
  --accent: #6FB3E0;
  --accent-ink: #0B142B;
  --warm: #FF8360;
  --warm-dim: rgba(255, 131, 96, 0.18);
  --line: rgba(255, 255, 255, 0.12);
  --mosaic-base: rgb(29, 42, 82);
  --mosaic-alt: rgb(41, 58, 108);
  --mosaic-glow: rgb(111, 179, 224);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; font-size: inherit; }

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

.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

#mosaic {
  position: fixed;
  inset: 0;
  z-index: -1;
}

/* --- Glass surfaces --- */

.glass {
  background: var(--surface-alpha);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid var(--line);
}

/* --- Shell / sidebar --- */

.shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px 20px;
  border-radius: 0;
  border-width: 0 1px 0 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  font-size: 18px;
}
.brand:hover { text-decoration: none; }
.brand-logo { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  color: var(--ink);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.side-nav a:hover { background: var(--line); text-decoration: none; }
.side-nav a.active { background: var(--accent); color: var(--accent-ink); }

.side-search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
}

.sidebar-spacer { flex: 1; }

.storage-block { display: flex; flex-direction: column; gap: 6px; }
.storage-gauge-track { width: 100%; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.storage-gauge-fill { height: 100%; background: var(--warm); border-radius: 3px; }
.storage-gauge-label { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); }

.theme-switch { display: flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.theme-switch button {
  flex: 1;
  padding: 7px 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.theme-switch button + button { border-left: 1px solid var(--line); }
.theme-switch button.active { background: var(--accent); color: var(--accent-ink); }

.session { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.username { font-weight: 600; }
.badge {
  display: inline-block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--warm);
  color: var(--warm);
  border-radius: var(--radius-sm);
  width: fit-content;
}
.logout { color: var(--muted); font-size: 13px; }

/* --- Content --- */

.content-shell {
  flex: 1;
  min-width: 0;
  padding: 36px 44px 80px;
}

.center-panel {
  max-width: 480px;
  margin: 12vh auto;
  padding: 40px;
  border-radius: var(--radius);
  text-align: left;
}
.center-logo { width: 56px; height: 56px; object-fit: contain; margin-bottom: 12px; border-radius: 10px; }

h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; margin: 4px 0 20px; }
p { color: var(--ink); max-width: 62ch; }

.empty-note, .error-note { color: var(--muted); font-size: 15px; padding: 12px 0; }
.error-note { color: var(--warm); }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-lg { padding: 13px 24px; font-size: 16px; }

/* --- Breadcrumb --- */

.breadcrumb {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  color: var(--muted);
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}
.breadcrumb a { color: var(--muted); padding: 2px 4px; border-radius: 4px; }
.breadcrumb a:last-child { color: var(--ink); font-weight: 500; }
.breadcrumb a.drop-hover { background: var(--warm-dim); }
.breadcrumb .sep { color: var(--line); margin: 0 2px; }

/* --- Toolbar / list controls --- */

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.toolbar h1 { margin: 0; }
.toolbar-actions { display: flex; gap: 10px; }

.list-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 14px;
  font-size: 14px;
  color: var(--muted);
}
.sort-controls, .view-toggle { display: flex; align-items: center; gap: 12px; }
.sort-label { color: var(--muted); }
.sort-controls a, .view-toggle a { color: var(--muted); }
.sort-controls a.active, .view-toggle a.active { color: var(--accent); font-weight: 600; text-decoration: underline; }

/* --- Tile grid --- */

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

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alpha);
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.tile:hover { border-color: var(--accent); }
.tile.drop-hover { border-color: var(--warm); background: var(--warm-dim); }

.tile-open { display: flex; flex-direction: column; gap: 8px; color: var(--ink); }
.tile-open:hover { text-decoration: none; }

.tile-icon-img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}
.tile-icon-img.icon-empty { opacity: 0.45; filter: grayscale(60%); }

.tile-up {
  border-style: dashed;
  color: var(--muted);
}
.tile-up .tile-label { color: var(--muted); }

.tile-label { font-weight: 500; font-size: 15px; word-break: break-word; }
.tile-meta { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); }

.own-badge {
  align-self: flex-start;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 1px 6px;
}

.tile-actions { display: flex; gap: 8px; margin-top: 2px; }
.tile-actions button, .tile-actions form button {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 9px;
  cursor: pointer;
}
.tile-actions button:hover { border-color: var(--accent); color: var(--accent); }
.tile-actions form:last-child button:hover { border-color: var(--warm); color: var(--warm); background: var(--warm-dim); }

/* --- File table --- */

.file-table {
  width: 100%;
  border-collapse: collapse;
  border-radius: var(--radius);
  overflow: hidden;
}
.file-table th, .file-table td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.file-table th { font-weight: 500; color: var(--muted); font-size: 13px; }
.file-table tr:last-child td { border-bottom: none; }
.file-table tr.drop-hover { background: var(--warm-dim); }
.actions-cell { text-align: right; white-space: nowrap; }
.actions-cell button, .actions-cell form { display: inline-block; }
.actions-cell button, .actions-cell form button {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 9px;
  margin-left: 6px;
  cursor: pointer;
}
.actions-cell button:hover { border-color: var(--accent); color: var(--accent); }
.row-icon-img { width: 22px; height: 22px; object-fit: contain; margin-right: 10px; vertical-align: middle; }
.row-icon-img.icon-empty { opacity: 0.45; filter: grayscale(60%); }

/* --- File-type tints (very slight background shade) --- */

.tile.tint-pdf, tr.tint-pdf { background: color-mix(in srgb, var(--surface-alpha) 85%, #E4483F 15%); }
.tile.tint-sheet, tr.tint-sheet { background: color-mix(in srgb, var(--surface-alpha) 85%, #2E9E5B 15%); }
.tile.tint-doc, tr.tint-doc { background: color-mix(in srgb, var(--surface-alpha) 85%, #2A6DB0 15%); }
.tile.tint-slide, tr.tint-slide { background: color-mix(in srgb, var(--surface-alpha) 85%, #D9772E 15%); }

/* --- Modals --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 24, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius);
  padding: 24px;
  background: var(--surface);
}
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.upload-preview-list { max-height: 220px; overflow-y: auto; padding-left: 20px; font-size: 14px; }

.preview-modal { max-width: 80vw; }
.preview-image, .preview-embed { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: var(--radius-sm); }
.preview-embed { width: 70vw; height: 70vh; }

/* --- Whole-screen upload drop veil --- */

.drop-veil {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(42, 111, 151, 0.12);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border: 3px dashed var(--accent);
  pointer-events: none;
}
.drop-veil.active { display: flex; }
.drop-veil-inner {
  padding: 18px 32px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  font-size: 20px;
}

/* --- Responsive --- */

@media (max-width: 860px) {
  html, body { font-size: 16px; }
  .shell { flex-direction: column; min-height: auto; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    top: auto;
    flex-direction: column;
    gap: 14px;
    padding: 16px 18px;
    border-width: 0 0 1px 0;
  }
  .sidebar-spacer { display: none; }
  .session { flex-direction: row; align-items: center; justify-content: space-between; }

  .content-shell { padding: 20px; }
  h1 { font-size: 21px; }

  .toolbar { gap: 10px; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { flex: 1; }

  .list-controls { flex-wrap: wrap; gap: 10px; }

  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .tile { padding: 12px; }

  .file-table th:nth-child(3), .file-table td:nth-child(3) { display: none; }
  .file-table th, .file-table td { padding: 10px 10px; font-size: 14px; }

  .modal { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
}
