:root {
  --ink: #191816;
  --muted: #6f6a61;
  --line: #dfddd7;
  --soft: #f6f4ef;
  --surface: #fffefa;
  --green: #16795f;
  --green-dark: #0f5e49;
  --red: #b84848;
  --amber: #b57922;
  --coal: #24211d;
  --mint: #dff3eb;
  --rose: #f5dfdd;
  --shadow: 0 24px 70px rgba(31, 29, 24, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(120deg, rgba(22, 121, 95, 0.12), transparent 32%),
    linear-gradient(300deg, rgba(184, 72, 72, 0.12), transparent 38%),
    #ebe7de;
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.shell {
  width: min(1480px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
}

.phone,
.admin-panel {
  background: rgba(255, 254, 250, 0.88);
  border: 1px solid rgba(25, 24, 22, 0.12);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.phone {
  min-height: 720px;
  border-radius: 30px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar,
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.admin-header h2,
.intro-block h2,
.success h2 {
  margin: 2px 0 0;
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 20px;
}

.admin-header h2 {
  font-size: 30px;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--ink);
  text-decoration: none;
}

.icon-button:hover,
.secondary:hover {
  border-color: rgba(22, 121, 95, 0.55);
}

.view {
  display: none;
  min-height: 0;
}

.view-active {
  display: block;
}

.chat {
  height: 100%;
  min-height: 620px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 14px;
  background:
    linear-gradient(180deg, rgba(22, 121, 95, 0.06), transparent 44%),
    var(--soft);
}

.message {
  max-width: 86%;
  padding: 14px 16px;
  border-radius: 8px;
  display: grid;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.application-form {
  padding: 20px;
  display: grid;
  gap: 14px;
}

.intro-block {
  padding: 10px 0 6px;
}

.intro-block h2,
.success h2 {
  font-size: 28px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 121, 95, 0.13);
}

.primary,
.secondary {
  min-height: 48px;
  border-radius: 8px;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 800;
}

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

.primary:hover {
  background: var(--green-dark);
}

.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.wide {
  width: 100%;
}

.form-state {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.success {
  min-height: 620px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.success p:last-of-type {
  margin: 0 0 12px;
  color: var(--muted);
}

.success-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 4px;
  border-radius: 50%;
  background: var(--mint);
  color: var(--green);
  display: grid;
  place-items: center;
}

.admin-panel {
  min-height: 720px;
  border-radius: 18px;
  padding-bottom: 18px;
  overflow: hidden;
}

.admin-actions {
  display: flex;
  gap: 10px;
}

.metrics {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  display: grid;
  align-content: space-between;
}

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

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.toolbar {
  padding: 0 18px 18px;
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 12px;
}

.search-field {
  position: relative;
}

.search-field input {
  height: 44px;
  padding-left: 40px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 15px;
  height: 15px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  transform: translateY(-55%);
}

.search-icon::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 2px;
  background: var(--muted);
  right: -6px;
  bottom: -3px;
  transform: rotate(45deg);
  border-radius: 2px;
}

.segments {
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.segment {
  min-width: 0;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 780;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(31, 29, 24, 0.08);
}

.crm-layout {
  padding: 0 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
  align-items: start;
}

.applications {
  display: grid;
  gap: 10px;
}

.application {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(190px, 0.8fr) minmax(220px, 1.1fr) auto;
  gap: 14px;
  align-items: start;
}

.application.selected {
  border-color: rgba(22, 121, 95, 0.65);
  box-shadow: 0 0 0 3px rgba(22, 121, 95, 0.1);
}

.person h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.person p,
.details p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.details strong {
  color: var(--ink);
}

.status {
  width: fit-content;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--mint);
  color: var(--green-dark);
}

.status.review {
  background: #efe6d5;
  color: var(--amber);
}

.status.accepted {
  background: var(--mint);
  color: var(--green-dark);
}

.status.declined {
  background: var(--rose);
  color: var(--red);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.score-badge {
  width: fit-content;
  min-width: 42px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 860;
  background: #ebe7de;
  color: var(--muted);
}

.score-badge.hot {
  background: #dff3eb;
  color: var(--green-dark);
}

.score-badge.warm {
  background: #efe6d5;
  color: var(--amber);
}

.score-badge.cold {
  background: var(--rose);
  color: var(--red);
}

.row-actions {
  display: grid;
  gap: 8px;
  min-width: 150px;
}

.row-actions select {
  min-height: 38px;
  padding: 8px 10px;
}

.empty {
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 254, 250, 0.62);
}

.drawer {
  position: sticky;
  top: 14px;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.drawer-card {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.drawer-head h3 {
  margin: 4px 0 6px;
  font-size: 22px;
  line-height: 1.05;
}

.drawer-section {
  display: grid;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.drawer-section h4 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.drawer-section p {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

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

.note-box {
  display: grid;
  gap: 8px;
}

.note-box textarea {
  min-height: 92px;
}

.ai-box {
  padding: 14px;
  border: 1px solid rgba(22, 121, 95, 0.22);
  border-radius: 8px;
  background: #f0f7f2;
}

.ai-box strong {
  font-size: 15px;
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-event {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--line);
}

.timeline-dot.timeline-ai,
.timeline-dot.timeline-message {
  background: var(--green);
}

.timeline-dot.timeline-status {
  background: var(--amber);
}

.timeline-dot.timeline-note {
  background: var(--muted);
}

.timeline-event strong {
  display: block;
  font-size: 13px;
}

.timeline-event p,
.timeline-event time {
  display: block;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.small-empty {
  min-height: 92px;
  font-size: 13px;
}

.compact-button {
  min-height: 40px;
}

.chevron-left,
.grid-icon,
.arrow-up-right,
.send-icon,
.refresh-icon,
.check-icon,
.download-icon {
  position: relative;
  display: inline-block;
}

.chevron-left {
  width: 13px;
  height: 13px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.grid-icon {
  width: 17px;
  height: 17px;
  background:
    linear-gradient(currentColor 0 0) 0 0 / 7px 7px,
    linear-gradient(currentColor 0 0) 10px 0 / 7px 7px,
    linear-gradient(currentColor 0 0) 0 10px / 7px 7px,
    linear-gradient(currentColor 0 0) 10px 10px / 7px 7px;
  background-repeat: no-repeat;
}

.arrow-up-right {
  width: 16px;
  height: 16px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
}

.arrow-up-right::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 2px;
  right: -3px;
  top: 7px;
  background: currentColor;
  transform: rotate(-45deg);
  transform-origin: right center;
}

.send-icon {
  width: 17px;
  height: 17px;
  clip-path: polygon(0 0, 100% 50%, 0 100%, 18% 58%, 62% 50%, 18% 42%);
  background: currentColor;
}

.refresh-icon {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
}

.refresh-icon::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 0;
  width: 7px;
  height: 7px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(25deg);
}

.check-icon {
  width: 22px;
  height: 12px;
  border-left: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: rotate(-45deg);
}

.download-icon {
  width: 18px;
  height: 18px;
  border-bottom: 2px solid currentColor;
}

.download-icon::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 0;
  width: 2px;
  height: 12px;
  background: currentColor;
}

.download-icon::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 7px;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 720px);
    padding: 10px 0;
  }

  .phone,
  .admin-panel {
    min-height: auto;
  }

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

  .toolbar,
  .application,
  .crm-layout {
    grid-template-columns: 1fr;
  }

  .drawer {
    position: static;
  }

  .row-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .shell {
    width: 100%;
    padding: 0;
  }

  .phone,
  .admin-panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .topbar,
  .admin-header,
  .application-form,
  .chat,
  .success {
    padding-left: 14px;
    padding-right: 14px;
  }

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

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