/* ===========================================================================
   Kezzo — служебная панель шлюза WhatsApp.

   Токены и приёмы повторяют kezzo-frontend: Manrope + Unbounded, оранжевый
   акцент, зерно поверх страницы, угловые засечки. Панель служебная, но она
   часть продукта, и выглядеть должна так же.
   =========================================================================== */

:root {
  --background: hsl(36 20% 97%);
  --foreground: hsl(24 20% 10%);
  --card: hsl(0 0% 100%);
  --muted: hsl(30 12% 93%);
  --muted-foreground: hsl(24 8% 42%);
  --primary: hsl(19 100% 50%);
  --primary-foreground: hsl(0 0% 100%);
  --border: hsl(30 10% 88%);
  --input: hsl(30 10% 85%);
  --success: hsl(160 84% 33%);
  --warning: hsl(38 92% 45%);
  --destructive: hsl(0 72% 51%);
  --radius: 0.9rem;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--background);
  color: var(--foreground);
  font-family: "Manrope", system-ui, sans-serif;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* Зерно поверх всей страницы — тот же приём, что на лендинге. */
.grain-fixed {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --- типографика ---------------------------------------------------------- */

.marker {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--primary);
  font-weight: 600;
}
.marker::before {
  content: "";
  width: 28px;
  height: 1px;
  background: var(--primary);
}

.field-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  font-weight: 600;
}

.field-hint {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted-foreground);
}

/* --- экран входа ---------------------------------------------------------- */

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  animation: fade-up 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Крупные угловые скобки — как у формы заявки на лендинге. */
.frame-corners { position: relative; }
.frame-corners::before,
.frame-corners::after {
  content: "";
  position: absolute;
  width: 44px;
  height: 44px;
  pointer-events: none;
}
.frame-corners::before {
  top: -1px; left: -1px;
  border-top: 2px solid var(--primary);
  border-left: 2px solid var(--primary);
  border-top-left-radius: var(--radius);
}
.frame-corners::after {
  bottom: -1px; right: -1px;
  border-bottom: 2px solid var(--primary);
  border-right: 2px solid var(--primary);
  border-bottom-right-radius: var(--radius);
}

.auth-title {
  font-family: "Unbounded", "Manrope", sans-serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 18px;
}

.auth-sub {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted-foreground);
}

.auth-note {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted-foreground);
}

.stack { margin-top: 26px; display: grid; gap: 18px; }

/* --- поля ----------------------------------------------------------------- */

.field { display: block; }

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  margin-top: 6px;
  padding: 11px 13px;
  font-family: inherit;
  font-size: 14px;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, textarea:focus { border-color: var(--primary); }
input::placeholder, textarea::placeholder { color: hsl(24 8% 62%); }
textarea { resize: vertical; line-height: 1.55; }

/* --- кнопки --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, opacity 0.2s;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 12px; }

.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover:not(:disabled) { background: hsl(19 100% 45%); }

.btn-ghost { background: transparent; color: var(--muted-foreground); border-color: var(--border); }
.btn-ghost:hover { background: var(--muted); color: var(--foreground); }

.btn-danger { background: transparent; color: var(--destructive); border-color: hsl(0 72% 51% / 0.35); }
.btn-danger:hover { background: hsl(0 72% 51% / 0.07); }

/* --- шапка ---------------------------------------------------------------- */

.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px 22px;
  background: hsl(0 0% 100% / 0.85);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: baseline; gap: 9px; }
.brand-name {
  font-family: "Unbounded", sans-serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-sub { font-size: 12px; color: var(--muted-foreground); }

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  background: var(--muted);
  color: var(--muted-foreground);
}
.pill-dot {
  width: 7px; height: 7px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}
.pill.connected { background: hsl(160 84% 33% / 0.12); color: var(--success); }
.pill.connected .pill-dot { animation: blink 1.8s ease-in-out infinite; }
.pill.scan_qr { background: hsl(38 92% 45% / 0.14); color: var(--warning); }

/* --- вкладки -------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 14px 22px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted-foreground);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}
.tab:hover { background: var(--muted); color: var(--foreground); }
.tab.active { background: var(--primary); color: var(--primary-foreground); }

/* --- содержимое ----------------------------------------------------------- */

.content {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 22px 40px;
}

.tab-panel { animation: fade-up 0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }

.grid-2 { display: grid; gap: 16px; }
@media (min-width: 860px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  min-width: 0;
}
.card-narrow { max-width: 560px; }
.card-center { text-align: center; display: flex; flex-direction: column; }

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

.card-title {
  font-family: "Unbounded", sans-serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-sub {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted-foreground);
}

.card-foot { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.hint { margin-top: 10px; font-size: 11.5px; line-height: 1.55; color: var(--muted-foreground); }

/* --- состояние подключения ------------------------------------------------ */

.state {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 16px;
  border-radius: 12px;
  background: var(--muted);
}
.state-dot {
  width: 10px; height: 10px;
  border-radius: 999px;
  background: var(--muted-foreground);
  flex-shrink: 0;
}
.state-text {
  font-family: "Unbounded", sans-serif;
  font-size: 14px;
  font-weight: 600;
}
.state.is-connected { background: hsl(160 84% 33% / 0.1); }
.state.is-connected .state-dot { background: var(--success); animation: blink 1.8s ease-in-out infinite; }
.state.is-connected .state-text { color: var(--success); }
.state.is-waiting { background: hsl(38 92% 45% / 0.12); }
.state.is-waiting .state-dot { background: var(--warning); }
.state.is-waiting .state-text { color: var(--warning); }

.rows { margin-top: 16px; }
.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.row:last-child { border-bottom: none; }
.row dt { color: var(--muted-foreground); flex-shrink: 0; }
.row dd { font-weight: 500; text-align: right; word-break: break-all; }

/* --- QR ------------------------------------------------------------------- */

.qr {
  margin-top: 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 300px;
  padding: 22px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--card);
  transition: background-color 0.3s;
}
.qr img {
  width: 100%;
  max-width: 240px;
  height: auto;
  border-radius: 10px;
}
.qr-text { font-size: 13px; color: var(--muted-foreground); }
.qr-done { font-family: "Unbounded", sans-serif; font-size: 15px; font-weight: 600; color: var(--success); }
.qr.is-connected { background: hsl(160 84% 33% / 0.07); border-style: solid; border-color: hsl(160 84% 33% / 0.28); }

.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

/* --- сообщения ------------------------------------------------------------ */

.alert {
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 10px;
  border: 1px solid transparent;
}
.alert-error { background: hsl(0 72% 51% / 0.07); color: var(--destructive); border-color: hsl(0 72% 51% / 0.25); }
.alert-success { background: hsl(160 84% 33% / 0.09); color: var(--success); border-color: hsl(160 84% 33% / 0.25); }

/* --- таблица -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  padding: 9px 12px 9px 0;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 12px 11px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table tr:last-child td { border-bottom: none; }
.table .msg { max-width: 380px; color: var(--muted-foreground); word-break: break-word; }
.table .time { color: var(--muted-foreground); white-space: nowrap; }
.table .phone { font-weight: 600; white-space: nowrap; }
.empty { text-align: center; color: var(--muted-foreground); padding: 28px 0; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  border-radius: 6px;
  white-space: nowrap;
}
.badge-sent { background: hsl(160 84% 33% / 0.12); color: var(--success); }
.badge-failed { background: hsl(0 72% 51% / 0.1); color: var(--destructive); }

/* --- подвал --------------------------------------------------------------- */

.foot {
  padding: 20px 22px 28px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted-foreground);
  border-top: 1px solid var(--border);
}

/* --- анимации ------------------------------------------------------------- */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 560px) {
  .topbar { padding: 14px 16px; }
  .tabs { padding: 12px 16px 0; }
  .content { padding: 16px 16px 32px; }
  .card { padding: 18px; }
  .auth-card { padding: 30px 24px; }
}
