/* Dark theme (default) */
:root,
[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #121a2b;
  --surface-2: #1a2438;
  --border: #2a3650;
  --text: #eef3fb;
  --muted: #93a4bf;
  --primary: #4f8cff;
  --primary-hover: #3b76e8;
  --danger: #ef4444;
  --danger-text: #fca5a5;
  --success: #22c55e;
  --success-text: #86efac;
  --topbar-bg: rgba(18, 26, 43, 0.92);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --aside-gradient: linear-gradient(160deg, rgba(79, 140, 255, 0.18), rgba(18, 26, 43, 1));
  --code-bg: var(--surface-2);
}

/* Light theme */
[data-theme="light"] {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --border: #d5deea;
  --text: #0f172a;
  --muted: #5b6b82;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-text: #991b1b;
  --success: #16a34a;
  --success-text: #166534;
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  --aside-gradient: linear-gradient(160deg, rgba(37, 99, 235, 0.08), rgba(244, 247, 251, 1));
  --code-bg: #eef2f8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Segoe UI, system-ui, sans-serif;
  line-height: 1.5;
  transition: background 0.2s ease, color 0.2s ease;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

input, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}

input:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  border-radius: 10px;
  padding: 0.6rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid transparent; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.card-pad { padding: 1.25rem; }

.badge, .chip {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}

.badge-admin { background: rgba(79, 140, 255, 0.18); color: #3b82f6; }
[data-theme="light"] .badge-admin { color: #1d4ed8; }
.badge-read { background: rgba(34, 197, 94, 0.15); color: var(--success-text); }
.badge-write { background: rgba(245, 158, 11, 0.15); color: #b45309; }
[data-theme="dark"] .badge-write { color: #fcd34d; }
.badge-admin-level { background: rgba(168, 85, 247, 0.15); color: #7c3aed; }

.alert { padding: 0.85rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.alert-error { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.35); color: var(--danger-text); }
.alert-success { background: rgba(34, 197, 94, 0.12); border: 1px solid rgba(34, 197, 94, 0.35); color: var(--success-text); }

.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.topbar-settings-link {
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid transparent;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.topbar-settings-link:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}
.topbar-settings-link.is-active {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}
.topbar nav { display: flex; gap: 1rem; margin-left: 1rem; }
.topbar nav a { color: var(--muted); }
.topbar nav a.active, .logo { font-weight: 700; color: var(--text); }

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.logo-image {
  height: 2rem;
  width: auto;
  max-width: 9rem;
  object-fit: contain;
  display: block;
}

.logo-fallback {
  font-size: 1.35rem;
  line-height: 1;
}

.logo-text {
  white-space: nowrap;
}

.logo-upload-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 6rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.logo-preview-image {
  max-height: 4.5rem;
  max-width: 100%;
  object-fit: contain;
}

.logo-preview-empty {
  font-size: 0.92rem;
}

.logo-upload-form {
  max-width: 28rem;
}

.brand-logo-large .brand-logo-image {
  max-height: 5.5rem;
  max-width: 14rem;
  object-fit: contain;
  margin: 0 auto;
  display: block;
}

.brand-logo-image {
  max-height: 3rem;
  max-width: 10rem;
  object-fit: contain;
}
.user-chip { color: var(--muted); font-size: 0.9rem; }

.theme-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.theme-picker-label {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.theme-select {
  width: auto;
  min-width: 7rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
  background: var(--surface-2);
}

.theme-select-menu {
  width: 100%;
  min-width: 0;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.user-bar-label {
  color: var(--muted);
}

.user-bar-name {
  font-weight: 600;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-bar-logout {
  margin: 0;
}

.user-menu {
  position: relative;
}

.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.user-menu-trigger:hover,
.user-menu.open .user-menu-trigger {
  border-color: var(--primary);
  background: var(--surface);
}

.user-menu-name {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-chevron {
  color: var(--muted);
  font-size: 0.85rem;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  min-width: 220px;
  padding: 0.65rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 50;
}

.user-menu-panel[hidden] {
  display: none;
}

.user-menu-email {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0.15rem 0.35rem 0.65rem;
  word-break: break-all;
}

.user-menu-section {
  padding: 0.15rem 0.35rem;
}

.user-menu-label {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 0.55rem 0;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}

.user-menu-item:hover {
  background: var(--surface-2);
}

a.user-menu-item {
  display: block;
  text-decoration: none;
  color: var(--text);
}

.user-menu-logout {
  color: var(--danger-text);
}

.user-menu-logout:hover {
  background: rgba(239, 68, 68, 0.1);
}

.item-menu {
  position: relative;
  display: inline-flex;
}

.item-menu-trigger {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.item-menu-trigger:hover,
.item-menu.open .item-menu-trigger {
  color: var(--text);
  border-color: var(--primary);
  background: var(--surface);
}

.item-menu-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  min-width: 9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.35rem;
  z-index: 30;
}

.item-menu-panel[hidden] {
  display: none !important;
}

.item-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}

.item-menu-item:hover {
  background: var(--surface-2);
}

a.item-menu-item {
  text-decoration: none;
}

.item-menu-danger {
  color: var(--danger-text);
}

.item-menu-danger:hover {
  background: rgba(239, 68, 68, 0.12);
}

.item-menu form {
  margin: 0;
}

.page { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 2rem; }
.page-browser {
  max-width: 1600px;
  padding: 1.75rem 1.5rem 2.5rem;
}

.browser-layout {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.folder-sidebar {
  position: sticky;
  top: 4.75rem;
  max-height: calc(100vh - 5.5rem);
  overflow: auto;
  padding: 0.5rem 0;
}

.folder-sidebar-head {
  padding: 0.65rem 1rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.folder-tree {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0 0.35rem 0.5rem;
}

.folder-tree-link {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.65rem;
  padding-left: calc(0.65rem + var(--depth, 0) * 0.85rem);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.3;
  min-width: 0;
}

.folder-tree-link:hover {
  background: var(--surface-2);
}

.folder-tree-link.is-active {
  background: rgba(79, 140, 255, 0.18);
  color: var(--primary);
  font-weight: 600;
}

[data-theme="light"] .folder-tree-link.is-active {
  background: rgba(37, 99, 235, 0.1);
  color: #1d4ed8;
}

.folder-tree-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.folder-tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-tree-empty {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
}

.folder-sidebar-foot {
  margin-top: 0.5rem;
  padding: 0.35rem 0.35rem 0.5rem;
  border-top: 1px solid var(--border);
}

.recycle-bin-link {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.recycle-bin-icon {
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.recycle-bin-count {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}

.recycle-name-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.recycle-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(200px, 240px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.admin-sidebar {
  position: sticky;
  top: 4.75rem;
  max-height: calc(100vh - 5.5rem);
  overflow: auto;
  padding: 0.5rem 0;
}

.admin-sidebar-head {
  padding: 0.65rem 1rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0 0.35rem 0.5rem;
}

.admin-nav-link {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.3;
}

.admin-nav-link:hover {
  background: var(--surface-2);
}

.admin-nav-link.is-active {
  background: rgba(79, 140, 255, 0.18);
  color: var(--primary);
  font-weight: 600;
}

[data-theme="light"] .admin-nav-link.is-active {
  background: rgba(37, 99, 235, 0.1);
  color: #1d4ed8;
}

.admin-main {
  min-width: 0;
}

.admin-page-title {
  margin: 0 0 1rem;
  font-size: 1.5rem;
}

.page-admin {
  padding-top: 1.25rem;
}

.browser-main {
  min-width: 0;
}

.browser-folder-path {
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

.browser-folder-path a {
  color: var(--primary);
}

.page-header { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 1.25rem; flex-wrap: wrap; position: relative; z-index: 20; }
.page-header h1, .page h1 { font-size: 1.75rem; margin-bottom: 0.4rem; }
.breadcrumbs { display: flex; gap: 0.4rem; flex-wrap: wrap; color: var(--muted); font-size: 0.95rem; }
.breadcrumbs a { color: var(--primary); }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.new-file-menu {
  position: relative;
  display: inline-flex;
}

.new-file-menu.open {
  z-index: 50;
}

.new-file-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  min-width: 13rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.35rem;
  z-index: 51;
}

.new-file-panel[hidden] {
  display: none !important;
}

.new-file-option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}

.new-file-option:hover {
  background: var(--surface-2);
}

.new-file-option-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  line-height: 1;
}

.new-file-option-icon .file-type-icon {
  width: 20px;
  height: 20px;
}

.browser-panel {
  overflow: hidden;
  min-height: 28rem;
}

.browser-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.35rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.browser-panel-title {
  font-weight: 700;
  font-size: 1rem;
}

.browser-list-head,
.browser-item {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) 10.5rem 9.5rem 5.5rem auto;
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0 1rem;
}

.browser-list-head {
  min-height: 1.75rem;
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.browser-sort-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: inherit;
  text-decoration: none;
  padding: 0.1rem 0;
  border-radius: 4px;
}

.browser-sort-link:hover {
  color: var(--text);
}

.browser-sort-link.is-active {
  color: var(--text);
  font-weight: 600;
}

.browser-sort-arrow {
  font-size: 0.65rem;
  line-height: 1;
  color: var(--primary);
}

[data-theme="light"] .browser-list-head {
  background: var(--surface-2);
}

.browser-list-head span:last-child,
.browser-actions {
  justify-self: end;
}

.browser-item {
  min-height: 1.625rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
}

.browser-item:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

[data-theme="light"] .browser-item:nth-child(even) {
  background: rgba(15, 23, 42, 0.02);
}

.browser-item:last-child {
  border-bottom: 0;
}

.browser-item:hover {
  background: rgba(79, 140, 255, 0.08);
}

[data-theme="light"] .browser-item:hover {
  background: rgba(37, 99, 235, 0.06);
}

.browser-name-cell {
  min-width: 0;
}

.browser-name {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  padding: 0.2rem 0;
  color: inherit;
}

.browser-name[hidden] {
  display: none !important;
}

.browser-rename-form {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  width: 100%;
  padding: 0.15rem 0;
}

.browser-rename-form[hidden] {
  display: none !important;
}

.browser-item.is-renaming {
  background: rgba(79, 140, 255, 0.1);
}

.browser-rename-field {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}

.browser-rename-input {
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 400;
  padding: 0.25rem 0.45rem;
}

.browser-rename-ext {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 400;
  white-space: nowrap;
}

.browser-rename-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.browser-name:hover .browser-title {
  color: var(--primary);
}

.browser-icon,
.file-type-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: block;
}

.browser-icon {
  border: 0;
  border-radius: 0;
  background: transparent;
}


.browser-title {
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.browser-col {
  font-size: 0.8125rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.browser-meta,
.browser-info {
  font-size: 0.8125rem;
  min-width: 0;
}

.browser-actions .btn-sm {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
}

.browser-empty {
  min-height: 24rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 1.5rem;
}

@media (max-width: 980px) {
  .browser-list-head {
    display: none;
  }

  .browser-item {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name actions"
      "meta actions"
      "info actions";
    gap: 0.2rem 0.75rem;
    padding: 0.55rem 0.85rem;
    min-height: auto;
  }

  .browser-name-cell,
  .browser-rename-form {
    grid-area: name;
  }

  .browser-rename-form {
    flex-wrap: wrap;
  }

  .browser-rename-actions {
    width: 100%;
  }

  .browser-col:nth-of-type(2) {
    grid-area: meta;
    font-size: 0.78rem;
  }

  .browser-col:nth-of-type(3) {
    grid-area: info;
    font-size: 0.78rem;
  }

  .browser-col:nth-of-type(4) {
    display: none;
  }

  .browser-meta {
    grid-area: meta;
    font-size: 0.78rem;
  }

  .browser-info {
    grid-area: info;
    font-size: 0.78rem;
  }

  .browser-actions {
    grid-area: actions;
    align-self: start;
  }

  .browser-title {
    font-size: 1.05rem;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.row-link { font-weight: 600; }
.row-link:hover { color: var(--primary); }
.file-link { display: inline-flex; align-items: center; gap: 0.35rem; }
.row-actions { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field label { color: var(--muted); font-size: 0.88rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1.2fr; gap: 1rem; }
@media (max-width: 900px) {
  .browser-layout,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .folder-sidebar,
  .admin-sidebar {
    position: static;
    max-height: none;
  }

  .admin-nav {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0.35rem 0.5rem 0.5rem;
  }
}

@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.tabs { display: flex; gap: 0.5rem; margin: 1rem 0; flex-wrap: wrap; }
.tab { padding: 0.55rem 0.9rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }

.auth-layout-minimal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg);
  overflow: auto;
}
.auth-window {
  width: min(100%, 18rem);
  flex-shrink: 0;
  padding: 1rem 1.1rem !important;
}
.auth-layout-minimal .brand {
  margin-bottom: 0.85rem;
}
.auth-layout-minimal .brand-logo-large .brand-logo-image {
  max-height: 3.5rem;
  max-width: 9rem;
}
.auth-layout-minimal .brand-icon {
  font-size: 2rem;
}
.auth-layout-minimal .field {
  margin-bottom: 0.75rem;
}
.auth-layout-minimal .auth-form .field:last-of-type {
  margin-bottom: 0.85rem;
}
.auth-layout-minimal input {
  padding: 0.55rem 0.7rem;
  font-size: 0.92rem;
}
.auth-layout-minimal .field label {
  font-size: 0.82rem;
}
.auth-layout-minimal .btn {
  padding: 0.5rem 0.85rem;
  font-size: 0.92rem;
}
.auth-layout-minimal .alert {
  padding: 0.65rem 0.8rem;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
}
.auth-layout { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 0.9fr; }
.auth-panel { display: flex; flex-direction: column; justify-content: center; padding: 2rem; }
.auth-aside {
  background: var(--aside-gradient), var(--surface);
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-aside h2 { margin-bottom: 1rem; }
.auth-aside li { margin: 0.65rem 0; color: var(--muted); }
.brand { text-align: center; margin-bottom: 1.5rem; }
.brand-icon { font-size: 2.8rem; }
.brand h1 { font-size: 1.8rem; margin-top: 0.4rem; }
.brand p, .hint { color: var(--muted); margin-top: 0.35rem; text-align: center; }
.auth-theme { display: flex; justify-content: center; margin-bottom: 1rem; }
@media (max-width: 900px) { .auth-layout { grid-template-columns: 1fr; } .auth-aside { display: none; } }

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(480px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  margin: 0;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 200;
}

.modal-wide {
  width: min(560px, calc(100vw - 2rem));
}

.modal[open] {
  display: block;
}

.modal > form,
.modal > .card {
  width: 100%;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

.manage-user-section {
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
}

.manage-user-section:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}

.manage-user-section h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.manage-user-groups-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.manage-user-group-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.45rem 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.manage-user-group-remove-form {
  display: inline;
  margin: 0;
}

.manage-user-group-remove {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
}

.manage-user-group-remove:hover {
  color: var(--danger-text);
}

.manage-user-danger {
  padding: 0.9rem;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.manage-user-danger h3 {
  color: var(--danger-text);
}

.manage-share-permissions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.manage-share-perm-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.manage-share-perm-name {
  min-width: 7rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.manage-share-perm-form,
.manage-share-perm-revoke-form {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}

.tab-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  margin-bottom: 1rem;
}
.tab-toolbar h2 { margin: 0; font-size: 1.15rem; }

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.audit-filters {
  margin-bottom: 1rem;
}

.audit-filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem 1rem;
}

.audit-filters-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.audit-filters-actions .muted {
  margin-left: auto;
}

.editor-shell { min-height: 100vh; display: flex; flex-direction: column; }
.editor-main { flex: 1; padding: 0; display: flex; flex-direction: column; min-height: 0; }
.editor-frame { width: 100%; height: calc(100vh - 76px); border: 1px solid var(--border); border-radius: 12px; background: white; }

.pdf-viewer-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  min-height: 0;
}
.pdf-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.pdf-viewer-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.pdf-viewer-actions { display: flex; gap: 0.45rem; }
.pdf-viewer-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #525659;
}
.center { text-align: center; max-width: 640px; margin: 2rem auto; }

/* Notepad / plain-text editor */
.notepad-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 60px);
  background: var(--notepad-canvas);
}
[data-theme="dark"] .notepad-workspace {
  --notepad-canvas: #0a0f18;
  --notepad-paper: #141c2b;
  --notepad-paper-text: #eef3fb;
  --notepad-ribbon-bg: #121a2b;
}
[data-theme="light"] .notepad-workspace {
  --notepad-canvas: #e8edf4;
  --notepad-paper: #ffffff;
  --notepad-paper-text: #1a1f2e;
  --notepad-ribbon-bg: #f7f9fc;
}

.notepad-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.notepad-ribbon {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.35rem 0;
  padding: 0.5rem 1rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: var(--notepad-ribbon-bg, var(--surface-2));
}

.notepad-ribbon-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.5rem;
  min-width: 0;
}

.notepad-ribbon-group--font {
  align-items: stretch;
}

.notepad-ribbon-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1;
  user-select: none;
}

.notepad-ribbon-row {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.notepad-ribbon-divider {
  width: 1px;
  align-self: stretch;
  margin: 0.15rem 0.35rem 0;
  background: var(--border);
}

.notepad-ribbon-spacer { flex: 1; min-width: 1rem; }

.notepad-ribbon-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding-bottom: 0.1rem;
}

.notepad-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.notepad-icon-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: currentColor;
}

.notepad-icon-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  border-color: var(--border);
}

.notepad-icon-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.notepad-icon-btn.is-active {
  background: color-mix(in srgb, var(--primary) 16%, var(--surface));
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  color: var(--primary);
}

.notepad-select {
  height: 2rem;
  padding: 0 1.75rem 0 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%2393a4bf' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") no-repeat right 0.45rem center;
  color: var(--text);
  font-size: 0.8125rem;
  appearance: none;
  cursor: pointer;
}

.notepad-select:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent);
  outline-offset: 1px;
}

.notepad-select--font { min-width: 8.5rem; }
.notepad-select--size { min-width: 3.75rem; }

.notepad-document {
  flex: 1;
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: 1.25rem 1.5rem 1rem;
  overflow: hidden;
}

.notepad-editor {
  width: 100%;
  max-width: 52rem;
  flex: 1;
  min-height: 0;
  padding: 2rem 2.25rem 2.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--notepad-paper, var(--surface));
  color: var(--notepad-paper-text, var(--text));
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.65;
  resize: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  box-shadow: var(--shadow);
  outline: none;
}

.notepad-editor:focus {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--border));
  box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
}

.notepad-statusbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  padding: 0.35rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--notepad-ribbon-bg, var(--surface-2));
  font-size: 0.75rem;
  color: var(--muted);
}

.notepad-status-item {
  white-space: nowrap;
}

.notepad-status-dirty {
  color: var(--primary);
  font-weight: 600;
}

.notepad-status-hint {
  margin-left: auto;
  white-space: nowrap;
  font-size: 0.72rem;
  opacity: 0.85;
}

@media (max-width: 720px) {
  .notepad-ribbon { padding: 0.5rem 0.65rem; }
  .notepad-ribbon-group { padding: 0 0.25rem; }
  .notepad-document { padding: 0.75rem; }
  .notepad-editor { padding: 1.25rem 1rem 1.5rem; }
  .notepad-status-hint { display: none; }
}

.editor-actions { display: flex; gap: 0.5rem; justify-content: flex-end; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.docx-preview {
  background: white;
  color: #111;
  padding: 2rem;
  border-radius: 10px;
  min-height: 200px;
  line-height: 1.6;
}
.docx-preview h1, .docx-preview h2, .docx-preview h3 { margin: 1rem 0 0.5rem; }

.settings-list { display: grid; grid-template-columns: 140px 1fr; gap: 0.65rem 1rem; }
.settings-list dt { color: var(--muted); font-size: 0.88rem; }
.settings-list dd { margin: 0; word-break: break-all; }
.settings-links { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.settings-help { margin-left: 1.25rem; color: var(--muted); }
.settings-help li { margin: 0.4rem 0; }

code {
  background: var(--code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-size: 0.9em;
}
