@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --app-bg: #f5f7fb;
  --app-surface: #ffffff;
  --app-border: #e6e9f0;
  --app-text: #1f2937;
  --app-muted: #6b7280;
  --app-primary: #4f46e5;
  --app-primary-700: #4338ca;
  --app-topbar-bg: rgba(255, 255, 255, 0.8);
  --app-footer-bg: rgba(255, 255, 255, 0.6);
  --chat-sidebar-width: 320px;
  --chat-header-height: 70px;
  --chat-footer-height: 80px;
  --sidebar-width: 270px;
  --topbar-height: 64px;
  --radius: 12px;
}

:root[data-theme="dark"],
body[data-theme="dark"] {
  color-scheme: dark;
  --app-bg: #0b1220;
  --app-surface: #0f172a;
  --app-border: rgba(255, 255, 255, 0.08);
  --app-text: #e5e7eb;
  --app-muted: #94a3b8;
  --app-primary: #6366f1;
  --app-primary-700: #4f46e5;
  --app-topbar-bg: rgba(15, 23, 42, 0.72);
  --app-footer-bg: rgba(15, 23, 42, 0.6);
}

:root[data-theme="dark"] a,
body[data-theme="dark"] a {
  color: #a5b4fc;
}

:root[data-theme="dark"] a:hover,
body[data-theme="dark"] a:hover {
  color: #c7d2fe;
}

:root[data-theme="dark"] .bg-light,
:root[data-theme="dark"] .table-light,
:root[data-theme="dark"] thead.bg-light,
:root[data-theme="dark"] .modal-footer.bg-light,
:root[data-theme="dark"] .card.bg-light,
:root[data-theme="dark"] .border-0.bg-light,
body[data-theme="dark"] .bg-light,
body[data-theme="dark"] .table-light,
body[data-theme="dark"] thead.bg-light,
body[data-theme="dark"] .modal-footer.bg-light,
body[data-theme="dark"] .card.bg-light,
body[data-theme="dark"] .border-0.bg-light {
  background-color: rgba(255, 255, 255, 0.05) !important;
  color: var(--app-text) !important;
}

:root[data-theme="dark"] .text-dark,
body[data-theme="dark"] .text-dark {
  color: var(--app-text) !important;
}

:root[data-theme="dark"] .text-muted,
body[data-theme="dark"] .text-muted {
  color: var(--app-muted) !important;
}

:root[data-theme="dark"] .btn-light,
body[data-theme="dark"] .btn-light {
  background-color: rgba(255, 255, 255, 0.06) !important;
  border-color: var(--app-border) !important;
  color: var(--app-text) !important;
}

:root[data-theme="dark"] .btn-light:hover,
body[data-theme="dark"] .btn-light:hover {
  background-color: rgba(255, 255, 255, 0.10) !important;
}

:root[data-theme="dark"] .dropdown-divider,
body[data-theme="dark"] .dropdown-divider {
  border-top-color: var(--app-border);
}

:root[data-theme="dark"] .badge.bg-warning.text-dark,
:root[data-theme="dark"] .badge.bg-info.text-dark,
:root[data-theme="dark"] .badge.bg-light.text-dark,
body[data-theme="dark"] .badge.bg-warning.text-dark,
body[data-theme="dark"] .badge.bg-info.text-dark,
body[data-theme="dark"] .badge.bg-light.text-dark {
  color: #0b1220 !important;
}

:root[data-theme="dark"] .table,
body[data-theme="dark"] .table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--app-text);
  --bs-table-border-color: var(--app-border);
}

:root[data-theme="dark"] .table > :not(caption) > * > *,
body[data-theme="dark"] .table > :not(caption) > * > * {
  background-color: transparent;
}

:root[data-theme="dark"] .modal-content,
body[data-theme="dark"] .modal-content {
  background: var(--app-surface);
  border-color: var(--app-border);
  color: var(--app-text);
}

:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select,
body[data-theme="dark"] .form-control,
body[data-theme="dark"] .form-select {
  background-color: rgba(255, 255, 255, 0.04);
  border-color: var(--app-border);
  color: var(--app-text);
}

:root[data-theme="dark"] .form-control::placeholder,
body[data-theme="dark"] .form-control::placeholder {
  color: rgba(229, 231, 235, 0.6);
}

:root[data-theme="dark"] .form-control:focus,
:root[data-theme="dark"] .form-select:focus,
body[data-theme="dark"] .form-control:focus,
body[data-theme="dark"] .form-select:focus {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: rgba(99, 102, 241, 0.6);
  box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.18);
}

:root[data-theme="dark"] .bg-white,
body[data-theme="dark"] .bg-white {
  background-color: rgba(255, 255, 255, 0.04) !important;
  color: var(--app-text) !important;
}

:root[data-theme="dark"] .list-group-item,
body[data-theme="dark"] .list-group-item {
  background: var(--app-surface);
  border-color: var(--app-border);
  color: var(--app-text);
}

:root[data-theme="dark"] .list-group-item-action:hover,
:root[data-theme="dark"] .list-group-item-action:focus,
body[data-theme="dark"] .list-group-item-action:hover,
body[data-theme="dark"] .list-group-item-action:focus {
  background: rgba(255, 255, 255, 0.06);
  color: var(--app-text);
}

html, body {
  height: 100%;
}

body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--app-bg);
  color: var(--app-text);
  font-size: 0.9rem;
  padding-top: 0;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-width);
  background: #0b1220;
  color: rgba(255, 255, 255, 0.85);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid rgb(0, 2, 110);
}

.app-sidebar .brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid rgb(7, 0, 112);
}

.app-sidebar .brand .brand-link {
  color: rgba(255,255,255,0.92);
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 1rem;
  width: 100%;
}

.app-sidebar .brand .brand-mini {
  display: none;
  font-weight: 900;
  letter-spacing: 0.12em;
}

body.sidebar-collapsed .app-sidebar .brand {
  justify-content: center;
  padding: 0 8px;
}

body.sidebar-collapsed .app-sidebar .brand .brand-full {
  display: none;
}

body.sidebar-collapsed .app-sidebar .brand .brand-mini {
  display: inline;
}

.sidebar-nav {
  padding: 12px 10px 18px;
}

.sidebar-section {
  margin-top: 14px;
  padding: 0 10px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin: 4px 6px;
  border-radius: 10px;
  color: rgba(255,255,255,0.86);
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
}

.sidebar-link:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.sidebar-link.active {
  background: rgba(79,70,229,0.25);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(79,70,229,0.35);
}

.sidebar-link i {
  font-size: 1.05rem;
  opacity: 0.95;
}

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

.app-topbar {
  height: var(--topbar-height);
  background: var(--app-topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--app-border);
  display: flex;
  align-items: center;
  padding: 0 18px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-weight: 700;
  font-size: 1rem;
  margin: 0;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-search {
  width: min(440px, 42vw);
}

.topbar-search .input-group-text {
  border-radius: 10px 0 0 10px;
}

.topbar-search .form-control {
  border-radius: 0 10px 10px 0;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--app-surface);
  border: 1px solid var(--app-border);
}

.user-chip img {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  object-fit: cover;
}

.user-initial {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  background: var(--app-primary);
}

.user-avatar-lg {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  object-fit: cover;
  background: rgba(79, 70, 229, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  color: var(--app-primary);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--app-border);
}

.user-card .field-label {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--app-muted);
}

.user-card .field-value {
  font-weight: 600;
  color: var(--app-text);
}

.app-content {
  padding: 18px;
  flex: 1;
}

.app-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--app-border);
  color: var(--app-muted);
  background: var(--app-footer-bg);
}

.card {
  border-radius: var(--radius);
  border: 1px solid var(--app-border);
  background: var(--app-surface);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.04);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--app-border);
}

.btn-primary {
  background: var(--app-primary);
  border-color: var(--app-primary);
}

.btn-primary:hover {
  background: var(--app-primary-700);
  border-color: var(--app-primary-700);
}

.form-control, .form-select {
  border-radius: 10px;
}

.form-control:focus, .form-select:focus {
  border-color: rgba(79,70,229,0.55);
  box-shadow: 0 0 0 0.2rem rgba(79,70,229,0.15);
}

.required-field::after {
  content: " *";
  color: #ef4444;
}

#loading-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.45);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.spinner-container {
  background-color: var(--app-surface);
  padding: 18px 20px;
  border-radius: 14px;
  text-align: center;
  border: 1px solid var(--app-border);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
}

.upload-area {
  border: 2px dashed var(--app-border);
  border-radius: 14px;
  padding: 1.75rem;
  text-align: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.upload-area:hover {
  border-color: rgba(79, 70, 229, 0.7);
}

.upload-area.dragover {
  border-color: rgba(79, 70, 229, 0.7);
  background-color: rgba(79, 70, 229, 0.06);
}

.file-info {
  background-color: rgba(15, 23, 42, 0.03);
  border-radius: 12px;
  padding: 1rem;
  margin-top: 1rem;
  border: 1px solid var(--app-border);
}

body[data-theme="dark"] .file-info {
  background-color: rgba(255, 255, 255, 0.04);
}

.dropdown-menu {
  border: 1px solid var(--app-border);
}

body[data-theme="dark"] .dropdown-menu {
  background: var(--app-surface);
}

body[data-theme="dark"] .dropdown-item {
  color: var(--app-text);
}

body[data-theme="dark"] .dropdown-item:hover,
body[data-theme="dark"] .dropdown-item:focus {
  background: rgba(255,255,255,0.06);
  color: var(--app-text);
}

.chat-container {
  height: calc(100vh - 120px);
  background: var(--app-surface);
  border-radius: 12px;
  border: 1px solid var(--app-border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
  overflow: hidden;
  display: flex;
}

.chat-sidebar {
  width: var(--chat-sidebar-width);
  border-right: 1px solid var(--app-border);
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.03);
}

body[data-theme="dark"] .chat-sidebar {
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--app-border);
  background: var(--app-surface);
}

.user-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.user-item {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid transparent;
}

.user-item:hover {
  background: var(--app-surface);
  border-color: var(--app-border);
}

.user-item.active {
  background: var(--app-surface);
  border-color: rgba(79, 70, 229, 0.45);
  box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

body[data-theme="dark"] .user-item.active {
  border-color: rgba(99, 102, 241, 0.5);
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--app-muted);
  position: relative;
}

body[data-theme="dark"] .user-avatar {
  background: rgba(255, 255, 255, 0.08);
}

.status-indicator {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--app-surface);
}

.status-online { background: #10b981; }
.status-offline { background: #94a3b8; }

.status-dot-sm {
  width: 8px;
  height: 8px;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-status { font-size: 0.75rem; color: var(--app-muted); }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--app-surface);
}

.chat-interface {
  height: 100%;
  flex-direction: column;
}

.chat-header {
  height: var(--chat-header-height);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--app-border);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: rgba(15, 23, 42, 0.03);
}

body[data-theme="dark"] .chat-messages {
  background: rgba(255, 255, 255, 0.03);
}

.message { max-width: 70%; display: flex; flex-direction: column; }
.message-own { align-self: flex-end; align-items: flex-end; }
.message-peer { align-self: flex-start; align-items: flex-start; }

.message-content {
  padding: 0.75rem 1rem;
  border-radius: 14px;
  font-size: 0.95rem;
  position: relative;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.message-own .message-content {
  background: var(--app-primary);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.chat-attachment {
  margin-top: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 12px;
  border: 1px solid var(--app-border);
  background: rgba(15, 23, 42, 0.03);
  font-size: 0.8rem;
}

body[data-theme="dark"] .chat-attachment {
  background: rgba(255, 255, 255, 0.04);
}

.chat-attachment a {
  color: var(--app-text);
}

.chat-attachment a:hover {
  color: var(--app-text);
  text-decoration: underline;
}

.message-peer .message-content {
  background: var(--app-surface);
  color: var(--app-text);
  border-bottom-left-radius: 2px;
  border: 1px solid var(--app-border);
}

.message-meta {
  font-size: 0.7rem;
  color: var(--app-muted);
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--app-border);
}

.chat-input-wrapper {
  background: rgba(15, 23, 42, 0.06);
  border-radius: 12px;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--app-border);
}

body[data-theme="dark"] .chat-input-wrapper {
  background: rgba(255, 255, 255, 0.05);
}

.chat-input-wrapper input[type="text"] {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0.5rem;
  color: var(--app-text);
}

.attachment-btn {
  color: var(--app-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 8px;
  transition: all 0.2s;
}

.attachment-btn:hover {
  background: rgba(15, 23, 42, 0.10);
  color: var(--app-text);
}

body[data-theme="dark"] .attachment-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--app-muted);
  text-align: center;
  padding: 2rem;
}

.empty-chat i { font-size: 4rem; margin-bottom: 1rem; opacity: 0.5; }

@media (max-width: 992px) {
  .chat-container {
    height: calc(100vh - 160px);
    flex-direction: column;
  }
  .chat-sidebar {
    width: 100%;
    max-height: 240px;
  }
}

body.sidebar-collapsed .app-sidebar {
  width: 78px;
}

body.sidebar-collapsed .sidebar-link span,
body.sidebar-collapsed .sidebar-section {
  display: none;
}

body.sidebar-collapsed .sidebar-link {
  justify-content: center;
  padding: 12px;
}

@media (max-width: 992px) {
  .app-sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    z-index: 1050;
    transition: left .2s ease;
  }
  body.sidebar-open .app-sidebar {
    left: 0;
  }
  .app-topbar {
    padding: 0 12px;
  }
}
