:root {
  --bg: #080b10;
  --bg-elevated: #0e1219;
  --surface: #151b26;
  --surface-glass: rgba(21, 27, 38, 0.72);
  --surface-highlight: #1c2433;
  --border: rgba(126, 182, 255, 0.12);
  --border-strong: rgba(126, 182, 255, 0.22);
  --text: #f4f7fc;
  --muted: #8b9bb5;
  --primary: #7eb6ff;
  --primary-glow: rgba(126, 182, 255, 0.35);
  --primary-dim: #5a8fcc;
  --accent-soft: #3d5a80;
  --danger: #ff8a8a;
  --success: #5fd4a4;
  --warning: #f5c26b;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 40px rgba(126, 182, 255, 0.08);
  --sidebar-w: 268px;
  --font-ui: "DM Sans", system-ui, sans-serif;
  --font-brand: "Syne", system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; }

/* ── Ambient background ── */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: float 18s var(--ease) infinite alternate;
}

.orb-a {
  width: 520px;
  height: 520px;
  top: -180px;
  left: -120px;
  background: radial-gradient(circle, #1a2840 0%, transparent 70%);
}

.orb-b {
  width: 400px;
  height: 400px;
  bottom: -100px;
  right: 10%;
  background: radial-gradient(circle, rgba(61, 90, 128, 0.6) 0%, transparent 70%);
  animation-delay: -6s;
}

.orb-c {
  width: 280px;
  height: 280px;
  top: 40%;
  right: -80px;
  background: radial-gradient(circle, rgba(126, 182, 255, 0.15) 0%, transparent 70%);
  animation-delay: -12s;
}

@keyframes float {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(24px, -18px) scale(1.06); }
}

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Shell layout ── */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface-glass);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-right: 1px solid var(--border);
  padding: 28px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 10px 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent-soft) 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px var(--primary-glow);
  flex-shrink: 0;
}

.brand-mark svg { width: 22px; height: 22px; }

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand {
  font-family: var(--font-brand);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--text);
  line-height: 1;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav-section {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 12px 8px;
  opacity: 0.7;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  width: 100%;
  font-weight: 500;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity 0.2s;
}

.nav-btn:hover {
  background: rgba(126, 182, 255, 0.06);
  color: var(--text);
  border-color: var(--border);
}

.nav-btn:hover svg { opacity: 1; }

.nav-btn.active {
  background: linear-gradient(90deg, rgba(126, 182, 255, 0.14) 0%, rgba(126, 182, 255, 0.04) 100%);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: inset 3px 0 0 var(--primary);
}

.nav-btn.active svg { opacity: 1; color: var(--primary); }

.nav-btn { position: relative; }
.nav-badge {
  position: absolute;
  top: 6px;
  right: 8px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  line-height: 18px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-soft), var(--primary-dim));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
  flex-shrink: 0;
  overflow: hidden;
}

.user-avatar-emoji { font-size: 1.25rem; background: var(--surface-elevated); }
.user-avatar-img img,
.user-avatar img,
.chat-avatar-img img,
.avatar-preview-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.user-meta { min-width: 0; }

.user-email {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.72rem;
  color: var(--muted);
}

.btn-logout {
  width: 100%;
  justify-content: center;
}

/* ── Main content ── */
.main {
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: clamp(24px, 2.5vw, 44px) clamp(20px, 3vw, 56px) clamp(40px, 4vw, 72px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.main,
.scroll-area,
.preview-body,
.doc-tiles-scroll,
.table-wrap {
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 182, 255, 0.62) rgba(255, 255, 255, 0.08);
}

.main::-webkit-scrollbar,
.scroll-area::-webkit-scrollbar,
.preview-body::-webkit-scrollbar,
.doc-tiles-scroll::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.main::-webkit-scrollbar-track,
.scroll-area::-webkit-scrollbar-track,
.preview-body::-webkit-scrollbar-track,
.doc-tiles-scroll::-webkit-scrollbar-track,
.table-wrap::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
}

.main::-webkit-scrollbar-thumb,
.scroll-area::-webkit-scrollbar-thumb,
.preview-body::-webkit-scrollbar-thumb,
.doc-tiles-scroll::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: rgba(126, 182, 255, 0.5);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
  min-height: 48px;
}

.main::-webkit-scrollbar-thumb:hover,
.scroll-area::-webkit-scrollbar-thumb:hover,
.preview-body::-webkit-scrollbar-thumb:hover,
.doc-tiles-scroll::-webkit-scrollbar-thumb:hover,
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(126, 182, 255, 0.78);
  background-clip: padding-box;
}

.main::-webkit-scrollbar-corner,
.scroll-area::-webkit-scrollbar-corner,
.preview-body::-webkit-scrollbar-corner,
.doc-tiles-scroll::-webkit-scrollbar-corner,
.table-wrap::-webkit-scrollbar-corner {
  background: transparent;
}

.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  margin: 0 0 6px;
  font-family: var(--font-brand);
  font-size: clamp(1.6rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-header .lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 20px;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
}

.muted { color: var(--muted); }

/* ── Cards ── */
.card {
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow), var(--shadow-glow);
}

.card-glow {
  position: relative;
  overflow: hidden;
}

.card-glow::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(126, 182, 255, 0.35), transparent 40%, transparent 60%, rgba(126, 182, 255, 0.15));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.welcome-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 28px;
  padding: 24px 28px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(26, 40, 64, 0.8) 0%, rgba(14, 18, 25, 0.9) 100%);
  border: 1px solid var(--border-strong);
}

.welcome-banner h2 {
  margin: 0 0 4px;
  font-family: var(--font-brand);
  font-size: 1.35rem;
}

.welcome-banner p { margin: 0; color: var(--muted); }

.welcome-time {
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(126, 182, 255, 0.1);
  border: 1px solid var(--border);
}

/* ── Stats grid ── */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: clamp(14px, 1.5vw, 22px); }

@media (min-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1600px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: transform 0.25s var(--ease), border-color 0.25s;
  overflow: hidden;
}

.stat::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), transparent);
  opacity: 0.6;
}

.stat:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(126, 182, 255, 0.1);
  border: 1px solid var(--border);
}

.stat-icon svg { width: 20px; height: 20px; color: var(--primary); }

.stat .value {
  font-family: var(--font-brand);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.03em;
}

.stat .label {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 6px;
  font-weight: 500;
}

.section-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 28px 0 14px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}

.btn svg { width: 18px; height: 18px; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dim) 100%);
  color: #061018;
  box-shadow: 0 4px 20px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 28px var(--primary-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  background: rgba(126, 182, 255, 0.08);
}

.btn-danger {
  background: rgba(255, 138, 138, 0.12);
  color: var(--danger);
  border: 1px solid rgba(255, 138, 138, 0.3);
}

.btn-danger:hover { background: rgba(255, 138, 138, 0.2); }

.btn-sm { padding: 7px 12px; font-size: 0.82rem; }
.btn-sm svg { width: 15px; height: 15px; }

.btn-block { width: 100%; }

/* ── Forms ── */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.field input,
.field select,
.field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(126, 182, 255, 0.15);
}

.field-check {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  cursor: pointer;
  font-size: 0.9rem;
}

.field-check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ── Login ── */
.login-wrap {
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 24px;
  overflow-y: auto;
}

.login-card {
  width: min(440px, 100%);
  animation: rise 0.6s var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-hero {
  text-align: center;
  margin-bottom: 28px;
}

.login-hero .brand-mark {
  margin: 0 auto 18px;
  width: 56px;
  height: 56px;
  border-radius: 18px;
}

.login-hero .brand {
  font-size: 1.75rem;
  display: block;
  margin-bottom: 8px;
}

.login-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ── Tables ── */
.table-wrap { overflow: auto; margin: -4px; padding: 4px; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  padding: 8px 14px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: none;
}

tbody tr {
  transition: transform 0.15s var(--ease);
}

tbody td {
  padding: 14px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

tbody td:first-child {
  border-left: 1px solid var(--border);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

tbody td:last-child {
  border-right: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

tbody tr:hover td {
  background: rgba(126, 182, 255, 0.05);
  border-color: var(--border-strong);
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-admin { background: rgba(126, 182, 255, 0.15); color: var(--primary); border: 1px solid rgba(126, 182, 255, 0.25); }
.badge-manager { background: rgba(95, 212, 164, 0.12); color: var(--success); border: 1px solid rgba(95, 212, 164, 0.25); }
.badge-user { background: rgba(139, 155, 181, 0.12); color: var(--muted); border: 1px solid var(--border); }
.badge-inactive { background: rgba(255, 138, 138, 0.12); color: var(--danger); border: 1px solid rgba(255, 138, 138, 0.25); }
.badge-pinned { background: rgba(245, 194, 107, 0.12); color: var(--warning); border: 1px solid rgba(245, 194, 107, 0.25); }

/* ── Alerts ── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 0.9rem;
  animation: rise 0.4s var(--ease) both;
}

.alert svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }

.alert-error {
  background: rgba(255, 138, 138, 0.1);
  border: 1px solid rgba(255, 138, 138, 0.3);
  color: #ffc9c9;
}

.alert-info {
  background: rgba(126, 182, 255, 0.1);
  border: 1px solid rgba(126, 182, 255, 0.28);
  color: #c5e0ff;
}

/* ── Toolbar & tabs ── */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toolbar select,
.toolbar input[type="text"],
.toolbar input:not([type]) {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  min-width: 0;
}

.toolbar select:focus,
.toolbar input:focus {
  outline: none;
  border-color: var(--primary);
}

.tab-pills {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.tab-pill {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 0.2s var(--ease);
}

.tab-pill:hover { color: var(--text); }

.tab-pill.active {
  background: rgba(126, 182, 255, 0.15);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 100;
  animation: fadeIn 0.2s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: min(580px, 100%);
  max-height: 90vh;
  overflow: auto;
  animation: rise 0.3s var(--ease) both;
}

.modal h2 {
  font-family: var(--font-brand);
  font-size: 1.2rem;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.upload-progress {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0 8px;
}

.upload-progress-name {
  font-weight: 600;
  word-break: break-word;
}

.upload-progress-meta {
  font-size: 0.9rem;
}

.upload-progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-variant, rgba(255, 255, 255, 0.08));
  overflow: hidden;
  border: 1px solid var(--border);
}

.upload-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #5ec8ff);
  transition: width 0.15s ease;
}

.upload-progress-track.is-indeterminate {
  position: relative;
  overflow: hidden;
}

.upload-progress-track.is-indeterminate .upload-progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  width: 40%;
  transition: none;
  animation: upload-indeterminate 1.1s ease-in-out infinite;
}

@keyframes upload-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}

.upload-progress-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.upload-progress-label {
  font-size: 0.92rem;
  color: var(--muted);
}

.upload-progress-percent {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--primary);
  min-width: 3ch;
  text-align: right;
}

/* ── Utilities ── */
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hidden { display: none !important; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.loading-pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: pulse 1.2s ease infinite;
  margin-right: 8px;
  vertical-align: middle;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

.doc-title-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

/* ── Kafelki gazetek z podglądem ── */
.doc-tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: clamp(16px, 1.6vw, 24px);
}

@media (min-width: 1600px) {
  .doc-tiles-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
}

@media (min-width: 2200px) {
  .doc-tiles-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
}

.doc-tiles-scroll {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable;
}

.doc-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.doc-tile:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-glow);
}

@media (hover: hover) and (pointer: fine) {
  .doc-tile:hover { transform: translateY(-2px); }
  .doc-tile { transition: border-color 0.2s var(--ease), transform 0.2s var(--ease), box-shadow 0.2s var(--ease); }
}

.doc-tiles-scroll .doc-tile {
  flex: 0 0 200px;
  scroll-snap-align: start;
}

.doc-tile-preview {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--bg);
  overflow: hidden;
  cursor: pointer;
}

.doc-tile-preview img,
.doc-tile-preview canvas,
.doc-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}

.doc-thumb-skeleton {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--surface-highlight) 0%,
    rgba(126, 182, 255, 0.08) 50%,
    var(--surface-highlight) 100%
  );
  background-size: 200% 100%;
  animation: thumb-shimmer 1.4s ease-in-out infinite;
}

@keyframes thumb-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.doc-thumb-loading,
.doc-thumb-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: linear-gradient(160deg, var(--surface-highlight) 0%, var(--bg) 100%);
}

.doc-thumb-fallback svg {
  width: 48px;
  height: 48px;
  opacity: 0.45;
}

.doc-tile-pin {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(245, 194, 107, 0.92);
  color: #1a1408;
}

.doc-fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 255, 255, 0.7);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}
.doc-fav-btn.active { color: #fbbf24; }
.doc-fav-btn:hover { background: rgba(0, 0, 0, 0.6); color: #fde68a; }

.doc-tile-body {
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  width: 100%;
  min-width: 0;
}

.doc-tile-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
  width: 100%;
  min-width: 0;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: keep-all;
  overflow-wrap: normal;
}

.doc-tile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 0.78rem;
  line-height: 1.4;
  width: 100%;
  min-width: 0;
}

.doc-tile-meta .badge,
.doc-tile-meta .muted {
  white-space: nowrap;
  max-width: 100%;
}

.doc-tile-meta .muted {
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-tile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

.doc-tile-compact .doc-tile-body {
  padding: 10px 12px 12px;
}

.doc-tile-compact .doc-tile-title {
  font-size: 0.82rem;
}

.doc-tile-compact .doc-tile-preview {
  aspect-ratio: 4 / 5;
}

/* ── Podgląd gazetki (modal) ── */
.preview-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 8, 14, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.18s ease both;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-glass);
  flex-shrink: 0;
}

.preview-toolbar h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: #0a0e14;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.preview-body iframe {
  width: 100%;
  height: 100%;
  min-height: 60vh;
  border: none;
  display: block;
  background: #111;
}

.preview-page-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: min-content;
  padding: 12px 0 24px;
  background: #0a0e14;
}

.preview-image-wrap,
.pdf-preview-page-wrap {
  display: block;
  line-height: 0;
  font-size: 0;
  background: #fff;
  max-width: 100%;
}

.preview-body .preview-image {
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0;
  display: block;
  object-fit: contain;
  background: #fff;
}

.pdf-preview-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 12px 0 24px;
  width: 100%;
  min-height: min-content;
  line-height: 0;
  font-size: 0;
  background: #0a0e14;
}

.pdf-preview-page,
canvas.pdf-preview-page {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #fff;
  vertical-align: top;
  image-rendering: auto;
}

.preview-loading {
  margin: auto;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-opening .doc-tile-preview {
  opacity: 0.7;
  pointer-events: none;
}

body.preview-open {
  overflow: hidden;
}

body.preview-open .main {
  overflow: hidden;
}

/* ── Responsive ── */
@media (max-width: 960px) {
  body { overflow: auto; height: auto; min-height: 100%; }
  #app { height: auto; min-height: 100vh; min-height: 100dvh; }
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 16px;
    gap: 4px;
  }

  .brand-block {
    width: 100%;
    padding-bottom: 12px;
  }

  .nav-section { display: none; }

  .nav-btn {
    width: auto;
    flex: 1;
    min-width: 120px;
    justify-content: center;
    padding: 10px 12px;
  }

  .nav-btn span.label { display: none; }

  .sidebar-footer {
    width: 100%;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
  }

  .user-chip { flex: 1; margin-bottom: 0; min-width: 200px; }
  .btn-logout { width: auto; }

  .main {
    height: auto;
    overflow: visible;
    padding: 20px 18px 40px;
  }
}

@media (max-width: 600px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; }
  .welcome-banner { flex-direction: column; align-items: flex-start; }
}

/* ── Start screen (jak aplikacja) ── */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--border);
  margin-top: 12px;
}

.status-chip.online {
  background: rgba(95, 212, 164, 0.1);
  border-color: rgba(95, 212, 164, 0.3);
  color: var(--success);
}

.status-chip.offline {
  background: rgba(255, 138, 138, 0.1);
  border-color: rgba(255, 138, 138, 0.3);
  color: var(--danger);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.action-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  text-align: left;
  width: 100%;
  color: inherit;
}

.action-card:hover {
  border-color: var(--border-strong);
  background: rgba(126, 182, 255, 0.06);
  transform: translateX(4px);
}

.action-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(126, 182, 255, 0.12);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.action-card-icon svg { width: 22px; height: 22px; color: var(--primary); }

.action-card-body { flex: 1; min-width: 0; }

.action-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 2px;
}

.action-card-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

.action-card-arrow {
  color: var(--muted);
  flex-shrink: 0;
}

.action-card-arrow svg { width: 20px; height: 20px; }

.doc-list { display: flex; flex-direction: column; gap: 8px; }

.doc-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.2s;
}

.doc-list-item:hover { border-color: var(--border-strong); }

.doc-list-item strong { font-weight: 600; font-size: 0.9rem; }

/* ── Kalendarz gazetek ── */
.calendar-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: clamp(18px, 2vw, 28px);
  align-items: start;
}

@media (min-width: 1400px) {
  .calendar-layout { grid-template-columns: minmax(0, 1fr) minmax(380px, 28vw); }
}

@media (max-width: 900px) {
  .calendar-layout { grid-template-columns: 1fr; }
}

.calendar-card { padding: 20px; }

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.calendar-nav h3 {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.1rem;
  font-weight: 600;
}

.calendar-nav-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.2s;
}

.calendar-nav-btn:hover {
  border-color: var(--primary);
  background: rgba(126, 182, 255, 0.1);
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.calendar-weekday {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  padding: 4px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: clamp(4px, 0.5vw, 8px);
}

.calendar-day {
  aspect-ratio: 1;
  min-height: clamp(44px, 5vw, 72px);
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 6px 4px 5px;
  position: relative;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.15s;
  overflow: hidden;
}

.calendar-day.empty {
  pointer-events: none;
  background: transparent;
  border-color: transparent;
}

.cal-day-num {
  font-size: clamp(0.82rem, 1.1vw, 0.95rem);
  font-weight: 600;
  line-height: 1;
  z-index: 1;
}

.cal-gazetka-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px 2px 4px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(126, 182, 255, 0.95), #5ec8ff);
  color: #061018;
  box-shadow: 0 2px 10px rgba(126, 182, 255, 0.35);
  z-index: 1;
}

.cal-gazetka-chip svg {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
}

.cal-gazetka-count {
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.calendar-day.has-gazetka::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 1;
  pointer-events: none;
}

.calendar-day.has-gazetka.tier-low::before {
  background: linear-gradient(160deg, rgba(126, 182, 255, 0.2), rgba(126, 182, 255, 0.04));
}

.calendar-day.has-gazetka.tier-mid::before {
  background: linear-gradient(160deg, rgba(126, 182, 255, 0.28), rgba(94, 200, 255, 0.08));
}

.calendar-day.has-gazetka.tier-high::before {
  background: linear-gradient(160deg, rgba(126, 182, 255, 0.38), rgba(94, 200, 255, 0.12));
}

.calendar-day.has-gazetka::after {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, var(--primary), #5ec8ff);
  box-shadow: 0 0 12px rgba(126, 182, 255, 0.45);
}

.calendar-day.has-gazetka.tier-mid::after { width: 4px; }
.calendar-day.has-gazetka.tier-high::after { width: 5px; }

.calendar-day.has-gazetka {
  border-color: rgba(126, 182, 255, 0.28);
  color: var(--text);
}

.calendar-day.has-gazetka .cal-day-num { font-weight: 800; }

.calendar-day:hover:not(.empty) {
  background: rgba(126, 182, 255, 0.1);
  color: var(--text);
  transform: translateY(-1px);
}

.calendar-day.today {
  border-color: var(--border-strong);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(126, 182, 255, 0.15);
}

.calendar-day.selected {
  background: rgba(126, 182, 255, 0.22);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(126, 182, 255, 0.35), 0 8px 24px rgba(126, 182, 255, 0.12);
  color: var(--text);
  font-weight: 700;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.calendar-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.cal-gazetka-chip--legend {
  pointer-events: none;
}

.calendar-legend-swatch {
  width: 30px;
  height: 22px;
  border-radius: 8px;
  border: 1px solid rgba(126, 182, 255, 0.28);
  position: relative;
  overflow: hidden;
}

.calendar-legend-swatch.tier-mid {
  background: linear-gradient(160deg, rgba(126, 182, 255, 0.28), rgba(94, 200, 255, 0.08));
}

.calendar-legend-swatch.tier-high {
  background: linear-gradient(160deg, rgba(126, 182, 255, 0.38), rgba(94, 200, 255, 0.12));
}

.calendar-legend-swatch::after {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  bottom: 5px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, var(--primary), #5ec8ff);
}

.calendar-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100dvh - 80px);
  position: sticky;
  top: clamp(20px, 2.5vw, 36px);
  align-self: start;
}

.calendar-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.calendar-side-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(126, 182, 255, 0.12);
  border: 1px solid rgba(126, 182, 255, 0.28);
  color: var(--primary);
  white-space: nowrap;
}

.calendar-side-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  margin-top: 12px;
  padding-right: 2px;
}

.calendar-side-scroll.is-multi {
  max-height: min(58vh, 640px);
}

.calendar-side-tiles {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.calendar-side-tiles.is-multi .doc-tile {
  flex-shrink: 0;
}

.calendar-side-tiles.is-multi .doc-tile-preview {
  aspect-ratio: 4 / 5;
  max-height: 210px;
}

.calendar-side-tiles.is-multi .doc-tile-title {
  white-space: nowrap;
}

.calendar-side-hint {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--muted);
}

.calendar-side h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.calendar-side .date-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0;
}

.calendar-side-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calendar-side-section-title {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary);
}

.calendar-entry-card {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(126, 182, 255, 0.22);
  background: rgba(126, 182, 255, 0.08);
  margin-bottom: 8px;
}

.calendar-entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.calendar-entry-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.calendar-entry-desc {
  margin-top: 4px;
  font-size: 0.82rem;
}

.calendar-entry-type {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.calendar-entry-title {
  margin: 0 0 4px;
  font-size: 0.9rem;
  font-weight: 600;
}

.calendar-side-entries {
  margin-bottom: 4px;
}

@media (max-width: 900px) {
  .calendar-side {
    max-height: none;
    position: static;
  }

  .calendar-side-scroll.is-multi {
    max-height: min(52vh, 480px);
  }
}

.gazetka-card {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.gazetka-card:hover { border-color: var(--primary); }

.gazetka-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.gazetka-card-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

/* ── Ustawienia ── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
}

.settings-panel { padding: 22px; }

.settings-panel h3 {
  margin: 0 0 16px;
  font-size: 1rem;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.info-row:last-child { border-bottom: none; }

.info-row span:first-child { color: var(--muted); }

.qr-box {
  padding: 16px;
  background: #fff;
  border-radius: var(--radius-sm);
  text-align: center;
  margin: 12px 0;
}

.qr-box img { max-width: 180px; }

.secret-code {
  font-family: monospace;
  font-size: 0.85rem;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.chat-inbox { display: flex; flex-direction: column; gap: 8px; }
.chat-conv-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; cursor: pointer; color: inherit;
}
.chat-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%;
  font-weight: 700; font-size: 0.85rem; color: #fff; flex-shrink: 0;
}
.chat-avatar-admin { background: #7c5cff; }
.chat-avatar-manager { background: #2db87c; }
.chat-avatar-user { background: #38bdf8; }
.chat-avatar-group { background: linear-gradient(135deg, #6366f1, #8b5cf6); font-weight: 700; }
.chat-new-actions { display: flex; flex-wrap: wrap; gap: 12px; padding: 16px 0; }
.chat-group-form { padding: 16px; }
.chat-group-members { display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow: auto; }
.chat-group-member { display: flex; align-items: center; gap: 10px; }
.chat-group-member-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.chat-group-subtitle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  color: var(--muted);
  font: inherit;
}
.chat-group-subtitle-btn:hover .chat-group-subtitle-action { color: var(--accent); }
.chat-group-subtitle-action { color: var(--accent); font-weight: 600; }
.chat-group-hint {
  margin: -8px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(95, 212, 164, 0.08);
  border: 1px solid rgba(95, 212, 164, 0.2);
  font-size: 0.9rem;
}
.chat-thread-header { display: flex; align-items: center; gap: 12px; }
.chat-bubble-row { display: flex; align-items: flex-end; gap: 8px; max-width: 92%; }
.chat-row-in { align-self: flex-start; }
.chat-row-out { align-self: flex-end; margin-left: auto; flex-direction: row-reverse; }
.chat-preview { margin: 6px 0 0; font-size: 0.85rem; color: var(--muted); }
.chat-thread {
  max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
  padding: 12px; background: var(--surface); border-radius: 12px; border: 1px solid var(--border);
}
.chat-bubble { max-width: 85%; padding: 10px 14px; border-radius: 14px; font-size: 0.92rem; }
.chat-in { align-self: flex-start; background: var(--surface-elevated); }
.chat-out { align-self: flex-end; background: rgba(56, 189, 248, 0.15); }
.chat-compose { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; flex-wrap: wrap; }
.chat-compose textarea { flex: 1; resize: vertical; min-height: 56px; }
.btn-chat-new {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  color: #041018; border: none; font-weight: 700;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35), 0 8px 24px rgba(14, 165, 233, 0.25);
}
.btn-chat-new:hover { filter: brightness(1.08); }
.btn-chat-new-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(4, 16, 24, 0.12); font-size: 1.1rem; line-height: 1;
}
.chat-avatar-emoji { font-size: 1.35rem; background: var(--surface-elevated); color: inherit; }
.chat-avatar-img { overflow: hidden; background: var(--surface-elevated); color: var(--muted); }
.chat-bubble-wrap { display: flex; flex-direction: column; gap: 4px; max-width: 85%; }
.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.chat-reaction-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 0.85rem; cursor: pointer; color: inherit;
}
.chat-reaction-pill.chat-reaction-mine { border-color: var(--primary); background: rgba(56,189,248,0.12); }
.chat-reaction-count { font-size: 0.72rem; color: var(--muted); }
.chat-reaction-picker, .chat-action-menu {
  position: fixed; z-index: 10050;
  display: flex; gap: 4px; padding: 8px;
  background: var(--surface-elevated); border: 1px solid var(--border);
  border-radius: 999px; box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}
.chat-action-menu { flex-direction: column; border-radius: 12px; min-width: 160px; }
.chat-action-menu button {
  text-align: left; padding: 10px 14px; border: none; background: none;
  color: inherit; cursor: pointer; border-radius: 8px; font-size: 0.9rem;
}
.chat-action-menu button:hover { background: rgba(255,255,255,0.06); }
.chat-action-menu button.danger { color: #f87171; }
.chat-reaction-opt {
  width: 36px; height: 36px; border: none; background: none;
  font-size: 1.35rem; cursor: pointer; border-radius: 50%;
}
.chat-reaction-opt:hover { background: rgba(255,255,255,0.08); }
.avatar-settings { max-width: 360px; }
.avatar-current { margin-bottom: 12px; }
.avatar-preview {
  display: inline-flex; align-items: center; justify-content: center;
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-soft), var(--primary-dim));
  font-weight: 700; font-size: 1.5rem;
}
.avatar-preview-emoji { font-size: 2rem; background: var(--surface-elevated); }
.avatar-preview-img { overflow: hidden; }
.avatar-emoji-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-emoji-btn {
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 1.35rem; cursor: pointer;
}
.avatar-emoji-btn.active, .avatar-emoji-btn:hover { border-color: var(--primary); background: rgba(56,189,248,0.1); }
.settings-grid { display: grid; gap: 16px; }
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
}

.chat-brief-compose-btn { flex-shrink: 0; white-space: nowrap; }
.chat-brief-modal { width: min(520px, 94vw); max-height: 90vh; overflow: auto; }
.chat-bubble-brief { max-width: min(520px, 92vw); }
.chat-brief-card { display: grid; gap: 8px; }
.chat-brief-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.chat-brief-kind {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--primary);
}
.chat-brief-status {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
}
.chat-brief-status-open { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.chat-brief-status-progress { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.chat-brief-status-done { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.chat-brief-status-rejected { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.chat-brief-title { font-weight: 700; font-size: 1.05rem; line-height: 1.35; }
.chat-brief-deadline { font-size: 12px; color: var(--muted); }
.chat-brief-body {
  white-space: pre-wrap; line-height: 1.45; font-size: 13px;
  padding-top: 6px; border-top: 1px solid var(--border);
}
.chat-brief-admin { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.chat-brief-admin-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.chat-brief-admin-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat-brief-status-select {
  flex: 1; min-width: 140px; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

.docs-summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.docs-summary-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.docs-summary-chip:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.docs-summary-chip strong {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.docs-summary-chip.alert-chip {
  border-color: rgba(126, 182, 255, 0.45);
  background: rgba(126, 182, 255, 0.08);
}

.briefs-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.briefs-filters .btn.active {
  border-color: var(--primary);
  color: var(--primary);
}

.brief-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.brief-row:last-child { border-bottom: none; }

.brief-row-main { flex: 1; min-width: 0; }

.brief-row-title {
  font-weight: 600;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.assistant-page textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.orders-table { padding: 0; overflow: hidden; }

.order-row {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.order-row:last-child { border-bottom: none; }

.order-row-main { flex: 1; min-width: 0; }

.order-row-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.order-kind-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(126, 182, 255, 0.15);
  color: #7eb6ff;
}

.order-status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.order-status-open { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.order-status-progress { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.order-status-done { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.order-status-rejected { background: rgba(239, 68, 68, 0.15); color: #f87171; }

.order-row-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 700;
}

.order-row-meta { margin: 0 0 8px; font-size: 13px; }

.order-row-desc {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  overflow: hidden;
  display: block;
  max-height: calc(1.45em * 2);
}

.order-row-doc { font-size: 13px; }

.order-doc-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.order-row-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  min-width: 140px;
}

.order-inline-status {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.order-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.order-detail-body {
  white-space: pre-wrap;
  line-height: 1.5;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

