/* ==========================================================================
   TSD File Management System — base (light) theme + layout + components
   ========================================================================== */

:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f2f6;
  --color-surface-hover: #eef1f6;
  --color-border: #e0e4ea;
  --color-border-strong: #cbd2dc;
  --color-text: #1a2130;
  --color-text-secondary: #4b5565;
  --color-text-muted: #8993a4;
  --color-accent: #2f6fed;
  --color-accent-hover: #2559c7;
  --color-accent-soft: #e8f0fe;
  --color-accent-contrast: #ffffff;
  --color-danger: #d9432e;
  --color-danger-soft: #fbe9e7;
  --color-warning: #b9770e;
  --color-warning-soft: #fdf2e3;
  --color-success: #1e8a5f;
  --color-success-soft: #e6f6ef;
  --color-focus-ring: rgba(47, 111, 237, 0.35);

  --shadow-sm: 0 1px 2px rgba(20, 24, 34, 0.06);
  --shadow-md: 0 4px 14px rgba(20, 24, 34, 0.09);
  --shadow-lg: 0 12px 32px rgba(20, 24, 34, 0.14);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, monospace;

  --sidebar-width: 264px;
  --topbar-height: 60px;
  --transition-fast: 120ms ease;
  --transition-med: 200ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

::selection {
  background: var(--color-accent-soft);
}

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm {
  width: 14px;
  height: 14px;
}

.icon-lg {
  width: 28px;
  height: 28px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ==========================================================================
   App shell layout
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas: 'topbar topbar' 'sidebar main';
  height: 100vh;
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 20;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
}

.topbar-brand img,
.topbar-brand .brand-fallback {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.topbar-brand .brand-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent);
  color: #fff;
  font-size: 13px;
}

.topbar-search {
  flex: 1;
  max-width: 560px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.menu-toggle {
  display: none;
}

.sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: var(--space-4) var(--space-3) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.main {
  grid-area: main;
  overflow-y: auto;
  padding: var(--space-6);
}

.main-inner {
  max-width: 1280px;
  margin: 0 auto;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-surface-alt);
  color: var(--color-text);
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
}

.btn:hover {
  background: var(--color-surface-hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border-strong);
}

.btn-ghost {
  background: transparent;
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--color-danger);
}

.btn-danger-ghost:hover {
  background: var(--color-danger-soft);
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-md);
  background: transparent;
}

.btn-icon:hover {
  background: var(--color-surface-hover);
}

.btn-icon.favorited {
  color: var(--color-warning);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
}

.btn-block {
  width: 100%;
}

/* ==========================================================================
   Forms
   ========================================================================== */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-4);
}

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.field-hint {
  font-size: 12px;
  color: var(--color-text-muted);
}

.field-error {
  font-size: 12px;
  color: var(--color-danger);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.textarea {
  resize: vertical;
  min-height: 80px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box input {
  padding-left: 38px;
  background: var(--color-surface-alt);
  border-color: var(--color-border);
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

/* Only the search bar that actually has a shortcut-hint badge (the topbar
   global search) reserves room for it — other .search-box instances (e.g.
   the per-department search) are untouched. */
.search-box:has(.search-shortcut-hint) input {
  padding-right: 56px;
}

.search-box:hover input:not(:focus) {
  border-color: var(--color-border-strong);
}

.search-box input:focus {
  background: var(--color-surface);
}

.search-box input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.search-box .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
  transition: color 120ms ease;
}

.search-box:focus-within .icon {
  color: var(--color-accent);
}

.search-shortcut-hint {
  display: none;
  align-items: center;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: none;
  white-space: nowrap;
}

/* Only when the field is both empty (placeholder showing) and unfocused —
   the whole point of the hint is to tell you how to get here, so it's
   redundant the moment you already are. */
.search-box:not(:focus-within) input:placeholder-shown ~ .search-shortcut-hint {
  display: inline-flex;
}

.department-search {
  max-width: 420px;
}

.inline-search {
  max-width: 280px;
  min-width: 180px;
  flex: 1;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   Navigation / sidebar
   ========================================================================== */

.nav-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: 0 var(--space-2);
  margin-bottom: var(--space-1);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-weight: 500;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--color-surface-hover);
  text-decoration: none;
}

.nav-item.active {
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-weight: 600;
}

.nav-item .icon {
  color: var(--color-text-muted);
}

.nav-item.active .icon {
  color: var(--color-accent);
}

.nav-item .badge-count {
  margin-left: auto;
}

/* Folder tree */

.tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree .tree {
  padding-left: var(--space-4);
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 13px;
  -webkit-user-select: none;
  user-select: none;
}

.tree-row:hover {
  background: var(--color-surface-hover);
}

.tree-row.active {
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-weight: 600;
}

.tree-row.drag-over {
  outline: 2px dashed var(--color-accent);
  outline-offset: -2px;
}

.tree-toggle {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: transform var(--transition-fast);
}

.tree-toggle.expanded {
  transform: rotate(90deg);
}

.tree-toggle.leaf {
  visibility: hidden;
}

.tree-row .icon {
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.tree-row.active .icon {
  color: var(--color-accent);
}

.tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   Cards / stat cards
   ========================================================================== */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  flex-shrink: 0;
}

.stat-icon.warning {
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.stat-icon.success {
  background: var(--color-success-soft);
  color: var(--color-success);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.panel-header h2 {
  font-size: 15px;
}

.section-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-4);
}

@media (max-width: 1100px) {
  .section-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Lists (recent uploads / activity / trash / search results)
   ========================================================================== */

.simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.simple-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 4px;
  border-bottom: 1px solid var(--color-border);
}

.simple-list-item:last-child {
  border-bottom: none;
}

.simple-list-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.simple-list-main {
  min-width: 0;
  flex: 1;
}

.simple-list-title {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.simple-list-meta {
  font-size: 12px;
  color: var(--color-text-muted);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  text-align: center;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--color-text-secondary);
}

.quick-action:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-soft);
  text-decoration: none;
}

.quick-action .icon {
  width: 24px;
  height: 24px;
}

/* ==========================================================================
   Breadcrumb / toolbar
   ========================================================================== */

.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 13.5px;
  margin-bottom: var(--space-4);
}

.breadcrumb-item {
  color: var(--color-text-secondary);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumb-item:hover {
  background: var(--color-surface-hover);
  text-decoration: none;
}

.breadcrumb-item.current {
  color: var(--color-text);
  font-weight: 600;
}

.breadcrumb-sep {
  color: var(--color-text-muted);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.toolbar-spacer {
  flex: 1;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
}

.toolbar-group .btn-icon.active {
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  color: var(--color-accent);
}

/* ==========================================================================
   File grid & list views
   ========================================================================== */

.drop-zone {
  border: 2px dashed transparent;
  border-radius: var(--radius-lg);
  min-height: 220px;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.drop-zone.drag-active {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: var(--space-3);
}

.file-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  text-align: center;
}

.file-card:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-sm);
}

.file-card.selected {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.file-card-icon {
  width: 46px;
  height: 46px;
  color: var(--color-text-muted);
}

.file-card-icon.color-pdf { color: #d9432e; }
.file-card-icon.color-doc { color: #2f6fed; }
.file-card-icon.color-xls { color: #1e8a5f; }
.file-card-icon.color-ppt { color: #d9662e; }
.file-card-icon.color-zip { color: #b9770e; }
.file-card-icon.color-image { color: #8a4fd9; }
.file-card-icon.color-audio { color: #d94f9b; }
.file-card-icon.color-video { color: #2f6fed; }
.file-card-icon.color-folder { color: #f0b429; }

.file-card-name {
  font-size: 12.5px;
  font-weight: 600;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-card-meta {
  font-size: 11px;
  color: var(--color-text-muted);
}

.file-card-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 16px;
  height: 16px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.file-card:hover .file-card-checkbox,
.file-card.selected .file-card-checkbox {
  opacity: 1;
}

.file-card-favorite {
  position: absolute;
  top: 6px;
  right: 6px;
  color: var(--color-warning);
  width: 15px;
  height: 15px;
}

.file-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.file-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  white-space: nowrap;
}

.file-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.file-table tr:hover td {
  background: var(--color-surface-hover);
}

.file-table tr.selected td {
  background: var(--color-accent-soft);
}

.file-table .name-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.file-table .name-cell .icon {
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.file-table .name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

tr:hover .row-actions,
.file-card:hover .row-actions {
  opacity: 1;
}

/* ==========================================================================
   Empty state
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-4);
  color: var(--color-text-muted);
  text-align: center;
}

.empty-state .icon {
  width: 44px;
  height: 44px;
}

.empty-state-title {
  font-weight: 600;
  color: var(--color-text-secondary);
}

/* ==========================================================================
   Context menu
   ========================================================================== */

.context-menu {
  position: fixed;
  left: var(--menu-x, 0px);
  top: var(--menu-y, 0px);
  z-index: 1000;
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text);
}

.context-menu-item:hover {
  background: var(--color-surface-hover);
}

.context-menu-item.danger {
  color: var(--color-danger);
}

.context-menu-item.danger:hover {
  background: var(--color-danger-soft);
}

.context-menu-item[aria-disabled='true'] {
  opacity: 0.4;
  pointer-events: none;
}

.context-menu-sep {
  height: 1px;
  background: var(--color-border);
  margin: 6px 4px;
}

.context-menu-item .icon {
  color: var(--color-text-muted);
}

.context-menu-item.danger .icon {
  color: var(--color-danger);
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 30, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: var(--space-4);
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.modal.modal-lg {
  max-width: 760px;
}

.modal.modal-xl {
  max-width: 980px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
  font-size: 15px;
}

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
}

/* ==========================================================================
   Preview viewer
   ========================================================================== */

.preview-viewer {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
  min-height: 320px;
  max-height: 62vh;
  overflow: auto;
  padding: var(--space-4);
}

.preview-viewer img,
.preview-viewer video {
  max-width: 100%;
  max-height: 58vh;
  border-radius: var(--radius-sm);
}

.preview-viewer iframe {
  width: 100%;
  height: 58vh;
  border: none;
  border-radius: var(--radius-sm);
  background: #fff;
}

.preview-viewer audio {
  width: 100%;
}

.preview-viewer pre {
  width: 100%;
  height: 100%;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 12.5px;
  text-align: left;
}

.preview-unsupported {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-muted);
}

.preview-stack {
  display: flex;
  flex-direction: column;
  width: 100%;
  align-self: stretch;
}

.preview-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.pptx-slide {
  width: 100%;
  text-align: left;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

.pptx-slide:last-child {
  border-bottom: none;
}

/* ==========================================================================
   Toasts
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 1200;
  max-width: 340px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--color-text);
  color: #fff;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in 160ms ease;
}

.toast.success {
  background: var(--color-success);
}

.toast.error {
  background: var(--color-danger);
}

.toast.warning {
  background: var(--color-warning);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   Upload panel
   ========================================================================== */

.upload-panel {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  width: 340px;
  max-height: 60vh;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 900;
  overflow: hidden;
}

.upload-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 13px;
}

.upload-panel-list {
  overflow-y: auto;
  padding: var(--space-2);
}

.upload-item {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
}

.upload-item + .upload-item {
  margin-top: 2px;
}

.upload-item-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: 6px;
}

.upload-item-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-item-status {
  font-size: 11px;
  color: var(--color-text-muted);
}

.upload-item-status.error {
  color: var(--color-danger);
}

.upload-item-status.success {
  color: var(--color-success);
}

.progress {
  height: 5px;
  background: var(--color-surface-alt);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: var(--progress, 0%);
  background: var(--color-accent);
  border-radius: var(--radius-pill);
  transition: width 120ms linear;
}

/* ==========================================================================
   Badges / chips
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  background: var(--color-surface-alt);
  color: var(--color-text-secondary);
}

.badge-count {
  background: var(--color-surface-alt);
  color: var(--color-text-secondary);
  border-radius: var(--radius-pill);
  font-size: 11px;
  padding: 1px 7px;
}

.badge-accent {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.badge-danger {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.badge-success {
  background: var(--color-success-soft);
  color: var(--color-success);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
  font-size: 12px;
  border: 1px solid var(--color-border);
}

.chip button {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0;
  display: flex;
}

/* ==========================================================================
   Tables (users, activity, permissions, search results)
   ========================================================================== */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  padding: 10px;
  border-bottom: 1px solid var(--color-border);
}

.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--color-border);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

img.avatar {
  object-fit: cover;
}

.user-menu {
  position: relative;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-pill);
}

.user-menu-trigger:hover {
  background: var(--color-surface-hover);
}

.user-menu-name {
  font-weight: 600;
  font-size: 13px;
}

.user-menu-role {
  font-size: 11px;
  color: var(--color-text-muted);
}

.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 100;
}

/* ==========================================================================
   Auth pages (login / first-run setup)
   ========================================================================== */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(155deg, var(--color-bg) 0%, var(--color-accent-soft) 100%);
  padding: var(--space-4);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-8) var(--space-6);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  text-align: center;
}

.auth-brand img,
.auth-brand .brand-fallback {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
}

.auth-brand .brand-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

.auth-brand h1 {
  font-size: 17px;
}

.auth-brand p {
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.auth-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-danger-soft);
  color: var(--color-danger);
  font-size: 13px;
  margin-bottom: var(--space-4);
}

.auth-alert.info {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.auth-footer {
  margin-top: var(--space-5);
  text-align: center;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.theme-toggle-floating {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
}

/* ==========================================================================
   Utility
   ========================================================================== */

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.gap-2 {
  gap: var(--space-2);
}

.gap-3 {
  gap: var(--space-3);
}

.text-muted {
  color: var(--color-text-muted);
}

.text-secondary {
  color: var(--color-text-secondary);
}

.text-warning {
  color: var(--color-warning);
}

.mt-4 {
  margin-top: var(--space-4);
}

.mb-1 {
  margin-bottom: var(--space-1);
}

.logo-preview {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  object-fit: cover;
  border: 1px solid var(--color-border);
}

.filter-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.mb-4 {
  margin-bottom: var(--space-4);
}

.hidden {
  display: none !important;
}

.clickable {
  cursor: pointer;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-accent);
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: 'topbar' 'main';
  }

  .menu-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: min(84vw, 300px);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform var(--transition-med);
    z-index: 40;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--topbar-height);
    background: rgba(15, 20, 30, 0.35);
    z-index: 30;
  }

  .sidebar-scrim.open {
    display: block;
  }

  .topbar-brand span {
    display: none;
  }

  .search-shortcut-hint {
    display: none !important;
  }

  .search-box:has(.search-shortcut-hint) input {
    padding-right: 12px;
  }

  .file-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .upload-panel {
    width: calc(100vw - 32px);
    right: 16px;
    bottom: 16px;
  }
}

@media (max-width: 600px) {
  .main {
    padding: var(--space-4);
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .file-table thead {
    display: none;
  }

  .file-table,
  .file-table tbody,
  .file-table tr,
  .file-table td {
    display: block;
    width: 100%;
  }

  .file-table tr {
    border-bottom: 1px solid var(--color-border);
    padding: 8px 0;
  }

  .file-table td {
    border-bottom: none;
    padding: 3px 0;
  }
}
