:root {
  color-scheme: light;
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #f8faf8;
  --border: #d9ded8;
  --text: #1f2623;
  --muted: #66736c;
  --green: #1f7a4d;
  --red: #b42318;
  --amber: #a15c07;
  --blue: #2563a8;
  --shadow: 0 1px 2px rgba(20, 26, 23, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  font-size: 15px;
}

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

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--text);
  font-weight: 700;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topnav form {
  margin: 0;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--surface-2);
}

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

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

h1 {
  font-size: 1.9rem;
}

h2 {
  font-size: 1.18rem;
}

h3 {
  margin: 18px 0 10px;
  font-size: 0.95rem;
}

.subtle {
  margin: 6px 0 0;
  color: var(--muted);
}

.period-switch {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(54px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.period-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 600;
}

.period-link.active {
  background: #e6f2eb;
  color: var(--green);
}

.metric-grid,
.compact-grid {
  display: grid;
  gap: 12px;
}

.metric-grid {
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  margin-bottom: 16px;
}

.compact-grid {
  grid-template-columns: repeat(8, minmax(118px, 1fr));
  margin: 14px 0;
}

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

.mini-metric {
  min-height: 72px;
}

.metric span,
.mini-metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.metric strong,
.mini-metric strong {
  display: block;
  margin-top: 6px;
  font-size: 1.55rem;
  line-height: 1.1;
}

.mini-metric strong {
  font-size: 1.2rem;
}

.metric small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.section-panel {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.section-title span {
  color: var(--muted);
  font-size: 0.9rem;
}

.two-column,
.three-column {
  display: grid;
  gap: 16px;
}

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

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  overflow: hidden;
  padding: 8px 9px;
  border-bottom: 1px solid #e8ece7;
  text-overflow: ellipsis;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
}

.data-table tbody tr:hover {
  background: var(--surface-2);
}

.data-table .num {
  text-align: right;
  white-space: nowrap;
}

.flow-table {
  min-width: 1100px;
}

.flow-cell {
  white-space: normal;
  word-break: break-word;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 7px;
  border-radius: 6px;
  background: #eef1ef;
  color: var(--muted);
  font-weight: 700;
}

.status.ok {
  background: #e4f4e9;
  color: var(--green);
}

.status.bad,
.status.danger {
  background: #fde8e5;
  color: var(--red);
}

.status.warning {
  background: #fff2db;
  color: var(--amber);
}

.status.muted,
.status.info {
  background: #eef1ef;
  color: var(--muted);
}

.login-shell {
  display: grid;
  min-height: calc(100vh - 104px);
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-header {
  margin-bottom: 18px;
}

.form-stack {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.field-label {
  color: var(--muted);
  font-weight: 700;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 8px;
}

.login-form {
  gap: 10px;
}

.login-submit {
  width: 100%;
}

.phone-mask-input,
.code-input {
  font-variant-numeric: tabular-nums;
}

.code-input {
  letter-spacing: 0.08em;
}

.login-code-hint {
  margin: 0 0 4px;
}

.login-secondary-actions {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.login-secondary-actions form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button,
.secondary-button,
.danger-button,
.form-control,
.btn {
  min-height: 40px;
  border-radius: 6px;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.secondary-button {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

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

.primary-button:hover,
.danger-button:hover,
.secondary-button:hover {
  text-decoration: none;
  filter: brightness(0.97);
}

.notice {
  margin: 0 0 16px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.notice.ok {
  border-color: #bce1ca;
  background: #eff9f2;
  color: var(--green);
}

.notice.bad {
  border-color: #f0c1bc;
  background: #fff4f2;
  color: var(--red);
}

.head-actions,
.form-actions,
.channel-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.form-stack {
  display: grid;
  gap: 0;
}

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

.form-grid label,
.form-stack > label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.form-grid .wide {
  grid-column: span 2;
}

.form-control {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
}

textarea.form-control {
  min-height: 96px;
  resize: vertical;
}

.check-row {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--text) !important;
}

.compact-input {
  min-width: 180px;
}

.inline-form form,
.inline-form.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-tile {
  display: grid;
  gap: 5px;
  min-height: 84px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
}

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

.message-preview {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.message-preview:last-child {
  border-bottom: 0;
}

.message-preview pre {
  margin: 10px 0;
  white-space: pre-wrap;
  font: inherit;
}

.breakable {
  overflow-wrap: anywhere;
}

@media (max-width: 1200px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .compact-grid {
    grid-template-columns: repeat(4, minmax(118px, 1fr));
  }

  .three-column {
    grid-template-columns: 1fr;
  }

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

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

  .page-head,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .compact-grid,
  .two-column,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: auto;
  }

  .section-panel {
    overflow-x: auto;
  }

  .period-switch {
    width: 100%;
  }
}
