/**
 * Ninox Database — визуальный слой как в десктопном приложении (Contacts / таблица + панель записи).
 * Цвета выверены по референсным скриншотам (синие панели, белая таблица, боковая форма).
 * Токены оболочки: ninox-tokens.css
 */

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Roboto, sans-serif;
}

body {
  background: var(--ninox-app-bg) !important;
  color: #2c3347;
}

/* ——— Левая колонка (навигация) ——— */
.sidebar {
  background: var(--ninox-sidebar) !important;
  border-right: 1px solid rgba(0, 0, 0, 0.08) !important;
}

.sidebar-section-label,
.sidebar-ninox-title {
  color: rgba(255, 255, 255, 0.98) !important;
}

.sidebar-ninox-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0 6px;
}

.sidebar-ninox-back {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.95);
  cursor: pointer;
}

.sidebar-ninox-back:hover {
  background: rgba(255, 255, 255, 0.22);
}

.sidebar-ninox-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.sidebar-ninox-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-ninox-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px 8px 12px;
  min-height: 38px;
  background: transparent;
  color: rgba(255, 255, 255, 0.92) !important;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.sidebar-ninox-nav-item:hover {
  background: rgba(255, 255, 255, 0.1) !important;
}

.sidebar-ninox-nav-item--secondary {
  opacity: 0.95;
  padding-top: 6px;
  padding-bottom: 6px;
  min-height: 34px;
  font-size: 12px;
}

.sidebar-ninox-nav-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.92);
}

.sidebar-ninox-nav-icon svg {
  width: 20px;
  height: 20px;
}

.sidebar-ninox-nav-item--secondary .sidebar-ninox-nav-icon svg {
  width: 16px;
  height: 16px;
}

.sidebar-ninox-nav .mode-button.active {
  background: rgba(0, 0, 0, 0.18) !important;
  color: #fff !important;
}

.sidebar-ninox-nav .mode-button.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: #fff !important;
}

.sidebar-active-table {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  min-height: 44px;
  padding: 8px 8px 8px 12px;
  border-radius: 6px;
  background: #fff !important;
  color: var(--ninox-tab-active-text) !important;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
}

.sidebar-active-table.hidden {
  display: none !important;
}

.sidebar-active-table-accent {
  display: none;
}

.sidebar-active-table-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  padding-left: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ninox-tab-active-text) !important;
}

.sidebar-active-table-chevron {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: rgba(93, 109, 190, 0.1);
  color: var(--ninox-tab-active-text);
  cursor: pointer;
}

.sidebar-active-table-chevron:hover {
  background: rgba(93, 109, 190, 0.18);
}

.mode-button span:last-child {
  color: inherit !important;
}

.sidebar-search input {
  background: rgba(0, 0, 0, 0.12) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  color: #fff !important;
}

.sidebar-search input::placeholder {
  color: rgba(255, 255, 255, 0.55) !important;
}

.table-button,
.nav-entry {
  border-radius: 6px !important;
}

.table-button.active,
.nav-entry.active {
  background: rgba(255, 255, 255, 0.2) !important;
}

/* ——— Верхняя полоса вкладок (как «Contacts» +) ——— */
.workspace-view-tabs {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between !important;
  align-items: flex-end !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
  background: var(--ninox-header-bar) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
  min-height: 44px !important;
  padding: 4px 12px 0 !important;
  min-width: 0 !important;
}

.workspace-view-tabs-start {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}

.workspace-view-tabs-end {
  display: flex;
  align-items: center;
  padding-bottom: 4px;
  flex-shrink: 0;
}

.workspace-header-icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.workspace-header-icon-button:hover {
  background: rgba(255, 255, 255, 0.26);
}

.workspace-db-label {
  font-size: 15px !important;
  font-weight: 600 !important;
  color: rgba(255, 255, 255, 0.95) !important;
  margin-right: 10px !important;
  letter-spacing: 0 !important;
}

.view-tab {
  height: 36px !important;
  min-width: auto !important;
  padding: 0 16px !important;
  border-radius: 6px 6px 0 0 !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  border-bottom: none !important;
  background: rgba(255, 255, 255, 0.14) !important;
  color: var(--ninox-tab-inactive) !important;
  font-weight: 600 !important;
  font-size: 13px !important;
}

.view-tab.active {
  background: var(--ninox-tab-active-bg) !important;
  color: var(--ninox-tab-active-text) !important;
  border-color: rgba(255, 255, 255, 0.45) !important;
  box-shadow: 0 -1px 0 #fff inset;
}

.view-tab.add-tab {
  width: 36px !important;
  min-width: 36px !important;
  font-size: 18px !important;
}

/* ——— Рабочая область ——— */
.workspace {
  background: var(--ninox-workspace-bg) !important;
}

/* Панель инструментов под вкладками */
.workspace-toolbar {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  gap: 8px !important;
  min-width: 0 !important;
  background: #ffffff !important;
  border-bottom: 1px solid var(--ninox-table-border) !important;
  padding: 6px 12px !important;
  min-height: 48px !important;
}

.toolbar-icon-button {
  height: 36px !important;
  width: 36px !important;
  border-radius: 5px !important;
  border: 1px solid #e8eaef !important;
  background: #fafbfc !important;
  color: #5c6b8a !important;
}

.toolbar-icon-button:hover {
  background: #f0f3f8 !important;
  border-color: #dce1ea !important;
}

.toolbar-icon-button.active {
  background: #e8eef9 !important;
  border-color: #c5d3ec !important;
  color: var(--ninox-tab-active-text) !important;
}

.toolbar-search {
  position: relative !important;
  display: flex !important;
  align-items: center !important;
}

.toolbar-search-icon {
  position: absolute;
  left: 12px;
  z-index: 1;
  color: #8b95a8;
  pointer-events: none;
  display: flex;
  align-items: center;
}

.toolbar-search input {
  border-radius: 18px !important;
  border: 1px solid #dce1ea !important;
  background: #f4f6fa !important;
  font-size: 13px !important;
  padding-left: 36px !important;
  width: 100%;
}

.toolbar-avatar {
  border: 1px solid #dce1ea !important;
  background: linear-gradient(180deg, #e2e8f5, #d2daf0) !important;
  color: #3d4f7a !important;
}

/* ——— Таблица (grid) ——— */
.main-stage {
  background: #fff !important;
  position: relative !important;
}

#record-grid {
  background: #fff !important;
}

#record-grid .grid-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--ninox-table-header) !important;
  color: #4a5568 !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  border-bottom: 1px solid var(--ninox-table-border) !important;
  box-shadow: none !important;
}

#record-grid .grid-header .grid-cell {
  border-right: 1px solid var(--ninox-table-border) !important;
  padding: 8px 10px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b !important;
}

#record-grid .grid-header .grid-cell[data-sort-key] {
  cursor: pointer;
}

#record-grid .grid-header .grid-cell.row-index-cell {
  display: flex !important;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

#record-grid .grid-header .grid-cell.row-index-cell .grid-header-hash {
  flex: 1;
  min-width: 0;
}

.grid-header-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
}

.grid-header-refresh:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #4a56a6;
}

.grid-header-refresh svg {
  width: 16px;
  height: 16px;
}

.grid-sort-indicator {
  margin-left: 4px;
  font-size: 10px;
  color: #5d6dbe;
  user-select: none;
}

#record-grid .grid-header .grid-cell:last-child {
  border-right: none !important;
}

#record-grid .grid-rows > button.grid-row {
  border-bottom: 1px solid var(--ninox-table-border) !important;
}

/* Зебра только внутри .grid-rows */
#record-grid .grid-rows > button.grid-row:nth-child(even) {
  background: var(--ninox-row-a) !important;
}

#record-grid .grid-rows > button.grid-row:nth-child(odd) {
  background: var(--ninox-row-b) !important;
}

#record-grid .grid-rows > button.grid-row:hover {
  background: var(--ninox-row-hover) !important;
}

#record-grid .grid-rows > button.grid-row.active {
  background: var(--ninox-row-selected) !important;
  box-shadow: inset 3px 0 0 #6d7dbd !important;
}

#record-grid .grid-rows > button.grid-row.grid-row-new {
  background: #f0f4fc !important;
  color: #4a56a6 !important;
}

#record-grid .grid-rows .grid-row .grid-cell {
  border-right: 1px solid var(--ninox-table-border) !important;
  font-size: 13px !important;
  color: #2d3748 !important;
  padding: 7px 10px !important;
}

#record-grid .row-index-cell {
  color: #8892a6 !important;
  font-size: 12px !important;
}

/* Перекрываем общие правила из styles.css */
.grid-header {
  background: var(--ninox-table-header) !important;
  border-bottom: 1px solid var(--ninox-table-border) !important;
}

.grid-row:hover {
  background: var(--ninox-row-hover) !important;
}

.grid-row.active {
  background: var(--ninox-row-selected) !important;
  box-shadow: inset 0 0 0 1px rgba(109, 125, 189, 0.35) !important;
}

/* ——— Правая панель записи (форма) ——— */
.workspace-body.tables-with-detail .detail-panel {
  box-shadow: var(--ninox-detail-shadow) !important;
  border-left: 1px solid var(--ninox-table-border) !important;
  z-index: 2;
  display: grid !important;
  grid-template-rows: auto auto minmax(0, 1fr) !important;
  align-content: stretch !important;
  background: #fff !important;
}

.detail-panel-head {
  padding: 12px 16px 10px !important;
  border-bottom: 1px solid var(--ninox-table-border) !important;
}

.detail-panel-head .eyebrow {
  color: #8b95a8 !important;
  font-size: 10px !important;
}

.detail-panel-head h3 {
  color: #2c3347 !important;
  font-size: 16px !important;
  font-weight: 600 !important;
}

.detail-tabs {
  padding: 0 8px !important;
  background: #fafbfc !important;
  border-bottom: 1px solid var(--ninox-table-border) !important;
}

.detail-tab {
  color: #718096 !important;
  height: 40px !important;
}

.detail-tab.active {
  color: var(--ninox-tab-active-text) !important;
  border-bottom-color: #6d7dbd !important;
}

.detail-body {
  padding: 12px 14px 20px !important;
  background: #fff !important;
}

.inspector-sheet {
  padding-top: 4px !important;
}

.inspector-field-shell span {
  color: #718096 !important;
  font-size: 11px !important;
  font-weight: 600 !important;
}

.inspector-field-value,
.stack-field input,
.stack-field select,
.stack-field textarea {
  border-radius: 4px !important;
  border: 1px solid #d1d5db !important;
  background: #fff !important;
}

/* Скрытый заголовок «Данные / Табличный вид» — в Ninox его нет над сеткой */
.data-panel-head {
  display: none !important;
}

.data-panel {
  border-top: none !important;
}

/* Правая узкая вкладка — открыть / свернуть панель записи */
.main-stage-detail-chevron {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 3;
  width: 22px;
  height: 56px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--ninox-table-border);
  border-right: none;
  border-radius: 6px 0 0 6px;
  background: #f8fafc;
  color: #5c6b8a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -2px 0 8px rgba(44, 53, 80, 0.06);
}

.main-stage-detail-chevron:hover {
  background: #eef2f7;
  color: var(--ninox-tab-active-text);
}

.main-stage-detail-chevron.hidden {
  display: none !important;
}

.main-stage-detail-chevron.is-panel-open svg {
  transform: scaleX(-1);
}

/* Прокрутка только у .record-grid-scroll — иначе scrollbar сужает строки относительно шапки */
#record-grid .grid-rows {
  flex: none;
  overflow: visible;
  min-height: 0;
}
