/* ==============================================================================
   Базовые стили, сброс, шапка, табы и футер
   ============================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  font-synthesis: none;
  font-stretch: 100%;
}

body {
  min-height: 100dvh;
  font: 400 var(--text-base)/1.6 var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
}

* {
  font-family: var(--font-body);
}

img, svg {
  display: block;
  max-width: 100%;
}

input, button, select, textarea, option {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
}

button:disabled, select:disabled {
  cursor: not-allowed;
}

button, input, select {
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
}

h1, h2 {
  line-height: 1.2;
  text-wrap: balance;
  font-family: var(--font-display);
}

p {
  overflow-wrap: anywhere;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  z-index: 9;
  background: white;
  padding: var(--space-3);
  text-decoration: underline;
}

.skip:focus {
  top: var(--space-2);
}

/* Верхняя полоса (Topbar) */
.topbar {
  max-width: 1440px;
  margin: auto;
  padding: var(--space-6) var(--space-10);
  display: grid;
  grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);
  align-items: center;
  gap: var(--space-4);
  border-bottom: 1px solid #e5e8e2;
}

.wordmark {
  justify-self: start;
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: .12em;
}

.company-brand {
  width: 200px;
  max-width: 100%;
  justify-self: center;
  transform: translateY(20.14%);
}

.company-logo {
  display: block;
  width: 100%;
  height: auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: var(--space-3);
  min-width: 0;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  font-size: var(--text-xs);
  color: var(--color-text);
  max-width: 220px;
}

.user-avatar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--color-primary);
}

.user-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.btn-logout {
  color: var(--color-text-muted);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
  line-height: 1.4;
  transition: all .15s ease;
}

.btn-logout:hover {
  color: var(--color-error);
  background: rgba(160, 51, 53, 0.08);
  border-color: rgba(160, 51, 53, 0.2);
}

.sync-label {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.sync-dot {
  height: 6px;
  width: 6px;
  background: #577660;
  border-radius: 50%;
}

.sync-dot.error-dot {
  background: var(--color-error);
}

/* Вкладки (Tabs) */
.tabs {
  max-width: 1440px;
  margin: auto;
  display: flex;
  justify-content: center;
  gap: var(--space-6);
  border-bottom: 1px solid #e5e8e2;
  padding: 0 var(--space-4);
}

.tabs.hidden {
  display: none !important;
}

.tab {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--color-text);
}

.tab.active, .tab[aria-current="page"] {
  color: var(--color-text);
  font-weight: 500;
  border-bottom-color: var(--color-primary);
}

/* Подвал */
.page-footer {
  margin: 0 var(--space-10);
  padding: var(--space-4) 0;
  border-top: 1px solid #dce1d8;
  color: var(--color-text-muted);
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  font-size: var(--text-xs);
}

.error-panel {
  background: #fbefee;
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  color: #8f3136;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quiet {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
}

.quiet:hover {
  background: #ffffff80;
}

@media (max-width: 760px) {
  .topbar {
    padding: var(--space-4) var(--space-3);
    column-gap: 6px;
  }
  .company-brand {
    width: clamp(90px, 28vw, 110px);
  }
  .wordmark {
    font-size: 12px;
    letter-spacing: .02em;
    white-space: nowrap;
  }
  .sync-label {
    font-size: 12px;
    white-space: nowrap;
  }
  .page-footer {
    margin: 0 var(--space-4);
    flex-direction: column;
    gap: var(--space-1);
  }
  .tabs {
    gap: var(--space-5);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
