/* ============================================================
   1Dentica — design tokens
   Import AFTER Tabler's CSS so these overrides win.
   ============================================================ */

:root, [data-theme="light"] {
  /* Brand */
  --brand-900: #073B5D;
  --brand-700: #0A5A87;
  --brand-500: #147DB4;
  --brand-300: #8BC3E4;
  --brand-100: #E8F3FB;
  --brand-50:  #F4FAFE;

  /* Surfaces & text */
  --bg:            #F6F8FB;
  --surface:       #FFFFFF;
  --surface-2:     #F9FAFC;
  --border:        #E6E9EF;
  --border-strong: #D6DBE3;
  --text:          #1B2436;
  --text-muted:    #5A6478;
  --text-soft:     #8A93A6;

  /* Category accents */
  --accent-blue-bg:   #E6F0FA;  --accent-blue-fg:   #2B7FB8;
  --accent-green-bg:  #E3F4EC;  --accent-green-fg:  #1F8A5B;
  --accent-purple-bg: #EDEAFB;  --accent-purple-fg: #6B5BD2;
  --accent-amber-bg:  #FBEFD8;  --accent-amber-fg:  #B8821F;
  --accent-rose-bg:   #FBE6E7;  --accent-rose-fg:   #C0414C;

  /* Tabler/Bootstrap variable overrides */
  --tblr-primary: #0A5A87;
  --tblr-primary-rgb: 10, 90, 135;
  --tblr-primary-fg: #FFFFFF;
  --tblr-body-bg: #F6F8FB;
  --tblr-body-color: #1B2436;
  --tblr-bg-surface: #FFFFFF;
  --tblr-bg-surface-secondary: #F9FAFC;
  --tblr-border-color: #E6E9EF;
  --tblr-link-color: #0A5A87;
  --tblr-link-color-rgb: 10, 90, 135;

  /* Layout */
  --sidebar-w-expanded: 260px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 64px;

  /* Radii / shadow */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .03);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .06), 0 2px 4px rgba(15, 23, 42, .04);

  color-scheme: light;
}

[data-theme="dark"] {
  /* Brand */
  --brand-900: #5BA3D9;
  --brand-700: #4A93CD;
  --brand-500: #3D85BF;
  --brand-300: #2B6A9C;
  --brand-100: #1A3147;
  --brand-50:  #142436;

  /* Surfaces & text */
  --bg:            #0C1422;
  --surface:       #131D2E;
  --surface-2:     #182337;
  --border:        #1F2C44;
  --border-strong: #2A3853;
  --text:          #E6EBF3;
  --text-muted:    #9AA5B9;
  --text-soft:     #6F7A92;

  /* Category accents */
  --accent-blue-bg:   rgba(43,127,184,.16);  --accent-blue-fg:   #6EB5E0;
  --accent-green-bg:  rgba(31,138,91,.18);   --accent-green-fg:  #5BC290;
  --accent-purple-bg: rgba(107,91,210,.18);  --accent-purple-fg: #9C8FE3;
  --accent-amber-bg:  rgba(184,130,31,.18);  --accent-amber-fg:  #E0B264;
  --accent-rose-bg:   rgba(192,65,76,.18);   --accent-rose-fg:   #E08A92;

  /* Tabler/Bootstrap variable overrides */
  --tblr-primary: #3D85BF;
  --tblr-primary-rgb: 61, 133, 191;
  --tblr-body-bg: #0C1422;
  --tblr-body-color: #E6EBF3;
  --tblr-bg-surface: #131D2E;
  --tblr-bg-surface-secondary: #182337;
  --tblr-border-color: #1F2C44;
  --tblr-link-color: #5BA3D9;
  --tblr-link-color-rgb: 91, 163, 217;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 14px rgba(0,0,0,.4);

  color-scheme: dark;
}

/* ============================================================
   Single-sidebar layout (replaces Tabler's dual layout-combo)
   ============================================================ */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w-expanded) 1fr;
  min-height: 100vh;
  transition: grid-template-columns .25s ease;
}
.app-shell[data-collapsed="true"] {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

.sb {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.sb-header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
}
.sb-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  white-space: nowrap;
}
.sb-logo-link {
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  text-decoration: none;
}
.sb-logo-image {
  display: block;
  width: 154px;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  object-position: left center;
}
[data-sidebar-collapsed="true"] .sb-logo-link {
  width: 34px;
  height: 34px;
}
[data-sidebar-collapsed="true"] .sb-logo-image {
  width: 118px;
  max-width: none;
  height: 34px;
  object-fit: cover;
  object-position: left center;
}

.sb-logo-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--brand-900);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  flex-shrink: 0;
}
.sb-logo-text {
  font-weight: 700;
  font-size: 18px;
  color: var(--brand-500);
}
.sb-logo-text b { color: var(--brand-900); }
[data-theme="dark"] .sb-logo-text b { color: #fff; }
.app-shell[data-collapsed="true"] .sb-logo-text { display: none; }

.sb-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sb-divider { height: 1px; background: var(--border); margin: 12px 8px; }

.sb-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
  overflow: hidden;
}
.sb-item:hover { background: var(--surface-2); color: var(--text); }
.sb-item.active {
  background: var(--brand-100);
  color: var(--brand-500);
  font-weight: 600;
}
.sb-item .icon { font-size: 20px; flex-shrink: 0; width: 20px; }
.sb-item .label { flex: 1; }
.sb-item .chev { font-size: 16px; color: var(--text-soft); }
.sb-badge {
  font-size: 10px; font-weight: 600;
  background: var(--accent-amber-bg); color: var(--accent-amber-fg);
  padding: 2px 7px; border-radius: 999px; letter-spacing: .3px;
}
.app-shell[data-collapsed="true"] .sb-item {
  justify-content: center;
  padding: 0;
  width: 44px; height: 44px;
  margin: 0 auto;
}
.app-shell[data-collapsed="true"] .sb-item .label,
.app-shell[data-collapsed="true"] .sb-item .chev,
.app-shell[data-collapsed="true"] .sb-badge { display: none; }
.app-shell[data-collapsed="true"] .sb-item .icon { font-size: 22px; }

.sb-footer { border-top: 1px solid var(--border); padding: 10px 12px; }
.sb-collapse {
  width: 100%;
  height: 40px;
  border: 0; background: transparent;
  border-radius: var(--radius-md);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  color: var(--text-soft);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sb-collapse:hover { background: var(--surface-2); color: var(--text); }
.sb-collapse .icon { font-size: 18px; transition: transform .25s; }
.app-shell[data-collapsed="true"] .sb-collapse { justify-content: center; padding: 0; }
.app-shell[data-collapsed="true"] .sb-collapse .label { display: none; }
.app-shell[data-collapsed="true"] .sb-collapse .icon { transform: rotate(180deg); }

/* ============================================================
   1Dentica — hybrid layout: single sidebar + Tabler topbar
   Override-и Tabler-структури під handoff single-sidebar pattern
   ============================================================ */

/* Sidebar шир 260px expanded, 72px collapsed, sticky на повну висоту */
.navbar.navbar-vertical {
  width: var(--sidebar-w-expanded);
  background: var(--surface);
  border-right: 1px solid var(--border);
}
[data-sidebar-collapsed="true"] .navbar.navbar-vertical {
  width: var(--sidebar-w-collapsed);
}
[data-sidebar-collapsed="true"] .navbar.navbar-vertical .navbar-brand .sb-logo-text,
[data-sidebar-collapsed="true"] .navbar.navbar-vertical .nav-link .nav-link-title,
[data-sidebar-collapsed="true"] .navbar.navbar-vertical .sb-badge,
[data-sidebar-collapsed="true"] .navbar.navbar-vertical .sb-collapse-label {
  display: none;
}

/* Page wrapper зміщується на ширину sidebar */
.page-wrapper {
  margin-left: var(--sidebar-w-expanded);
  transition: margin-left .25s ease;
}
[data-sidebar-collapsed="true"] .page-wrapper {
  margin-left: var(--sidebar-w-collapsed);
}
@media (max-width: 991.98px) {
  .page-wrapper { margin-left: 0; }
}

/* 1Dentica логотип-блок у sidebar header (CSS-recreation з handoff) */
.sb-logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--brand-900);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  flex-shrink: 0;
}
.sb-logo-text {
  font-weight: 700;
  font-size: 18px;
  color: var(--brand-500);
  letter-spacing: -0.2px;
}
.sb-logo-text b { color: var(--brand-900); }
[data-theme="dark"] .sb-logo-text b { color: #fff; }

/* Нав-айтеми sidebar — стиль handoff */
.navbar.navbar-vertical .nav-link {
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  gap: 12px;
  transition: background .15s, color .15s;
}
.navbar.navbar-vertical .nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}
.navbar.navbar-vertical .nav-item.active > .nav-link,
.navbar.navbar-vertical .nav-link.active {
  background: var(--brand-100);
  color: var(--brand-500);
  font-weight: 600;
}
.sb-badge {
  font-size: 10px;
  font-weight: 600;
  background: var(--accent-amber-bg);
  color: var(--accent-amber-fg);
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: .3px;
  margin-left: auto;
}

/* Sidebar footer з Collapse-кнопкою */
.sb-collapse {
  width: 100%;
  height: 40px;
  border: 0;
  background: transparent;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sb-collapse:hover {
  background: var(--surface-2);
  color: var(--text);
}
.sb-collapse .icon {
  transition: transform .25s;
}
[data-sidebar-collapsed="true"] .sb-collapse {
  justify-content: center;
  padding: 0;
}
[data-sidebar-collapsed="true"] .sb-collapse .icon {
  transform: rotate(180deg);
}

/* Topbar — pill для пошуку, Post-CTA, profile pill */
.shell-topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.shell-search-pill .form-control {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  height: 40px;
  width: 100%;
}
.shell-search-pill .form-control:focus {
  background: var(--surface);
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(10,90,135,.12);
}
.shell-search-pill {
  flex: 1 1 22rem;
  max-width: clamp(18rem, 38vw, 42rem);
  min-width: 12rem;
}
.shell-kbd-hint {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  color: var(--text-soft);
  background: var(--surface);
}

.btn-brand {
  background: var(--brand-500);
  border-color: var(--brand-500);
  color: #fff;
  height: 38px;
  border-radius: 8px;
  font-weight: 600;
}
.btn-brand:hover { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }

.shell-topnav {
  flex: 0 0 auto;
}
.shell-topnav__link {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: var(--topbar-h);
  padding: 0 .85rem;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.shell-topnav__link:hover {
  color: var(--brand-700);
  text-decoration: none;
}
.shell-topnav__link.active {
  color: var(--brand-900);
}
.shell-topnav__link.active::after {
  content: "";
  position: absolute;
  right: .75rem;
  bottom: 0;
  left: .75rem;
  height: 3px;
  border-radius: 999px 999px 0 0;
  background: var(--brand-700);
}

.notif-dot {
  position: absolute;
  top: 4px; right: 4px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--brand-500);
  border: 2px solid var(--surface);
}

.profile-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.profile-pill:hover { background: var(--brand-50); color: var(--text); }
.profile-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-300), var(--brand-500));
  color: #fff;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 13px;
}

/* ============================================================
   Communications
   ============================================================ */

.communications-shell {
  min-width: 0;
}

.communications-tabs .btn.active {
  background: var(--brand-500);
  border-color: var(--brand-500);
  color: #fff;
}

.communications-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem;
}

.communications-summary-grid > div {
  min-width: 0;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.communications-summary-grid span {
  display: block;
  color: var(--text-muted);
  font-size: .76rem;
  line-height: 1.2;
}

.communications-summary-grid strong {
  display: block;
  margin-top: .2rem;
  font-size: 1.45rem;
  line-height: 1.1;
  color: var(--text);
}

.communications-start-form {
  display: grid;
  grid-template-columns: minmax(12rem, .8fr) minmax(14rem, 1fr) auto;
  gap: .75rem;
  align-items: end;
}

.communications-form-action {
  min-width: 8rem;
}

.communications-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 22rem) minmax(0, 1fr);
  gap: 1rem;
  min-height: 34rem;
}

.communications-list-pane,
.communications-thread-pane {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.communications-list-pane {
  overflow: hidden;
}

.communications-room-list,
.communications-notification-list {
  display: grid;
}

.communications-room-item,
.communications-notification-item {
  width: 100%;
  min-width: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.communications-room-item {
  display: grid;
  gap: .35rem;
  padding: .9rem 1rem;
  cursor: pointer;
}

.communications-room-item:hover,
.communications-room-item.active {
  background: var(--brand-50);
}

.communications-room-title,
.communications-notification-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.communications-room-preview,
.communications-notification-preview,
.communications-room-meta,
.communications-notification-meta {
  min-width: 0;
  color: var(--text-muted);
  font-size: .84rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.communications-room-meta,
.communications-notification-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: center;
}

.communications-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 .35rem;
  border-radius: 999px;
  background: var(--accent-rose-bg);
  color: var(--accent-rose-fg);
  font-size: .74rem;
  font-weight: 700;
}

.communications-thread-pane {
  display: grid;
  grid-template-rows: auto minmax(18rem, 1fr) auto;
  overflow: hidden;
}

.communications-thread-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.communications-message-list {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  min-height: 18rem;
  max-height: 32rem;
  overflow: auto;
  padding: 1rem;
  background: var(--surface-2);
}

.communications-message-bubble {
  max-width: min(42rem, 82%);
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.communications-message-bubble.is-mine {
  align-self: flex-end;
  border-color: rgba(43, 127, 184, .24);
  background: var(--brand-100);
}

.communications-message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.communications-message-time {
  margin-top: .35rem;
  color: var(--text-muted);
  font-size: .72rem;
}

.communications-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .75rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.communications-notification-item {
  display: grid;
  gap: .45rem;
  padding: 1rem;
}

.communications-notification-item.is-unread {
  background: var(--brand-50);
}

.communications-notification-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .2rem;
}

.communications-empty {
  padding: 1.25rem;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 991.98px) {
  .communications-start-form,
  .communications-layout,
  .communications-compose {
    grid-template-columns: 1fr;
  }

  .communications-layout {
    min-height: 0;
  }

  .communications-message-list {
    max-height: 24rem;
  }
}

@media (max-width: 575.98px) {
  .communications-summary-grid {
    grid-template-columns: 1fr;
  }

  .communications-thread-header {
    flex-direction: column;
  }

  .communications-message-bubble {
    max-width: 100%;
  }
}
