:root {
  --ink: #16211d;
  --muted: #6d7973;
  --surface: #ffffff;
  --canvas: #f3f6f4;
  --line: #dde5e0;
  --green: #16835d;
  --green-dark: #0f6246;
  --green-soft: #e7f6ef;
  --amber: #d89028;
  --shadow: 0 16px 50px rgba(27, 55, 43, 0.08);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 15%, rgba(22, 131, 93, .14), transparent 30%),
    radial-gradient(circle at 85% 80%, rgba(216, 144, 40, .13), transparent 28%),
    #f5f8f6;
}
.login-card {
  width: min(430px, 100%);
  padding: 38px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  text-align: center;
}
.login-card h1 { margin: 4px 0 0; }
.login-card p, .login-card small { margin: 0; color: var(--muted); }
.login-card input { width: 100%; }
.form-error { color: #b43d3d; min-height: 22px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #102b22;
  color: white;
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #24a979, #137454);
  color: white;
  font-weight: 800;
  font-size: 22px;
  box-shadow: 0 8px 24px rgba(10, 93, 64, .25);
}
.brand div:last-child { display: grid; }
.brand strong { font-size: 18px; }
.brand span { color: #9cc5b5; font-size: 13px; }
.sidebar nav { display: grid; gap: 5px; }
.nav-item {
  border: 0;
  background: transparent;
  color: #b8d2c8;
  padding: 13px 15px;
  border-radius: 12px;
  text-align: right;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.1); color: white; }
.nav-item.active { box-shadow: inset -3px 0 0 #4dd29e; }
.logout { margin-top: auto; }

main { min-width: 0; padding: 0 34px 45px; }
.topbar {
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.topbar h1 { margin: 0 0 7px; font-size: 27px; }
.topbar p { margin: 0; color: var(--muted); }
.status-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
}
.status-chip span { width: 9px; height: 9px; background: #21a86f; border-radius: 50%; box-shadow: 0 0 0 4px #dff6ed; }

.page { display: none; }
.page.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: .35; transform: translateY(3px); } }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 18px; margin-bottom: 20px; }
.metric-card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 9px 30px rgba(31, 61, 48, .045);
}
.metric-card { padding: 21px; }
.metric-card span { color: var(--muted); font-size: 14px; }
.metric-card strong { display: block; margin-top: 9px; font-size: 30px; }
.metric-card small { color: var(--green); }
.panel { padding: 24px; }
.panel h2 { margin: 0 0 8px; font-size: 19px; }
.panel p { color: var(--muted); }
.panel-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 15px; }
.panel-heading h2, .panel-heading p { margin: 0 0 6px; }
.narrow { max-width: 760px; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

.button {
  border: 0;
  border-radius: 11px;
  padding: 11px 17px;
  font-weight: 650;
}
.button.primary { background: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: #eef3f0; color: var(--ink); }

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.status-row:last-child { border-bottom: 0; }
.badge { padding: 6px 10px; border-radius: 999px; font-size: 12px; background: var(--green-soft); color: var(--green-dark); }
.badge.warning { background: #fff2dc; color: #9b5d00; }

.simulator-layout { display: grid; grid-template-columns: minmax(340px, 520px) minmax(260px, 1fr); gap: 28px; align-items: start; }
.phone { overflow: hidden; background: #e9f2ed; border: 8px solid #1b2823; border-radius: 35px; min-height: 690px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.phone-header { background: #155e49; color: white; display: flex; align-items: center; gap: 10px; padding: 16px; }
.phone-header .avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: white; color: var(--green); font-weight: 800; }
.phone-header div:last-child { display: grid; }
.phone-header span { font-size: 12px; color: #bce5d5; }
.chat { flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 10px; max-height: 570px; overflow: auto; background-color: #e7eee9; background-image: radial-gradient(rgba(24, 93, 69, .07) 1px, transparent 1px); background-size: 18px 18px; }
.bubble { max-width: 85%; padding: 11px 14px; border-radius: 14px; white-space: pre-wrap; line-height: 1.65; box-shadow: 0 2px 4px rgba(0,0,0,.06); }
.bubble.incoming { align-self: flex-start; background: white; border-top-right-radius: 4px; }
.bubble.outgoing { align-self: flex-end; background: #d2f5e3; border-top-left-radius: 4px; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; background: #f8faf9; }
.composer input { border: 1px solid var(--line); border-radius: 999px; padding: 12px 16px; }
.composer button { border: 0; border-radius: 999px; background: var(--green); color: white; padding: 0 17px; }
.tips { display: grid; gap: 10px; }
.suggestion { border: 1px solid var(--line); background: white; border-radius: 12px; padding: 13px; text-align: right; }
.suggestion:hover { border-color: var(--green); background: var(--green-soft); }
.notice { padding: 13px 15px; background: #fff8e8; border: 1px solid #f4ddb0; border-radius: 12px; color: #70531d !important; line-height: 1.6; }

.stacked-form { display: grid; gap: 16px; }
.stacked-form label { display: grid; gap: 8px; font-weight: 650; }
input, textarea {
  border: 1px solid #ced9d3;
  background: white;
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--ink);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,131,93,.1); }
textarea { resize: vertical; }
.toggle-row { grid-template-columns: auto 1fr !important; align-items: center; }
.toggle-row input { width: 18px; height: 18px; accent-color: var(--green); }
.actions { display: flex; gap: 9px; }

.reply-list, .conversation-list { display: grid; gap: 10px; }
.reply-item, .conversation-item {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 14px;
  background: #fbfcfb;
}
.reply-item { cursor: pointer; }
.reply-item:hover { border-color: #9ecab9; }
.reply-item h3, .conversation-item h3 { margin: 0 0 7px; font-size: 15px; }
.reply-item p, .conversation-item p { margin: 0; font-size: 13px; line-height: 1.55; }
.reply-meta { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.danger-link { border: 0; background: transparent; color: #b13f3f; }
.conversation-head { display: flex; justify-content: space-between; gap: 12px; }
.conversation-messages { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 5px; }
.conversation-messages div { font-size: 13px; color: var(--muted); }
.conversation-messages strong { color: var(--ink); }
.empty { color: var(--muted); text-align: center; padding: 35px; }

.conversation-panel { padding-bottom: 18px; }
.conversation-tools { display: grid; grid-template-columns: minmax(220px, 1fr) 190px; gap: 10px; margin-bottom: 14px; }
.conversation-workspace {
  display: grid;
  grid-template-columns: minmax(260px, .75fr) minmax(420px, 1.6fr);
  min-height: 610px;
  border: 1px solid var(--line);
  border-radius: 15px;
  overflow: hidden;
  background: #f7faf8;
}
.conversation-list {
  align-content: start;
  padding: 12px;
  border-left: 1px solid var(--line);
  max-height: 680px;
  overflow: auto;
}
.conversation-item {
  width: 100%;
  text-align: right;
  color: var(--ink);
  cursor: pointer;
}
.conversation-item:hover, .conversation-item.selected { border-color: #82bda6; background: var(--green-soft); }
.conversation-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conversation-list-head span { color: var(--muted); font-size: 11px; }
.conversation-item p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 8px 0; }
.conversation-status { display: inline-block; border-radius: 999px; padding: 3px 8px; font-size: 11px; }
.status-human { background: #fff0d7; color: #8d5708; }
.status-bot { background: var(--green-soft); color: var(--green-dark); }
.status-closed { background: #ecefed; color: #68726d; }
.conversation-detail { min-width: 0; display: flex; flex-direction: column; background: #eef4f0; }
.detail-header {
  min-height: 70px;
  padding: 13px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: white;
  border-bottom: 1px solid var(--line);
}
.detail-header h3 { margin: 0 0 4px; }
.detail-header span { color: var(--muted); font-size: 12px; }
.detail-messages { flex: 1; max-height: 520px; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.detail-message { max-width: 84%; padding: 10px 13px; border-radius: 13px; box-shadow: 0 2px 6px rgba(25,55,42,.06); }
.detail-message.customer { align-self: flex-start; background: white; border-top-right-radius: 3px; }
.detail-message.agent { align-self: flex-end; background: #d8f5e6; border-top-left-radius: 3px; }
.detail-message p { margin: 7px 0 0; color: var(--ink); white-space: pre-wrap; line-height: 1.65; overflow-wrap: anywhere; }
.message-meta { display: flex; justify-content: space-between; gap: 15px; font-size: 11px; }
.message-meta span { color: var(--muted); }
.agent-composer { display: grid; grid-template-columns: 1fr auto; gap: 9px; padding: 12px; background: white; border-top: 1px solid var(--line); }
.agent-composer textarea { min-height: 48px; max-height: 120px; resize: none; }
.ad-cards { display: grid; gap: 8px; margin-top: 10px; }
.ad-card { display: grid; grid-template-columns: 68px 1fr; gap: 10px; padding: 8px; border: 1px solid #cfe0d7; border-radius: 11px; background: white; color: var(--ink); }
.ad-card img, .ad-image-placeholder { width: 68px; height: 64px; object-fit: cover; border-radius: 8px; }
.ad-image-placeholder { display: grid; place-items: center; background: var(--green-soft); color: var(--green); font-size: 24px; font-weight: 800; }
.ad-card div:last-child { display: grid; gap: 3px; min-width: 0; }
.ad-card strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-card span { color: var(--muted); font-size: 12px; }
.ad-card a { color: var(--green-dark); font-weight: 700; font-size: 12px; }

.steps { list-style: none; padding: 0; display: grid; gap: 18px; }
.steps li { display: flex; align-items: center; gap: 12px; line-height: 1.55; }
.steps span { flex: 0 0 auto; width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: var(--green-soft); color: var(--green-dark); font-weight: 800; }
.toast { position: fixed; left: 24px; bottom: 24px; background: #17352b; color: white; padding: 12px 18px; border-radius: 11px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { grid-template-columns: repeat(3, 1fr); }
  .logout { margin-top: 0; }
  main { padding: 0 18px 35px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid, .two-columns, .simulator-layout { grid-template-columns: 1fr; }
  .conversation-workspace { grid-template-columns: minmax(220px, .8fr) minmax(360px, 1.4fr); }
}
@media (max-width: 560px) {
  .sidebar nav { grid-template-columns: 1fr 1fr; }
  .metric-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; padding: 24px 0; }
  .status-chip { display: none; }
  .phone { min-height: 620px; border-width: 5px; }
  .conversation-tools, .conversation-workspace { grid-template-columns: 1fr; }
  .conversation-list { border-left: 0; border-bottom: 1px solid var(--line); max-height: 245px; }
  .conversation-workspace { min-height: 720px; }
  .detail-messages { max-height: 430px; }
  .agent-composer { grid-template-columns: 1fr; }
}
