:root {
  color-scheme: light;
  --bg: #f3f5f2;
  --panel: #ffffff;
  --ink: #172126;
  --muted: #66737a;
  --line: #d7ded9;
  --blue: #153442;
  --green: #2f7d5c;
  --amber: #b97722;
  --red: #b95043;
  --violet: #6750a4;
  --shadow: 0 16px 50px rgba(21, 52, 66, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.app-shell {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.auth-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(243, 245, 242, 0.94);
}

.auth-panel[hidden] {
  display: none;
}

.auth-card {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-brand {
  margin-bottom: 18px;
}

.auth-field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.auth-field span,
.auth-error {
  color: var(--muted);
  font-size: 13px;
}

.auth-field input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

.auth-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.auth-actions .primary {
  margin-left: auto;
}

.auth-error {
  min-height: 18px;
  margin-top: 10px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 1px 4px rgba(21, 52, 66, 0.14);
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.05;
}

p {
  margin: 0;
}

.brand p,
.metric-label,
#audioState {
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.audio-row,
.nav-row,
.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.text-button,
.action-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.text-button.primary,
.action-button.done {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.text-button.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.text-button.muted {
  color: var(--muted);
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.score-strip > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.metric-value {
  display: block;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.05;
}

.reward-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(180px, 1fr) minmax(150px, 0.55fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.reward-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.reward-main strong {
  font-size: 18px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.reward-kicker,
#dailyLevelHint,
#dailyProgressText {
  color: var(--muted);
  font-size: 13px;
}

.reward-progress {
  display: grid;
  gap: 6px;
}

.reward-progress-bar {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebe7;
}

.reward-progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 180ms ease;
}

.award-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  transform: translate(-50%, 14px);
  max-width: min(420px, calc(100vw - 28px));
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  padding: 13px 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
}

.award-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  grid-template-areas: "queue review";
  gap: 14px;
  align-items: start;
}

.queue-panel,
.review-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.queue-panel {
  grid-area: queue;
  padding: 12px;
  position: sticky;
  top: 12px;
}

.search-row {
  margin-bottom: 10px;
}

.search-row input,
.search-row select,
.detail-grid select,
.detail-grid input,
.note-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  padding: 8px 10px;
}

.search-row input {
  min-width: 0;
}

.search-row select {
  width: 126px;
  flex: 0 0 126px;
}

.search-row .jump-input {
  width: 70px;
  flex: 0 0 70px;
}

.search-row .jump-button {
  flex: 0 0 auto;
}

.queue-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 190px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 2px;
  scroll-padding: 8px;
  scrollbar-gutter: stable;
}

.queue-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  padding: 9px 10px;
  touch-action: pan-y;
  position: relative;
  overflow: hidden;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
  will-change: transform;
}

.queue-item::after {
  content: "в D";
  position: absolute;
  inset: 0 10px 0 auto;
  display: grid;
  place-items: center;
  color: var(--red);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.queue-item.swiping-left {
  border-color: rgba(185, 80, 67, 0.34);
  background: #fffafa;
}

.queue-item.swipe-ready::after {
  opacity: 1;
}

.queue-item.active {
  border-color: var(--blue);
  box-shadow: inset 3px 0 0 var(--blue);
}

.queue-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  min-height: 34px;
  width: 100%;
  border-radius: 8px;
  background: #eef3ef;
  color: var(--blue);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.queue-main {
  display: grid;
  gap: 3px;
  align-content: center;
  min-width: 0;
  min-height: 42px;
}

.queue-item strong,
.contact-title {
  display: block;
  overflow-wrap: anywhere;
}

.queue-item strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.16;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.queue-item span,
.contact-meta,
.field-label {
  color: var(--muted);
  font-size: 13px;
}

.queue-main > span {
  display: block;
  min-width: 0;
  line-height: 1.16;
  overflow-wrap: anywhere;
}

.review-panel {
  grid-area: review;
  padding: 16px;
}

.review-panel.enrichment-active {
  border-color: rgba(47, 125, 92, 0.42);
}

.review-panel.enrichment-active .contact-card {
  background: #f7fbf8;
  border-color: rgba(47, 125, 92, 0.32);
}

.review-panel.recording-active .contact-card {
  border-color: rgba(185, 80, 67, 0.42);
  box-shadow: inset 0 0 0 2px rgba(185, 80, 67, 0.08);
}

.review-panel.processing-active .contact-card {
  border-color: rgba(21, 52, 66, 0.34);
  background: #f7fafa;
}

.contact-card {
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fbfcfb;
  margin-bottom: 14px;
}

.contact-kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 3px 9px;
  font-size: 13px;
  color: var(--muted);
  background: #fff;
}

.pill.good {
  border-color: rgba(47, 125, 92, 0.32);
  color: var(--green);
}

.pill.warn {
  border-color: rgba(185, 119, 34, 0.32);
  color: var(--amber);
}

.pill.bad {
  border-color: rgba(185, 80, 67, 0.32);
  color: var(--red);
}

.contact-title {
  margin: 0 0 12px;
  max-width: 100%;
  font-size: 30px;
  line-height: 1.12;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.contact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.contact-field {
  min-height: 58px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  overflow-wrap: anywhere;
}

.field-value {
  margin-top: 3px;
  font-weight: 650;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.focus-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.action-button,
.focus-button {
  min-height: 48px;
  font-weight: 700;
}

.focus-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.action-button.keep {
  border-color: rgba(47, 125, 92, 0.45);
  color: var(--green);
}

.action-button.later {
  border-color: rgba(185, 119, 34, 0.45);
  color: var(--amber);
}

.action-button.duplicate {
  border-color: rgba(103, 80, 164, 0.4);
  color: var(--violet);
}

.action-button.enrich {
  border-color: rgba(21, 52, 66, 0.36);
  color: var(--blue);
}

.focus-button.rank-s.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.focus-button.rank-a {
  border-color: rgba(47, 125, 92, 0.45);
  color: var(--green);
}

.focus-button.rank-a.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.focus-button.rank-b {
  border-color: rgba(185, 119, 34, 0.45);
  color: var(--amber);
}

.focus-button.rank-b.active {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}

.focus-button.rank-c {
  border-color: rgba(102, 115, 122, 0.35);
  color: var(--muted);
}

.focus-button.rank-c.active {
  background: var(--muted);
  border-color: var(--muted);
  color: #fff;
}

.focus-button.rank-d {
  border-color: rgba(185, 80, 67, 0.45);
  color: var(--red);
}

.focus-button.rank-d.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.action-button.trash {
  border-color: rgba(185, 80, 67, 0.45);
  color: var(--red);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.detail-grid label,
.note-field {
  display: grid;
  gap: 5px;
}

.detail-grid span,
.note-field span {
  color: var(--muted);
  font-size: 13px;
}

.note-field {
  margin-bottom: 12px;
}

.note-field textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.35;
}

.audio-row {
  flex-wrap: wrap;
  min-height: 44px;
  margin-bottom: 12px;
}

.voice-log {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
  margin-bottom: 12px;
  padding: 10px;
}

.voice-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.voice-log-head strong {
  color: var(--ink);
  font-size: 14px;
}

.voice-log-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  margin-top: 8px;
  padding-right: 2px;
}

.voice-log-item {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.voice-log-meta,
.voice-log-applied {
  color: var(--muted);
  font-size: 12px;
}

.voice-log-item p {
  margin-top: 3px;
  line-height: 1.35;
}

.voice-log-applied {
  margin-top: 4px;
}

#recordTimer {
  min-width: 54px;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}

.audio-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(21, 52, 66, 0.18);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.audio-spinner[hidden] {
  display: none;
}

#audioState {
  flex: 1 1 180px;
}

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

.nav-row {
  justify-content: flex-end;
}

.nav-row .primary {
  min-width: 130px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  color: var(--muted);
}

.error-state {
  align-content: center;
  gap: 10px;
  text-align: center;
}

.error-state strong {
  color: var(--ink);
  font-size: 18px;
}

.error-state span {
  max-width: 360px;
  font-size: 13px;
  line-height: 1.35;
}

.loading-state {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 220px;
  align-content: center;
  color: var(--muted);
  text-align: center;
}

.loading-logo {
  width: min(220px, 64vw);
  aspect-ratio: 1218 / 1328;
  object-fit: contain;
  border-radius: 28px;
  filter: drop-shadow(0 14px 24px rgba(21, 52, 66, 0.14));
}

.loading-state strong {
  color: var(--ink);
  font-size: 18px;
}

.loading-state span:last-child {
  font-size: 13px;
}

.loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(21, 52, 66, 0.16);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@media (max-width: 980px) {
  .reward-panel {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "review"
      "queue";
  }

  .review-panel {
    grid-area: review;
    order: 1;
  }

  .queue-panel {
    grid-area: queue;
    order: 2;
    position: static;
  }

  .queue-list {
    max-height: min(46vh, 520px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .score-strip,
  .contact-grid,
  .detail-grid {
    grid-template-columns: 1fr 1fr;
  }

  .score-strip {
    gap: 8px;
  }

  .score-strip > div {
    padding: 10px;
  }

  .metric-value {
    font-size: 22px;
  }

  .review-panel,
  .queue-panel {
    padding: 10px;
  }

  .queue-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    position: static;
    height: auto;
    max-height: none;
    overflow: hidden;
    margin-bottom: 10px;
  }

  .queue-list {
    min-height: 190px;
    max-height: 42vh;
    max-height: 42dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .queue-item {
    min-height: 62px;
    align-items: stretch;
  }

  .contact-card {
    min-height: 220px;
    padding: 14px;
  }

  .contact-title {
    font-size: 25px;
  }

  .action-grid {
    grid-template-columns: 1fr 1fr;
  }

  .focus-grid {
    grid-template-columns: 1fr 1fr;
  }

  .action-button,
  .focus-button,
  .text-button,
  .detail-grid select,
  .detail-grid input {
    min-height: 48px;
  }

  .nav-row .text-button {
    flex: 1;
  }
}

@media (max-width: 440px) {
  .topbar {
    gap: 10px;
  }

  .brand-logo {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 21px;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .auth-actions .text-button {
    flex: 1 1 120px;
  }

  .auth-actions .primary {
    margin-left: 0;
  }

  .score-strip,
  .contact-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .contact-title {
    font-size: 23px;
  }

  .search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 92px;
  }

  .queue-list {
    min-height: 260px;
  }

  .queue-item {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 8px;
    padding: 8px 9px;
  }

  .queue-number {
    min-height: 44px;
    font-size: 12px;
  }

  .queue-item strong {
    font-size: 14px;
    line-height: 1.15;
  }

  .queue-main > span {
    font-size: 12px;
    line-height: 1.15;
  }

  .search-row .jump-button,
  .search-row select {
    width: 100%;
    flex-basis: auto;
  }

  .audio-row .text-button {
    flex: 1 1 150px;
  }
}
