:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #17202a;
  --muted: #637083;
  --line: #d9e0e8;
  --accent: #0f8b8d;
  --accent-dark: #0b6e70;
  --ink: #202939;
  --good: #20845a;
  --warn: #b46b08;
  --bad: #bd3f37;
  --blue: #3568d4;
  --shadow: 0 16px 45px rgba(19, 32, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 139, 141, 0.14), transparent 42%),
    linear-gradient(315deg, rgba(53, 104, 212, 0.11), transparent 48%),
    #eef3f6;
}

.login-panel {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark.small {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

.login-panel h1 {
  margin: 22px 0 8px;
  font-size: 30px;
  letter-spacing: 0;
}

.login-panel p {
  margin: 0;
  color: var(--muted);
}

.login-form,
.stack-form {
  display: grid;
  gap: 14px;
  margin-top: 26px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  padding: 11px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.primary-button,
.ghost-button,
.nav-item,
.chat-reply button,
.login-form button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  padding: 0 15px;
  font-weight: 750;
}

.primary-button,
.chat-reply button,
.login-form button {
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover,
.chat-reply button:hover,
.login-form button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #ffffff;
}

.ghost-button:hover {
  border-color: #bcc8d5;
  background: var(--panel-soft);
}

.form-error {
  min-height: 18px;
  color: var(--bad);
  font-size: 13px;
}

.login-hint {
  margin-top: 18px !important;
  font-size: 13px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 22px 16px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar-head strong,
.sidebar-head span {
  display: block;
}

.sidebar-head span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

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

.nav-item {
  width: 100%;
  text-align: left;
  color: var(--muted);
  background: transparent;
}

.nav-item:hover,
.nav-item.active {
  color: var(--text);
  background: #eaf4f4;
}

.sidebar > .ghost-button {
  margin-top: auto;
}

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

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

.topbar p {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(19, 32, 48, 0.04);
}

.metric {
  padding: 18px;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 8px 0 2px;
  font-size: 34px;
  letter-spacing: 0;
}

.analytics-grid,
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.45fr);
  gap: 16px;
}

.keys-layout,
.products-layout,
.settings-layout {
  display: grid;
  gap: 16px;
}

.settings-layout {
  max-width: 1100px;
}

.content-grid {
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel.wide {
  grid-column: span 1;
}

.panel.single {
  max-width: 1000px;
}

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

.panel-head h3,
.chat-head h3 {
  margin: 0 0 5px;
  font-size: 18px;
  letter-spacing: 0;
}

.panel-head p,
.chat-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.chart {
  min-height: 280px;
}

.line-chart svg,
.bar-chart svg {
  display: block;
  width: 100%;
  height: 280px;
}

.axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.point-label {
  fill: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  max-width: 420px;
}

.date-control input {
  min-width: 150px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 12px;
}

.chart-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  padding: 0 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.legend-item:hover,
.legend-item.active {
  border-color: var(--legend-color);
  background: #ffffff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--legend-color) 18%, transparent);
}

.legend-item.muted {
  opacity: 0.45;
}

.legend-item i,
.product-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 999px;
  background: var(--legend-color, var(--product-color, var(--accent)));
}

.product-dot {
  display: inline-block;
  margin-right: 8px;
  vertical-align: 1px;
}

.date-control {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.date-control input {
  min-height: 42px;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  text-transform: none;
}

.chart-empty,
.empty-state {
  display: grid;
  min-height: 160px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.status-list,
.product-list,
.product-tabs,
.chat-list,
.integration-grid {
  display: grid;
  gap: 10px;
}

.status-row,
.product-row,
.chat-row,
.integration-grid div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  padding: 12px;
}

.product-row {
  align-items: flex-start;
}

.product-tab {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  padding: 14px;
  color: var(--text);
  text-align: left;
}

.product-tab:hover,
.product-tab.active {
  border-color: var(--accent);
  background: #eaf4f4;
}

.product-row strong,
.product-row span,
.product-tab strong,
.product-tab span,
.chat-row strong,
.chat-row span,
.integration-grid strong,
.integration-grid span {
  display: block;
}

.product-row span,
.product-tab span,
.integration-grid span {
  color: var(--muted);
  font-size: 13px;
}

.chat-row span:not(.tag) {
  color: var(--muted);
  font-size: 13px;
}

.product-detail-stats {
  display: grid;
  justify-items: end;
  gap: 4px;
  color: var(--muted);
  white-space: nowrap;
}

.product-detail-stats span {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
}

.listing-section {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.listing-section h4 {
  margin: 0 0 4px;
  font-size: 16px;
}

.listing-section p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.listing-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 0.5fr) minmax(180px, 1fr) 150px 130px;
  gap: 10px;
  align-items: center;
}

.create-details summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 800;
}

.create-details .stack-form {
  margin-top: 18px;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
}

.tag.available,
.tag.paid,
.tag.closed {
  color: #15533a;
  background: #dff3ea;
}

.tag.issued,
.tag.waiting_payment,
.tag.key_sent {
  color: #704004;
  background: #ffe7bf;
}

.tag.problem,
.tag.manual {
  color: #8d2922;
  background: #ffe0dd;
}

.tag.new,
.tag.waiting_activation,
.tag.draft {
  color: #254a9a;
  background: #e1eaff;
}

.tag.active {
  color: #15533a;
  background: #dff3ea;
}

.tag.paused {
  color: #704004;
  background: #ffe7bf;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

.compact-table {
  min-width: 760px;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.key-mask {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}

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

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

.table-filters select {
  width: auto;
  min-width: 190px;
}

#keyForm {
  grid-template-columns: 280px minmax(260px, 1fr) 190px;
  align-items: end;
}

#keyValue {
  min-height: 66px;
}

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

.row-actions button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 750;
}

.chat-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  min-height: calc(100vh - 116px);
}

.chat-list-panel,
.chat-panel {
  display: flex;
  min-height: 620px;
  flex-direction: column;
}

.chat-row {
  width: 100%;
  border: 1px solid var(--line);
  text-align: left;
  background: var(--panel-soft);
}

.chat-row.active {
  border-color: var(--accent);
  background: #eaf4f4;
}

.chat-row .tag {
  max-width: 155px;
  white-space: normal;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

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

.message-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 18px 4px;
}

.message {
  max-width: min(680px, 88%);
  border-radius: 8px;
  padding: 11px 13px;
  line-height: 1.45;
}

.message.client {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.message.agent {
  align-self: flex-end;
  color: #ffffff;
  background: var(--accent);
}

.message.owner {
  align-self: flex-end;
  color: #ffffff;
  background: var(--ink);
}

.message small {
  display: block;
  margin-top: 5px;
  opacity: 0.72;
  font-size: 11px;
}

.chat-reply {
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.chat-reply input {
  flex: 1;
}

.script-steps {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 22px;
}

.script-steps li {
  line-height: 1.55;
}

.integration-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.integration-grid div {
  display: grid;
  min-height: 104px;
  align-content: start;
  justify-content: stretch;
  gap: 8px;
}

.integration-grid strong {
  font-size: 16px;
  line-height: 1.18;
}

.integration-grid span {
  line-height: 1.35;
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .analytics-grid,
  .content-grid,
  .chat-layout {
    grid-template-columns: 1fr;
  }

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

  .listing-form,
  #keyForm {
    grid-template-columns: 1fr;
  }

  .chat-list-panel,
  .chat-panel {
    min-height: auto;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    gap: 14px;
    padding: 16px;
  }

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

  .nav-item {
    text-align: center;
  }

  .topbar,
  .panel-head,
  .chat-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .chat-actions,
  .chart-controls {
    justify-content: stretch;
  }

  .top-actions button,
  .chat-actions button,
  .date-control,
  .date-control input {
    width: 100%;
  }

  .metric-grid,
  .integration-grid {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 16px;
  }

  .chat-layout {
    min-height: 0;
  }

  .chat-list-panel,
  .chat-panel {
    min-height: 0;
  }

  .message {
    max-width: 100%;
  }

  .product-tab,
  .chat-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .product-detail-stats {
    justify-items: start;
    white-space: normal;
  }

  .table-filters,
  .table-filters select {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .login-panel {
    padding: 24px;
  }

  .sidebar-head {
    padding-bottom: 12px;
  }

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

  .nav-item,
  .sidebar > .ghost-button {
    min-height: 38px;
    padding: 0 10px;
  }

  .main {
    padding: 12px;
  }

  .topbar h2 {
    font-size: 24px;
  }

  .panel,
  .metric {
    padding: 14px;
  }

  .metric strong {
    font-size: 28px;
  }

  .chat-reply {
    flex-direction: column;
  }

  .chat-reply button {
    width: 100%;
  }

  .message-list {
    padding: 14px 0;
  }

  .message {
    font-size: 14px;
  }
}
