/* ═══════════════════════════════════════════
   Global Styles — MVP Agents
   ═══════════════════════════════════════════ */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: #1c1917;
  background: #f5f5f4;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img, svg { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; }

::selection { background: #4f46e5; color: white; }

/* ── Typography ── */
h1, h2, h3, h4 { line-height: 1.2; font-weight: 700; color: #1c1917; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

p { margin-bottom: 1rem; }
small, .text-small { font-size: 0.875rem; color: #78716c; }

/* ── Links ── */
a { color: #4f46e5; text-decoration: none; transition: opacity 0.1s; }
a:hover { opacity: 0.8; }
a:focus-visible { outline: 2px solid #4f46e5; outline-offset: 2px; border-radius: 2px; }

/* ── Focus ring (global) ── */
:focus-visible {
  outline: 2px solid #818cf8;
  outline-offset: 2px;
}

/* ── Lists ── */
ul, ol { padding-left: 1.25rem; }
li { margin-bottom: 0.25rem; }

/* ── Separator ── */
hr { border: none; border-top: 1px solid #e7e5e4; margin: 2rem 0; }

/* ═══════════════════════════════════════════
   Layout
   ═══════════════════════════════════════════ */

/* ── Site header ── */
.site-header {
  background: white;
  border-bottom: 1px solid #e7e5e4;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  position: sticky;
  top: 0;
  z-index: 50;
}

.site-header .inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.site-header .brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: #4f46e5;
  letter-spacing: -0.02em;
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.site-header nav a {
  font-size: 0.875rem;
  color: #57534e;
  transition: color 0.1s;
}
.site-header nav a:hover { color: #1c1917; opacity: 1; }

.site-header .user-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.site-header .user-name { color: #78716c; }

/* ── Admin header ── */
.admin-header { background: #1c1917; border-bottom: 1px solid #292524; }
.admin-header .brand { color: #818cf8; }
.admin-header nav a { color: #a8a29e; }
.admin-header nav a:hover { color: white; opacity: 1; }
.admin-header .user-name { color: #57534e; }

/* ── Main content ── */
.main-content {
  max-width: 1280px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  flex: 1;
  width: 100%;
}

/* ── Flash messages ── */
.flash { max-width: 1280px; margin: 1rem auto 0; padding: 0 1.5rem; }
.flash p {
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  border: 1px solid;
}
.flash p:not(:last-child) { margin-bottom: 0.5rem; }
.flash-notice { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.flash-alert  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ═══════════════════════════════════════════
   Components
   ═══════════════════════════════════════════ */

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  line-height: 1.4;
}
.btn-primary { background: #4f46e5; color: white; }
.btn-primary:hover { background: #4338ca; opacity: 1; }
.btn-ghost { background: transparent; color: #57534e; }
.btn-ghost:hover { background: #f5f5f4; opacity: 1; }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover { background: #dc2626; opacity: 1; }

/* ── Cards ── */
.card {
  background: white;
  border: 1px solid #e7e5e4;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: box-shadow 0.15s;
}
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.06); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.card h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem; }
.card p { font-size: 0.875rem; color: #78716c; line-height: 1.5; }
.card .line-clamp {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* ── Tables ── */
.table-wrap {
  background: white;
  border: 1px solid #e7e5e4;
  border-radius: 0.75rem;
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead { background: #fafaf9; border-bottom: 1px solid #e7e5e4; }
th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 500;
  color: #78716c;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}
td { padding: 0.75rem 1rem; border-bottom: 1px solid #f5f5f4; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafaf9; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
}
.badge-active { background: #f0fdf4; color: #166534; }
.badge-inactive { background: #fef2f2; color: #991b1b; }
.badge-admin { background: #eef2ff; color: #4338ca; }
.badge-user { background: #f5f5f4; color: #57534e; }

/* ── Forms ── */
.form-wrap { max-width: 32rem; }
.form-group { margin-bottom: 1rem; }

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #44403c;
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid #d6d3d1;
  border-radius: 0.375rem;
  background: white;
  color: #1c1917;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

textarea { resize: vertical; min-height: 100px; }
.help-text { font-size: 0.75rem; color: #a8a29e; margin-top: 0.25rem; }

/* ── Stats / metrics ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: white; border: 1px solid #e7e5e4; border-radius: 0.75rem; padding: 1.5rem; }
.stat-card .stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: #78716c; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; margin-top: 0.25rem; color: #1c1917; }

/* ── Agent detail page ── */
.agent-page { max-width: 56rem; margin: 0 auto; }
.back-link { font-size: 0.875rem; color: #4f46e5; margin-bottom: 1rem; display: inline-block; }
.back-link:hover { text-decoration: underline; opacity: 1; }

/* ── Chat window ── */
.chat-window {
  background: white;
  border: 1px solid #e7e5e4;
  border-radius: 0.75rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e7e5e4;
  background: #fafaf9;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #4f46e5;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.chat-agent-name { font-weight: 600; font-size: 0.9rem; color: #1c1917; }
.chat-status { font-size: 0.75rem; color: #16a34a; }

.chat-description {
  padding: 0.75rem 1.25rem;
  font-size: 0.825rem;
  color: #78716c;
  line-height: 1.5;
  border-bottom: 1px solid #e7e5e4;
  background: white;
}

.chat-messages {
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #fafaf9;
  min-height: 320px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.msg-agent { align-self: flex-start; }
.msg-user { align-self: flex-end; }

.msg-bubble {
  padding: 0.65rem 1rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.msg-agent .msg-bubble {
  background: white;
  border: 1px solid #e7e5e4;
  border-bottom-left-radius: 0.25rem;
  color: #1c1917;
}

.msg-user .msg-bubble {
  background: #4f46e5;
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.msg-time {
  font-size: 0.6875rem;
  color: #a8a29e;
  margin-top: 0.25rem;
  padding: 0 0.5rem;
}

.msg-agent .msg-time { text-align: left; }
.msg-user .msg-time { text-align: right; }

.chat-input {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid #e7e5e4;
  background: white;
}

.chat-input input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d6d3d1;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  background: #fafaf9;
}

.chat-input input:disabled { background: #f5f5f4; color: #a8a29e; }

/* ── Login page ── */
.login-page { max-width: 24rem; margin: 4rem auto; }
.login-page h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 2rem; text-align: center; }
.login-page .btn-primary { width: 100%; justify-content: center; padding: 0.625rem; }

/* ═══════════════════════════════════════════
   Utility helpers
   ═══════════════════════════════════════════ */

.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-wrap   { display: flex; flex-wrap: wrap; }
.flex-gap-2  { gap: 0.5rem; }
.flex-gap-3  { gap: 0.75rem; }
.flex-gap-4  { gap: 1rem; }

.mb-4 { margin-bottom: 1rem; }
.mb-8 { margin-bottom: 2rem; }
.mt-4 { margin-top: 1rem; }
.mt-8 { margin-top: 2rem; }
