/* Files Data — modern card UI with light/dark themes */

:root {
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.1);
  --transition: 180ms ease;

  --bg: #eef3f1;
  --bg-elevated: #ffffff;
  --bg-soft: #f7faf9;
  --text: #0f1f1a;
  --text-muted: #5b6b66;
  --border: #d7e2dd;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-soft: rgba(15, 118, 110, 0.1);
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #059669;
  --warning: #d97706;
  --input-bg: #ffffff;
  --topbar-bg: rgba(255, 255, 255, 0.82);
  --sidebar-w: 280px;
  --overlay: rgba(15, 23, 42, 0.45);
  --auth-glow: radial-gradient(1200px 600px at 10% -10%, rgba(15, 118, 110, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(14, 116, 144, 0.14), transparent 50%),
    linear-gradient(160deg, #e8f2ef 0%, #eef3f1 45%, #e7eef5 100%);
}

[data-theme="dark"] {
  --bg: #0b1412;
  --bg-elevated: #121c19;
  --bg-soft: #182420;
  --text: #e8f0ed;
  --text-muted: #93a59e;
  --border: #24332e;
  --primary: #2dd4bf;
  --primary-hover: #5eead4;
  --primary-soft: rgba(45, 212, 191, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --success: #34d399;
  --warning: #fbbf24;
  --input-bg: #0f1916;
  --topbar-bg: rgba(11, 20, 18, 0.88);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
  --overlay: rgba(0, 0, 0, 0.6);
  --auth-glow: radial-gradient(1000px 500px at 0% 0%, rgba(45, 212, 191, 0.12), transparent 50%),
    radial-gradient(800px 400px at 100% 10%, rgba(56, 189, 248, 0.08), transparent 45%),
    linear-gradient(165deg, #0b1412 0%, #0e1a17 50%, #0c1520 100%);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

body.auth-checking .boot-loader { display: flex; }
body:not(.auth-checking) .boot-loader { display: none; }
body.auth-checking .auth-shell,
body.auth-checking .app-shell { visibility: hidden; }

.boot-loader {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 10000;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.85rem; }
.mobile-only { display: none; }

/* Buttons & inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 1.05rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.25);
}
.btn--primary:hover { background: var(--primary-hover); }
[data-theme="dark"] .btn--primary { color: #042f2e; }
.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn--ghost:hover { background: var(--bg-soft); }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.65; cursor: not-allowed; }
.btn.is-loading { position: relative; }
.btn.is-loading .btn-label { opacity: 0; }
.btn .spinner--btn { display: none; }
.btn.is-loading .spinner--btn {
  display: inline-block;
  position: absolute;
  left: 50%;
  top: 50%;
  margin: -9px 0 0 -9px;
}

.ghost-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.icon-btn:hover { background: var(--bg-soft); border-color: var(--primary); }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 500;
}
.field input,
.field select,
.toolbar input,
.client-picker input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus,
.field select:focus,
.toolbar input:focus,
.client-picker input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.input-with-action {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
  padding-right: 0.35rem;
}
.input-with-action input {
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.alert {
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.alert--error { background: var(--danger-soft); color: var(--danger); }
.alert--info { background: var(--primary-soft); color: var(--primary); }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner--btn {
  width: 18px;
  height: 18px;
  border-width: 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Theme toggle icons */
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
.theme-fab {
  position: relative;
  top: auto;
  right: auto;
  z-index: 20;
}
.auth-toolbar {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Auth */
.auth-page {
  background: var(--auth-glow);
  min-height: 100dvh;
}
.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-stack {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.auth-card {
  width: 100%;
  padding: 2rem 1.75rem;
  animation: riseIn 0.45s ease both;
}
.demo-users {
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 38%, var(--border));
  border-radius: 14px;
  padding: 14px 16px 16px;
  animation: riseIn 0.45s ease 0.08s both;
}
.demo-users-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 12px;
  text-align: start;
}
.demo-users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.demo-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
}
.demo-user-btn {
  width: auto;
  flex: none;
  text-align: center;
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  font-family: inherit;
  white-space: nowrap;
  transition: background var(--transition), transform 120ms ease;
}
.demo-user-btn:hover {
  background: var(--primary-hover);
}
.demo-user-creds {
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}
.login-footer {
  text-align: center;
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand h1 {
  margin: 0.85rem 0 0.35rem;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
}
.auth-brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.auth-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.15);
}
.auth-mark--sm {
  width: 40px;
  height: 40px;
  margin: 0;
  border-radius: 12px;
}
@keyframes riseIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* App shell */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100dvh;
  background:
    radial-gradient(800px 400px at 100% -10%, rgba(15, 118, 110, 0.08), transparent 50%),
    var(--bg);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1.15rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  z-index: 30;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-brand strong { display: block; font-size: 1rem; }
.sidebar-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.55rem;
}
.folder-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow: auto;
  max-height: calc(100dvh - 180px);
}
.folder-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.folder-item:hover { background: var(--bg-soft); }
.folder-item.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}
.folder-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  font-size: 0.85rem;
}
.folder-item.is-active .folder-icon { background: var(--bg-elevated); }
.sidebar-footer { margin-top: auto; }

.socket-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}
.socket-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.socket-pill.is-live .socket-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.18);
  animation: pulse 1.6s ease infinite;
}
.socket-pill.is-live { color: var(--success); }
.socket-pill.is-off .socket-dot { background: var(--warning); }
.socket-pill.is-error .socket-dot { background: var(--danger); }
.socket-pill.is-error { color: var(--danger); }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.7; }
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 25;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.topbar-sub {
  margin: 0.1rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.live-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.2s ease, transform 0.2s ease;
}
.live-pulse.is-flash {
  background: var(--success);
  transform: scale(1.4);
  box-shadow: 0 0 0 6px rgba(5, 150, 105, 0.2);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.35rem 0.25rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.88rem;
  font-weight: 600;
}

.toolbar {
  position: relative;
  z-index: 20;
  margin: 1rem 1.25rem 0;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow: visible;
  animation: riseIn 0.4s ease both;
}
.toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.toolbar-search {
  position: relative;
  flex: 1;
  min-width: 0;
}
.toolbar-search .search-icon,
.client-picker .search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}
.toolbar-search input,
.client-picker input {
  width: 100%;
  padding-left: 2.4rem;
}
.client-picker {
  position: relative;
  flex: 1;
  min-width: 0;
  width: 100%;
}
.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow: auto;
  z-index: 80;
}
.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0.7rem 0.85rem;
  font: inherit;
  cursor: pointer;
}
.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--primary-soft);
  color: var(--primary);
  outline: none;
}
.dropdown-empty {
  padding: 0.85rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  min-height: 44px;
  padding: 0.45rem 0.4rem 0.45rem 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(15, 118, 110, 0.35);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.chip--client {
  width: 100%;
}
.chip-prefix {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 8px;
  padding: 0.2rem 0.45rem;
}
.chip-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-clear {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chip-clear:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.content {
  position: relative;
  z-index: 1;
  padding: 1rem 1.25rem 2rem;
  flex: 1;
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  transition: opacity var(--transition);
}
.file-grid.is-dim { opacity: 0.45; }

.file-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  animation: riseIn 0.35s ease both;
}
.file-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(15, 118, 110, 0.35);
}
.file-thumb {
  height: 140px;
  background:
    linear-gradient(145deg, var(--bg-soft), var(--bg-elevated));
  display: grid;
  place-items: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.file-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.file-thumb-fallback {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: var(--primary-soft);
}
.file-body { padding: 0.95rem 1rem 0.5rem; flex: 1; }
.file-name {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.file-meta {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.file-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.7rem;
}
.tag {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.22rem 0.5rem;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
}
.tag--muted {
  background: var(--bg-soft);
  color: var(--text-muted);
}
.file-actions {
  display: flex;
  gap: 0.35rem;
  padding: 0.65rem 0.85rem 0.9rem;
  border-top: 1px solid transparent;
}
.icon-action {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.icon-action:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}
.icon-action--danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

.empty-state, .loading-state {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--text-muted);
}
.empty-state h2 {
  margin: 0.5rem 0 0.35rem;
  color: var(--text);
}
.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
}
.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 1.25rem;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-card {
  width: min(480px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: visible;
  animation: riseIn 0.25s ease;
}
.modal-card--wide {
  width: min(920px, 100%);
  max-height: min(90dvh, 860px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-card--upload {
  width: min(520px, 100%);
  overflow: visible;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-header .muted {
  margin: 0.25rem 0 0;
}
.modal-actions { display: flex; align-items: center; gap: 0.4rem; }
.modal-form { padding: 1.1rem; }
.modal-form .req {
  color: var(--danger);
  font-style: normal;
  font-weight: 700;
}
.modal-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
}
.client-picker--modal {
  width: 100%;
}
.field .chip--client {
  margin-top: 0.55rem;
}
.field.has-upload-client .client-picker--modal {
  display: none;
}
.file-drop {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: 14px;
  background: var(--bg-soft);
  min-height: 132px;
  display: grid;
  place-items: center;
  text-align: center;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.file-drop.is-dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.file-drop.has-file {
  border-style: solid;
  border-color: rgba(15, 118, 110, 0.35);
}
.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.file-drop-content {
  pointer-events: none;
  padding: 1.1rem 1rem;
  display: grid;
  gap: 0.25rem;
  justify-items: center;
}
.file-drop-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  margin-bottom: 0.25rem;
}
.file-drop-content strong {
  font-size: 0.95rem;
}
.file-drop-content .muted {
  margin: 0;
  font-size: 0.8rem;
}
.file-picker {
  position: relative;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 1rem;
  background: var(--bg-soft);
  color: var(--text-muted);
  text-align: center;
}
.file-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.preview-body {
  min-height: 360px;
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  flex: 1;
}
.preview-image {
  max-width: 100%;
  max-height: min(70dvh, 640px);
  object-fit: contain;
}
.preview-frame {
  width: 100%;
  height: min(70dvh, 640px);
  border: 0;
  background: #fff;
}

/* Toasts */
.toast-host {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-in { opacity: 1; transform: none; }
.toast--success { border-color: rgba(5, 150, 105, 0.35); }
.toast--error { border-color: rgba(220, 38, 38, 0.35); color: var(--danger); }
.toast--info { border-color: rgba(15, 118, 110, 0.35); }

/* Responsive */
@media (max-width: 980px) {
  .toolbar-row {
    flex-wrap: wrap;
  }
  .toolbar-row > .btn--primary {
    width: 100%;
  }
}

@media (max-width: 860px) {
  .mobile-only { display: inline-flex; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .sidebar-backdrop.is-open { display: block; }
  .user-chip span { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar { padding: 0.85rem 1rem; }
  .content, .toolbar { margin-left: 1rem; margin-right: 1rem; }
  .content { padding-left: 0; padding-right: 0; }
  .toolbar { margin-top: 0.85rem; }
}

@media (max-width: 480px) {
  .auth-card { padding: 1.5rem 1.15rem; }
  .file-grid { grid-template-columns: 1fr; }
  .topbar-right .ghost-btn { display: none; }
}

/* Language switcher */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.lang-select-wrap {
  display: inline-flex;
  align-items: center;
}
.lang-select {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 1.75rem 0.45rem 0.65rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235b6b66' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
}
.lang-select:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

/* RTL layout */
[dir="rtl"] .sidebar {
  border-right: 0;
  border-left: 1px solid var(--border);
}
[dir="rtl"] .folder-item,
[dir="rtl"] .dropdown-item {
  text-align: right;
}
[dir="rtl"] .toolbar-search .search-icon,
[dir="rtl"] .client-picker .search-icon {
  left: auto;
  right: 0.85rem;
}
[dir="rtl"] .toolbar-search input,
[dir="rtl"] .client-picker input {
  padding-left: 0.85rem;
  padding-right: 2.4rem;
}
[dir="rtl"] .user-chip {
  padding: 0.25rem 0.75rem 0.25rem 0.35rem;
}
[dir="rtl"] .chip {
  padding: 0.45rem 0.85rem 0.45rem 0.4rem;
}
[dir="rtl"] .lang-select {
  padding: 0.45rem 0.65rem 0.45rem 1.75rem;
  background-position: left 0.5rem center;
}
[dir="rtl"] .toast-host {
  right: auto;
  left: 1rem;
}
[dir="rtl"] .auth-toolbar {
  right: auto;
  left: 1rem;
}
@media (max-width: 860px) {
  [dir="rtl"] .sidebar {
    left: auto;
    right: 0;
    transform: translateX(105%);
  }
  [dir="rtl"] .sidebar.is-open {
    transform: none;
  }
}
