:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --ink: #17211f;
  --muted: #6b7774;
  --line: #dce5e2;
  --blue: #315d83;
  --green: #1f7a62;
  --amber: #b7791f;
  --red: #b42318;
  --soft-blue: #e7f0f8;
  --soft-green: #e7f5ef;
  --soft-amber: #fff3d6;
  --soft-red: #fde8e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #eef3f1;
}

.auth-screen.hidden { display: none; }

.auth-panel {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 50px rgba(23, 33, 31, 0.12);
}

.auth-panel h2 { margin: 18px 0 6px; }
.auth-panel > p { margin: 0 0 20px; color: var(--muted); }
.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 6px; }
.auth-form input { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 6px; }
.auth-error { min-height: 18px; color: var(--red); font-size: 13px; }
.current-user { color: var(--muted); font-size: 13px; }

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

.app {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #182724;
  color: #f5fbf9;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: #e7f5ef;
  color: #163d33;
  font-weight: 800;
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand p {
  margin: 4px 0 0;
  color: #b7c7c3;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-btn {
  border: 0;
  background: transparent;
  color: #d7e3df;
  text-align: left;
  padding: 11px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.nav-btn:hover,
.nav-btn.active {
  background: #26413b;
  color: #ffffff;
}

.sync-box {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid #34504a;
}

.primary-btn,
.ghost-btn,
.ghost-dark-btn,
.secondary-link {
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.primary-btn {
  background: var(--green);
  color: white;
}

.secondary-link {
  color: #d7e3df;
  border: 1px solid #45645d;
}

.ghost-btn {
  background: #edf3f1;
  color: #263b36;
}

.ghost-dark-btn {
  background: #304c45;
  color: #f5fbf9;
  border: 1px solid #45645d;
}

#syncInfo,
#googleSyncInfo,
#yandexSyncInfo {
  color: #b7c7c3;
  font-size: 12px;
}

.google-sync-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.google-sync-actions button {
  min-width: 0;
  white-space: normal;
}

.setup-note {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf9;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 14px;
}

.check-field input {
  width: 18px;
  height: 18px;
}

.tax-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #34504a;
  border-radius: 8px;
  background: #213630;
}

.tax-title {
  font-weight: 700;
  color: #ffffff;
}

.tax-box label {
  display: grid;
  gap: 4px;
}

.tax-box span {
  color: #b7c7c3;
  font-size: 12px;
}

.tax-box input {
  width: 100%;
  border: 1px solid #45645d;
  background: #15231f;
  color: #ffffff;
  border-radius: 6px;
  padding: 8px 9px;
}

.content {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.topbar h2 {
  margin: 0;
  font-size: 26px;
}

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

.search {
  min-width: 320px;
}

.search input,
.filters select,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 6px;
  padding: 10px 11px;
  outline: none;
}

.search input:focus,
.filters select:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 98, 0.13);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

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

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.metric.net {
  background: #e7f5ef;
  border-color: #b9dfd0;
}

.metric.tax {
  background: #fff3d6;
  border-color: #ecd18d;
}

.filters {
  display: flex;
  gap: 10px;
  margin: 8px 0 12px;
}

.filters select {
  max-width: 260px;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 230px);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf3f1;
  color: #40504d;
  font-size: 12px;
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #eef3f1;
  vertical-align: top;
}

.data-table tr {
  cursor: pointer;
}

.data-table tr:hover {
  background: #f8fbfa;
}

.id-cell,
.money-cell,
.date-cell {
  white-space: nowrap;
}

.name-cell {
  min-width: 340px;
  max-width: 520px;
}

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

.pill {
  display: inline-flex;
  max-width: 230px;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  line-height: 1.2;
  white-space: normal;
}

.pill.default {
  background: #edf3f1;
  color: #40504d;
}

.pill.green {
  background: var(--soft-green);
  color: #166044;
}

.pill.blue {
  background: var(--soft-blue);
  color: #214f78;
}

.pill.amber {
  background: var(--soft-amber);
  color: #805300;
}

.pill.red {
  background: var(--soft-red);
  color: var(--red);
}

.hidden {
  display: none !important;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(720px, 100vw);
  height: 100vh;
  background: white;
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(15, 25, 22, 0.18);
  transform: translateX(105%);
  transition: transform 0.18s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.drawer h3 {
  margin: 3px 0 0;
  font-size: 20px;
}

.icon-btn {
  border: 0;
  background: #edf3f1;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.drawer-body {
  overflow: auto;
  padding: 18px 22px 24px;
}

.shade {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 18, 0.22);
  z-index: 10;
}

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

.field.full {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  margin-bottom: 5px;
  color: #485956;
  font-size: 12px;
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0 18px;
}

.workflow-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.warehouse-panel {
  margin: 14px 0;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.warehouse-label {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.warehouse-label img {
  width: 88px;
  height: 88px;
  border: 1px solid var(--line);
}

.warehouse-label strong,
.warehouse-label small {
  display: block;
  margin-top: 4px;
}

.warehouse-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.warehouse-history {
  margin-top: 14px;
}

@media (max-width: 680px) {
  .warehouse-label { grid-template-columns: 72px minmax(0, 1fr); }
  .warehouse-label img { width: 72px; height: 72px; }
  .warehouse-label .ghost-btn { grid-column: 1 / -1; }
  .warehouse-actions { grid-template-columns: 1fr; }
}

.workflow-panel > div:first-child {
  display: grid;
  gap: 3px;
}

.workflow-warning {
  flex: 1;
  color: #805300;
  font-size: 13px;
}

.workflow-next {
  margin-left: auto;
}

.detail {
  background: #f7faf9;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.detail span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail strong {
  display: block;
  margin-top: 4px;
}

.save-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.events {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.event {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 0;
}

.inbox-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.inbox-controls {
  display: flex;
  flex: 1;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.segmented-control {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.segment {
  border: 0;
  border-right: 1px solid var(--line);
  background: white;
  color: var(--muted);
  padding: 9px 11px;
  cursor: pointer;
  white-space: nowrap;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: #153f3a;
  color: white;
}

.segment span {
  display: inline-block;
  min-width: 18px;
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 9px;
  background: rgba(21, 63, 58, 0.1);
  font-size: 11px;
  text-align: center;
}

.segment.active span {
  background: rgba(255, 255, 255, 0.18);
}

.inbox-search {
  flex: 1 1 280px;
  max-width: 430px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  background: white;
}

.inbox-list {
  display: grid;
  gap: 8px;
}

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

.request-summary > div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.request-summary span,
.request-summary strong {
  display: block;
}

.request-summary span {
  color: var(--muted);
  font-size: 12px;
}

.request-summary strong {
  margin-top: 3px;
  font-size: 20px;
}

.request-summary .attention {
  border-color: #e7b6ae;
  background: #fff6f4;
  color: var(--red);
}

.preliminary-list {
  display: grid;
  gap: 6px;
}

.preliminary-row {
  width: 100%;
  display: grid;
  grid-template-columns: 110px minmax(150px, 0.8fr) minmax(240px, 1.5fr) minmax(145px, 0.8fr) minmax(145px, 0.8fr) 36px;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  background: white;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.preliminary-row:hover {
  border-color: #8ea9a4;
  background: #fbfdfc;
}

.preliminary-row.overdue {
  border-left: 4px solid var(--red);
  background: #fffafa;
}

.overdue-text {
  color: var(--red) !important;
  font-weight: 700;
}

.automation-check {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f7faf9;
}

.automation-check.green { border-left: 4px solid #2e7b64; }
.automation-check.amber { border-left: 4px solid #b67a16; }
.automation-check.red { border-left: 4px solid var(--red); }
.automation-check span { color: var(--muted); }

.preliminary-row span,
.preliminary-row strong,
.preliminary-row small {
  min-width: 0;
}

.preliminary-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.request-text-cell {
  overflow-wrap: anywhere;
}

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

.conversation-message {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 3px solid #8da5a1;
  border-radius: 6px;
  background: #f8faf9;
}

.conversation-message.outbound {
  border-left-color: #2e7b64;
  background: #f0f8f5;
}

.conversation-message div {
  color: var(--muted);
  font-size: 12px;
}

.conversation-message p {
  margin: 7px 0 0;
  white-space: pre-wrap;
}

@media (max-width: 1050px) {
  .preliminary-row {
    grid-template-columns: 90px minmax(140px, 0.8fr) minmax(220px, 1.5fr) minmax(140px, 0.8fr);
  }
  .preliminary-row > :nth-child(5),
  .preliminary-row > :nth-child(6) { grid-column: auto; }
}

@media (max-width: 720px) {
  .request-summary { grid-template-columns: 1fr; }
  .preliminary-row { grid-template-columns: 1fr; }
  .request-count { text-align: left; }
}

.message {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.message-head {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.message-meta {
  margin-bottom: 8px;
}

.message-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.2;
}

.message-status.new {
  background: var(--soft-amber);
  color: #805300;
}

.message-status.attached {
  background: var(--soft-green);
  color: #166044;
}

.message-status.ignored {
  background: #edf3f1;
  color: #596966;
}

.message-status.suggestion {
  margin-left: 6px;
  background: #e4f2ee;
  color: #155c4c;
}

.suggestion-reasons {
  margin: -2px 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.message-text {
  white-space: pre-wrap;
}

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

.create-from-chain {
  margin-right: auto;
}

.attach-preview {
  margin-bottom: 14px;
}

.linked-messages {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.linked-message {
  background: #f7faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}

.confirmation-area {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.section-head,
.confirmation-card,
.confirmation-actions,
.confirmation-fields {
  display: flex;
  align-items: center;
}

.section-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.section-head h3,
.section-head p {
  margin: 0;
}

.section-head h3 {
  font-size: 16px;
}

.section-head p,
.confirmation-meta,
.confirmation-fields,
.empty-note {
  color: var(--muted);
  font-size: 12px;
}

.confirmation-list {
  display: grid;
  gap: 8px;
}

.confirmation-card {
  justify-content: space-between;
  gap: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--green);
  border-radius: 7px;
  background: white;
}

.confirmation-main {
  min-width: 0;
}

.confirmation-text {
  margin-top: 5px;
}

.confirmation-fields,
.confirmation-actions {
  gap: 8px;
  flex-wrap: wrap;
}

.confirmation-fields {
  margin-top: 7px;
}

.confirmation-actions {
  flex: 0 0 auto;
}

.empty-note {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  background: #f7faf9;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    min-width: 0;
    width: 100%;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .inbox-toolbar,
  .inbox-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .confirmation-card,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented-control {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segment {
    border-bottom: 1px solid var(--line);
  }

  .inbox-search {
    flex-basis: auto;
    max-width: none;
    width: 100%;
  }
}
