* {
  box-sizing: border-box;
}

:root {
  /* Primary (buttons, headings): #6928D8 */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e1e6ec;
  --text: #1a2332;
  --muted: #5c6b7c;
  --primary: #6928D8;
  --primary-hover: #5a21b8;
  --primary-light: #ede5fc;
  --nav-bg: #ffffff;
  --guest-bg: #e8f4f0;
  --guest-text: #0d5c4a;
  --ai-bg: #ffffff;
  --ai-text: #1a2332;
  --chat-bg: #eef2f6;
  --chat-ai-bubble: #ffffff;
  --chat-guest-bubble: #d4ebe4;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  margin: 0;
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Nav */
.nav {
  background: var(--nav-bg);
  color: #fff;
  padding: 0.875rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-tagline {
  margin-left: auto;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
}

.nav-logo-img {
  height: 32px;
  width: auto;
  display: block;
  object-fit: contain;
}


/* Main */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  margin-bottom: 1.5rem;
}

.card-form {
  padding: 1.25rem 1.5rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.card-head h2,
.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
}

.card-table .card-title {
  padding: 1.25rem 1.5rem 0;
  margin-bottom: 0.75rem;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
}

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

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

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem 1rem;
}

.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.field input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Table */
.table-wrap {
  overflow-x: auto;
  border-radius: 0 0 var(--radius) var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

th, td {
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
}

tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

tbody tr:hover {
  background: var(--chat-bg);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Status */
.status-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.status-1 { background: #fef3c7; color: #92400e; }
.status-2 { background: #dbeafe; color: #1e40af; }
.status-4 { background: #d1fae5; color: #065f46; }
.status-5 { background: #fee2e2; color: #991b1b; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.modal[aria-hidden="true"] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(8px);
}

.modal-box {
  position: relative;
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 960px;
  height: 88vh;
  max-height: 800px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.04);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--nav-bg);
  color: #fff;
}

.modal-title {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--primary);
}

.modal-close {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.modal-close:hover {
  background: rgba(255,255,255,0.22);
}

.modal-inner {
  flex: 1;
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 0;
  overflow: hidden;
}

/* Modal side – detail cards */
.modal-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  background: linear-gradient(180deg, var(--chat-bg) 0%, #e1e6ec 100%);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.detail-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
}

.detail-card-title {
  margin: 0 0 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
}

.detail-fields {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.detail-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.25rem;
}

.detail-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.detail-value {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
  line-height: 1.4;
}

.detail-card .detail-value.status-badge {
  display: inline-block;
  margin-top: 0.15rem;
}

/* Modal chat – transcript area */
.modal-chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Soft gradient + subtle pattern: primary tint to white */
  background: linear-gradient(165deg, var(--primary-light) 0%, rgba(237, 229, 252, 0.4) 25%, #faf9fc 50%, var(--chat-bg) 100%);
  background-color: #faf9fc;
  background-image:
    radial-gradient(ellipse 120% 80% at 20% 10%, rgba(105, 40, 216, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse 80% 60% at 80% 90%, rgba(105, 40, 216, 0.05) 0%, transparent 45%),
    url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 20h40M20 0v40' stroke='%236928D8' stroke-opacity='0.04' stroke-width='0.5' fill='none'/%3E%3C/svg%3E");
}

.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(90deg, rgba(105, 40, 216, 0.08) 0%, rgba(255,255,255,0.95) 100%);
  border-bottom: 2px solid var(--primary);
  box-shadow: 0 1px 0 rgba(105, 40, 216, 0.06);
}

.chat-header-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
}

.chat-header-legend {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-ai { background: var(--primary); }
.legend-guest { background: #0d5c4a; }

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
}

.msg {
  max-width: 75%;
  padding: 0.65rem 1rem 0.75rem;
  border-radius: 18px;
  font-size: 0.9375rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.msg-ai {
  align-self: flex-start;
  background: #fff;
  color: var(--ai-text);
  border: 1px solid rgba(105, 40, 216, 0.15);
  border-left: 4px solid var(--primary);
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 3px rgba(105, 40, 216, 0.08);
}

.msg-guest {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(105, 40, 216, 0.06) 0%, var(--chat-guest-bubble) 100%);
  color: var(--guest-text);
  border: 1px solid rgba(105, 40, 216, 0.1);
  border-bottom-right-radius: 5px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.chat-history .no-history {
  margin: auto;
  text-align: center;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 2rem;
  opacity: 0.85;
}
