:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef3f5;
  --text: #1c252b;
  --muted: #64727d;
  --line: #d8e0e5;
  --accent: #0f8f77;
  --accent-strong: #086956;
  --blue: #1478d4;
  --danger: #b83232;
  --warning: #a46412;
  --success-bg: #dff4e8;
  --danger-bg: #fae2e2;
  --warning-bg: #fff0d3;
  --shadow: 0 10px 24px rgba(28, 37, 43, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.app-shell {
  width: min(1960px, calc(100% - 24px));
  margin: 0 auto;
  padding: 26px 0 42px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 750;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 4px;
}

.tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  font-weight: 700;
}

.tab.is-active {
  background: var(--accent);
  color: #ffffff;
}

.logout-form {
  margin: 0;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-summary {
  max-width: 240px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 24px;
  line-height: 1.15;
}

.section-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.primary-button,
.secondary-button,
.mini-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.primary-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
  padding: 10px 14px;
}

.secondary-button,
.mini-button {
  padding: 10px 14px;
}

.mini-button {
  min-width: 76px;
  padding: 7px 10px;
  font-size: 13px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  box-shadow: var(--shadow);
}

.icon-button span {
  font-size: 24px;
  line-height: 1;
}

.icon-button.is-loading span {
  animation: spin 0.9s linear infinite;
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.filters label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.filters input,
.filters select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.summary,
.sync-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric,
.notice {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.metric {
  display: grid;
  align-content: center;
  gap: 5px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 22px;
  line-height: 1.1;
}

.metric small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.sync-progress-metric {
  gap: 8px;
}

.sync-progress-metric.is-running,
.deal-progress-panel.is-running {
  border-color: rgba(20, 120, 212, 0.34);
  box-shadow: 0 10px 24px rgba(20, 120, 212, 0.11);
}

.progress-track {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e6edf1;
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  min-width: 6px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  transition: width 0.25s ease;
}

.is-running .progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    transparent 0,
    transparent 34%,
    rgba(255, 255, 255, 0.45) 48%,
    transparent 62%,
    transparent 100%
  );
  animation: progress-sheen 1.3s linear infinite;
}

.notice {
  grid-column: 1 / -1;
  color: var(--muted);
}

.notice.error {
  border-color: rgba(184, 50, 50, 0.35);
  background: var(--danger-bg);
  color: var(--danger);
}

.notice.success {
  border-color: rgba(15, 143, 119, 0.25);
  background: var(--success-bg);
  color: var(--accent-strong);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 600px), 1fr));
  gap: 10px;
}

.widget,
.sync-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.widget {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.widget h2 {
  font-size: 14px;
  line-height: 1.25;
}

.widget-total {
  display: grid;
  place-items: center;
  min-width: 36px;
  height: 28px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 15px;
}

.table-wrap {
  overflow-x: auto;
  max-height: 340px;
}

.widget .table-wrap {
  min-height: 190px;
  max-height: 330px;
}

.sync-table-wrap {
  max-height: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
  font-size: 14px;
}

.sync-table {
  min-width: 940px;
}

.widget table {
  table-layout: fixed;
  min-width: 0;
  font-size: 12px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.widget th,
.widget td {
  padding: 7px 8px;
  line-height: 1.25;
}

.widget th {
  color: #52616c;
  font-size: 11px;
  white-space: normal;
}

.widget td {
  overflow-wrap: anywhere;
}

.widget tbody tr:nth-child(even):not(.total-row) td {
  background: #fbfdfe;
}

.widget tbody tr:hover td {
  background: #f8fbfc;
}

.widget tbody tr.data-row {
  cursor: pointer;
}

.widget tbody tr.data-row.is-expanded td {
  background: #edf7f5;
}

.widget tbody tr.deal-list-row td {
  background: #f7fbfa;
  padding: 8px 10px 12px;
}

.deal-list {
  display: grid;
  gap: 6px;
  max-height: 170px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.deal-list li {
  min-width: 0;
}

.deal-list a,
.deal-list span {
  display: block;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  color: var(--text);
  padding: 6px 8px;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.deal-list a:hover {
  color: var(--blue);
  text-decoration: underline;
}

.deal-list-empty {
  color: var(--muted);
  font-size: 12px;
}

.widget .date-col {
  width: 86px;
}

.widget .person-col {
  width: 32%;
}

.widget .type-col {
  width: 24%;
}

.widget .count-col {
  width: 136px;
}

td.num,
th.num {
  width: 116px;
  text-align: right;
}

.widget td.num,
.widget th.num {
  width: 136px;
}

.count-cell {
  padding-block: 5px;
}

.count-bar {
  position: relative;
  display: grid;
  align-items: center;
  min-height: 22px;
  overflow: hidden;
  border-radius: 3px;
  background: #edf2f4;
}

.count-bar > span {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar-width);
  border-radius: inherit;
  background: linear-gradient(90deg, #ff5a74, #f2b83b);
}

.count-bar strong {
  position: relative;
  z-index: 1;
  padding: 0 7px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  text-align: right;
}

.total-row td {
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: #e4eaee;
  color: var(--text);
  font-weight: 850;
}

.toggle-col {
  width: 78px;
  text-align: center;
}

.action-col {
  width: 96px;
  text-align: center;
}

.method {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.entity-settings-row td {
  background: #fbfcfd;
  padding: 0;
}

.entity-settings {
  display: grid;
  grid-template-columns: 280px minmax(360px, 1fr);
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.deal-progress-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(260px, 1fr);
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 16px;
}

.deal-progress-panel > div:first-child {
  display: grid;
  gap: 5px;
}

.deal-progress-panel strong {
  font-size: 20px;
  line-height: 1.15;
}

.deal-progress-panel small,
.progress-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.sync-eyebrow {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.deal-progress-body {
  display: grid;
  gap: 8px;
}

.progress-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 14px;
}

.entity-setting-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.entity-setting-card > span {
  color: var(--muted);
  font-weight: 700;
}

.entity-setting-card strong {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 28px;
  border-radius: 7px;
  background: var(--blue);
  color: #ffffff;
  font-size: 15px;
}

.entity-setting-card button {
  margin-left: auto;
}

.period-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr)) auto;
}

.period-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.period-card input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f2f4f6;
  padding: 0;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 2px 4px rgba(28, 37, 43, 0.14);
  transition: transform 0.18s ease;
}

.switch.is-on {
  border-color: rgba(15, 143, 119, 0.35);
  background: #43d26f;
}

.switch.is-on span {
  transform: translateX(20px);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  min-height: 26px;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 800;
}

.status.ok {
  background: var(--success-bg);
  color: var(--accent-strong);
}

.status.running,
.status.partial {
  background: var(--warning-bg);
  color: var(--warning);
}

.status.bad {
  background: var(--danger-bg);
  color: var(--danger);
}

.status.idle,
.status.muted {
  background: var(--surface-soft);
  color: var(--muted);
}

.empty {
  color: var(--muted);
  text-align: center;
}

.user-labels-panel,
.app-users-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.user-labels-header,
.app-users-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.user-labels-header h3,
.app-users-header h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.user-labels-header p,
.app-users-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.user-labels-panel .notice,
.app-users-panel .notice {
  min-height: 0;
  margin: 12px 16px;
  box-shadow: none;
}

.user-labels-table-wrap {
  max-height: 420px;
}

.user-labels-table {
  min-width: 840px;
}

.user-labels-table code {
  color: var(--muted);
  font-family: inherit;
  font-weight: 800;
}

.user-labels-table tr.is-unmapped td {
  background: #fffaf0;
}

.user-label-input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
}

.user-label-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.app-user-form {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(160px, 1.2fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.app-user-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.app-user-form input,
.app-user-form select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}

.app-users-table-wrap {
  max-height: 360px;
}

.app-users-table {
  min-width: 900px;
}

.mini-button.ghost {
  background: transparent;
  color: var(--muted);
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 37, 43, 0.32);
}

.modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto minmax(220px, 1fr) auto;
  width: min(980px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(28, 37, 43, 0.22);
  overflow: hidden;
}

.modal-header,
.modal-footer,
.field-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  font-size: 20px;
}

.modal-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.modal-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-footer span {
  color: var(--muted);
  font-weight: 800;
}

.icon-button.flat {
  box-shadow: none;
}

.field-toolbar input {
  flex: 1;
  min-width: 220px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.field-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  overflow: auto;
  padding: 14px 16px;
}

.field-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.field-option.is-required {
  background: var(--surface-soft);
}

.field-option input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
}

.field-option span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.field-option strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.field-option small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.field-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

.field-empty.error {
  color: var(--danger);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-shell {
  width: min(100%, 380px);
}

.login-card {
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 26px;
}

.login-card h1 {
  font-size: 30px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-card input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 0 12px;
}

.login-card button {
  height: 44px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.login-error {
  margin: 0;
  border: 1px solid var(--danger-bg);
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 12px;
  font-weight: 700;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes progress-sheen {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(100%);
  }
}

@media (max-width: 980px) {
  .topbar,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .user-menu {
    align-items: stretch;
    flex-direction: column;
  }

  .user-summary {
    max-width: none;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1;
  }

  .dashboard-grid,
  .summary,
  .sync-status,
  .filters,
  .app-user-form,
  .entity-settings,
  .deal-progress-panel,
  .period-card,
  .field-list {
    grid-template-columns: 1fr;
  }

  .app-shell {
    width: min(100% - 20px, 760px);
    padding-top: 18px;
  }
}
