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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; }

/* ── Auth layout ── */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 40px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--color-text);
}

.auth-card .subtitle {
  color: var(--color-muted);
  margin-bottom: 28px;
  font-size: 13px;
}

/* ── App layout: sidebar + main ── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition);
  z-index: 100;
}

.sidebar-logo {
  padding: 16px 16px 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-logo span.logo-icon {
  font-size: 20px;
  margin-right: 8px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-nav a, .sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--color-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: 0;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav a:hover, .sidebar-nav .nav-item:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.sidebar-nav a.router-link-active, .sidebar-nav a.active, .sidebar-nav .nav-item.active {
  background: rgba(59,130,246,0.15);
  color: var(--color-accent);
}

.sidebar-nav .nav-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-nav .nav-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-nav-bottom {
  border-top: 1px solid var(--color-border);
  padding: 8px 0 16px;
}

.sidebar-nav-bottom a, .sidebar-nav-bottom .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--color-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: 0;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav-bottom a:hover, .sidebar-nav-bottom .nav-item:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.sidebar-nav-bottom a.router-link-active, .sidebar-nav-bottom a.active, .sidebar-nav-bottom .nav-item.active {
  background: rgba(59,130,246,0.15);
  color: var(--color-accent);
}

.sidebar-nav-bottom .nav-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-user {
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  overflow: hidden;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--color-muted);
}

.sidebar-logout {
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 16px;
  display: flex;
  align-items: center;
  transition: color var(--transition);
}

.sidebar-logout:hover { color: var(--color-danger); }

/* ── Nav tree (Диалоги) ── */
.nav-tree-root-row {
  cursor: pointer;
}

.nav-tree-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-tree-chevron {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--color-border-light);
  transition: transform 0.18s;
  line-height: 1;
  padding: 0 2px;
  user-select: none;
}

.nav-tree-chevron.open {
  transform: rotate(180deg);
}

.nav-tree-children {
  /* no extra wrapper padding — each child handles its own indent */
}

.nav-tree-platform {
  padding-left: 28px;
  padding-top: 7px;
  padding-bottom: 7px;
  gap: 8px;
  cursor: pointer;
}

.nav-tree-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-muted);
}

.nav-tree-account {
  padding-left: 40px;
  padding-top: 5px;
  padding-bottom: 5px;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
}

.nav-tree-dash {
  flex-shrink: 0;
  color: var(--color-border-light);
  font-size: 12px;
  line-height: 1;
  width: 10px;
  text-align: center;
}

/* ── Main content area ── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Stats bar ── */
.statsbar {
  height: var(--statsbar-height);
  min-height: var(--statsbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  overflow-x: auto;
  flex-shrink: 0;
}

/* ── Page wrapper (scrollable area below statsbar) ── */
.page-wrapper {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Dashboard split layout ── */
.dashboard-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.conversation-list-panel {
  width: 420px;
  min-width: 320px;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

.conv-list-resize-handle {
  position: absolute;
  top: 0;
  right: -2px;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
  background: transparent;
  transition: background 0.15s;
}

.conv-list-resize-handle:hover,
.conv-list-resize-handle.dragging {
  background: var(--color-accent);
  opacity: 0.4;
}

.conversation-detail-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Conversation detail inner (main + sidebar) ── */
.conv-detail-inner {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.conv-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.conv-sidebar {
  width: 300px;
  min-width: 260px;
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  gap: 0;
  background: var(--color-bg);
}

.sidebar-section {
  border-bottom: 1px solid var(--color-border);
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
  min-height: 36px;
}

.sidebar-section-header:hover {
  background: var(--color-surface-2);
}

.sidebar-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--color-muted);
}

.sidebar-chevron {
  font-size: 11px;
  color: var(--color-border-light);
  transition: transform 0.2s;
  line-height: 1;
  flex-shrink: 0;
}

.sidebar-chevron.open {
  transform: rotate(180deg);
}

.sidebar-section-body {
  padding: 2px 12px 10px;
}

.sidebar-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 6px;
}

.sidebar-row:last-child { margin-bottom: 0; }

.sidebar-label {
  font-size: 10px;
  color: var(--color-muted);
  margin-bottom: 1px;
}

.sidebar-value {
  font-size: 12px;
  color: var(--color-text);
  word-break: break-word;
  line-height: 1.4;
}

.sidebar-value.mono {
  font-family: monospace;
  font-size: 11px;
  color: var(--color-muted);
}

/* Attribute tags */
.attr-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.attr-tag {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  color: var(--color-text);
  line-height: 1.4;
}

/* Attachment thumbnails */
.att-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.att-thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  cursor: zoom-in;
  transition: opacity 0.15s;
}

.att-thumb:hover { opacity: 0.85; }

.att-file {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  text-decoration: none;
  color: var(--color-text);
  max-width: 100%;
}

.att-file:hover { background: var(--color-surface); }

/* Image lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
}

.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 4px;
  object-fit: contain;
}

/* ── Page content (non-dashboard) ── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-border-light); }
