/* ITBOT styles — Feldman Ruel brand (Urban Property Advisors). */
:root {
  /* Brand palette (from Brand Standards 2024) */
  --medium-blue: #028abf;
  --electric-blue: #92c7df;
  --off-white: #f7f9fb;
  --light-grey: #c9d7dd;
  --medium-grey: #697785;
  --dark-blue: #02365d;
  --navy-blue: #1e4477;
  --grey-blue: #6a94b5;
  --teal-green: #10a5a3;
  --dark-grey: #343940;

  /* Roles */
  --bg: var(--off-white);
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --border: #dde6ec;
  --text: var(--dark-grey);
  --text-soft: var(--medium-grey);
  --muted: #97a3b1;
  --accent: var(--medium-blue);
  --accent-strong: var(--navy-blue);   /* hover / pressed */
  --accent-deep: var(--dark-blue);
  --accent-soft: #e3f1f8;              /* light medium-blue tint */
  --user-bubble: var(--medium-blue);
  --bot-bubble: #ffffff;
  --admin-bubble: #e4f5f4;             /* light teal tint */
  --admin-accent: var(--teal-green);
  --danger: #b4413c;                   /* functional: urgent / delete */
  --warn: #c77b1f;                     /* functional: high priority */
  --ok: var(--teal-green);
  --shadow: 0 1px 3px rgba(2, 54, 93, 0.08), 0 6px 20px rgba(2, 54, 93, 0.07);
  --radius: 12px;
  --font: "Poppins", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

/* Dark mode — overrides the role variables; brand accents stay the same. */
:root[data-theme="dark"] {
  --bg: #0f141a;
  --surface: #1a212a;
  --surface-2: #222c37;
  --border: #2c3742;
  --text: #e7edf3;
  --text-soft: #a7b3c0;
  --muted: #7d8a98;
  --accent-soft: #15303d;
  --bot-bubble: #1a212a;
  --admin-bubble: #14302d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
}
:root[data-theme="dark"] .auth-wrap {
  background:
    radial-gradient(1200px 600px at 80% -10%, #15303d 0%, transparent 60%),
    radial-gradient(900px 500px at 0% 110%, #14222b 0%, transparent 55%),
    var(--bg);
}
:root[data-theme="dark"] .banner { border-color: #1e4f63; }
:root[data-theme="dark"] .msg.user .file-chip { background: rgba(255, 255, 255, 0.12); }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
.hidden { display: none !important; }

/* --- Auth screen ---------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 80% -10%, #e3f1f8 0%, transparent 60%),
    radial-gradient(900px 500px at 0% 110%, #eaf2f7 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.brand-logo { height: 34px; width: auto; display: block; }
.brand-tag {
  font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--medium-grey); padding-left: 12px; border-left: 1px solid var(--border);
}
.auth-card .brand { margin-bottom: 10px; }
.auth-card .brand-logo { height: 46px; }
.auth-card .subtitle { color: var(--text-soft); margin: 4px 0 24px; font-size: 14px; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  flex: 1; padding: 9px; border: 1px solid var(--border);
  background: var(--surface-2); border-radius: 8px; color: var(--text-soft);
  font-weight: 600; font-size: 14px;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

label { display: block; font-size: 13px; font-weight: 600; color: var(--text-soft); margin: 14px 0 6px; }
input, textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; font-family: inherit; background: var(--surface);
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border: 1px solid transparent; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
}
.btn:hover { background: var(--accent-strong); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #973531; }

.form-error {
  margin-top: 14px; padding: 10px 12px; border-radius: 8px;
  background: #fbe9e8; color: var(--danger); font-size: 13px; border: 1px solid #f3cfcd;
}
/* Microsoft SSO button — follows Microsoft's official identity button spec. */
.btn-microsoft {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 10px 16px; margin-bottom: 4px;
  border: 1px solid #8c8c8c; border-radius: 4px;
  background: #fff; color: #5e5e5e;
  font-family: 'Segoe UI', var(--font); font-size: 14px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn-microsoft:hover { background: #f3f3f3; border-color: #5e5e5e; color: #5e5e5e; }
:root[data-theme="dark"] .btn-microsoft {
  background: #1a212a; border-color: #4a5568; color: #e7edf3;
}
:root[data-theme="dark"] .btn-microsoft:hover { background: #222c37; }
.sso-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0 4px; color: var(--muted); font-size: 12.5px;
}
.sso-divider::before, .sso-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.form-note { margin-top: 14px; color: var(--muted); font-size: 12.5px; text-align: center; }
.privacy-note {
  margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 12px; line-height: 1.5;
  color: var(--text-soft); background: var(--surface-2); border: 1px solid var(--border);
}
.composer-note {
  max-width: 820px; margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--muted);
}

/* --- App shell ------------------------------------------------------------ */
.app { display: grid; grid-template-columns: 290px 1fr; height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: 16px; border-bottom: 1px solid var(--border); }
.sidebar-head .brand h1 { font-size: 15px; }
.sidebar-actions { padding: 12px 16px; }
.convo-list { flex: 1; overflow-y: auto; padding: 4px 10px 16px; }
.convo-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
  border: 1px solid transparent;
}
.convo-item:hover { background: var(--surface-2); }
.convo-item.active { background: var(--accent-soft); border-color: #c9e2e0; }
.convo-item .title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sidebar-foot {
  padding: 14px 16px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.user-chip { font-size: 13px; color: var(--text-soft); overflow: hidden; }
.user-chip strong { display: block; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.main-head {
  padding: 14px 22px; border-bottom: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.main-head h2 { margin: 0; font-size: 16px; }

/* --- Chat ----------------------------------------------------------------- */
.messages { flex: 1; overflow-y: auto; padding: 24px; }
.messages-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 12px; max-width: 86%; }
.msg .avatar {
  flex: 0 0 32px; width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff;
}
.msg .bubble {
  padding: 11px 14px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word;
  border: 1px solid var(--border); background: var(--bot-bubble); box-shadow: var(--shadow);
}
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* Rendered markdown inside assistant/admin bubbles */
.bubble .md { white-space: normal; }
.bubble .md > :first-child { margin-top: 0; }
.bubble .md > :last-child { margin-bottom: 0; }
.bubble .md p { margin: 0 0 10px; }
.bubble .md ul, .bubble .md ol { margin: 0 0 10px; padding-left: 22px; }
.bubble .md li { margin: 2px 0; }
.bubble .md h3, .bubble .md h4, .bubble .md h5, .bubble .md h6 {
  margin: 12px 0 6px; font-size: 14.5px; line-height: 1.3;
}
.bubble .md a { color: var(--accent); text-decoration: underline; }
.bubble .md strong { font-weight: 700; }
.bubble .md code {
  font-family: "SFMono-Regular", ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.88em; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px;
}
.bubble .md pre {
  margin: 0 0 10px; padding: 12px 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; overflow-x: auto;
}
.bubble .md pre code { background: none; border: none; padding: 0; font-size: 12.5px; }
/* On the blue user bubble these tints would be invisible — keep them legible. */
.msg.user .bubble .md code, .msg.user .bubble .md pre {
  background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.28); color: #fff;
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .avatar { background: var(--accent); }
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-color: var(--accent); }
.msg.assistant .avatar { background: var(--accent-deep); }
.msg .avatar.mitch { background: #7a5c3e; font-size: 17px; padding: 0; overflow: hidden; }
.msg .avatar.mitch img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Mitch Mode toggle */
.mitch-btn {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); font-size: 13px; font-weight: 600; color: var(--text-soft);
  white-space: nowrap;
}
.mitch-btn:hover { border-color: #7a5c3e; color: #7a5c3e; }
.mitch-btn.active { background: #7a5c3e; color: #fff; border-color: #7a5c3e; }
.msg.admin .avatar { background: var(--admin-accent); }
.msg.admin .bubble { background: var(--admin-bubble); border-color: #bfe6e4; }

.empty-state { text-align: center; color: var(--muted); margin-top: 12vh; padding: 0 24px; }
.empty-state h3 { color: var(--text); font-size: 20px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 20px; }
.suggestion {
  padding: 9px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; font-size: 13.5px; color: var(--text-soft);
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); }

.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 14px 22px; }
.composer-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; max-height: 180px; min-height: 46px; }
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* --- Badges --------------------------------------------------------------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
  font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase;
}
.badge.open { background: var(--surface-2); color: var(--text-soft); }
.badge.escalated { background: #e3eaf4; color: var(--navy-blue); }
.badge.resolved { background: #e0f4f3; color: #0b7e7c; }
.badge.new { background: #e3f1f8; color: var(--medium-blue); }
.badge.forwarded { background: #e3eaf4; color: var(--navy-blue); }
.badge.in_house { background: #eaf1ee; color: #0b7e7c; }
.badge.closed { background: var(--surface-2); color: var(--muted); }
.badge.urgent { background: #fbe2e1; color: var(--danger); }
.badge.high { background: #fdeede; color: var(--warn); }
.badge.medium { background: #e3f1f8; color: var(--medium-blue); }
.badge.low { background: var(--surface-2); color: var(--text-soft); }
.badge.admin { background: #e0f4f3; color: #0b7e7c; }
.badge.user { background: var(--surface-2); color: var(--text-soft); }

.banner {
  margin: 0 auto 0; max-width: 820px; padding: 10px 14px; border-radius: 8px;
  background: var(--accent-soft); border: 1px solid #bfe0ef; color: var(--dark-blue); font-size: 13.5px;
}

/* --- Admin ---------------------------------------------------------------- */
.admin-nav {
  display: flex; gap: 6px; padding: 0 22px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.admin-nav button {
  padding: 13px 14px; background: none; border: none; border-bottom: 2px solid transparent;
  font-weight: 600; font-size: 14px; color: var(--text-soft);
}
.admin-nav button.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-body { flex: 1; overflow-y: auto; padding: 22px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-card .n { font-size: 28px; font-weight: 700; }
.stat-card .l { color: var(--muted); font-size: 13px; margin-top: 2px; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: top; }
th { background: var(--surface-2); color: var(--text-soft); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: var(--accent-soft); cursor: pointer; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.section-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; }

/* --- Modal / drawer ------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 45, 0.45);
  display: flex; justify-content: flex-end; z-index: 50;
}
.drawer {
  width: min(640px, 100%); background: var(--bg); height: 100%; overflow-y: auto;
  box-shadow: -8px 0 24px rgba(0,0,0,0.15); display: flex; flex-direction: column;
}
.drawer-head { padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.drawer-body { padding: 18px 20px; flex: 1; overflow-y: auto; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.close-x { background: none; border: none; font-size: 22px; color: var(--muted); line-height: 1; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.field-help { font-size: 12px; color: var(--muted); margin-top: 4px; }
/* Attach button + composer preview */
.icon-btn {
  width: 46px; height: 46px; flex: 0 0 auto; border: 1px solid var(--border);
  background: var(--surface); border-radius: 8px; font-size: 18px; color: var(--text-soft);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.attach-preview { max-width: 820px; margin: 0 auto 8px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.attach-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; display: block; }
.attach-chip span { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip button { border: none; background: none; font-size: 18px; color: var(--muted); line-height: 1; cursor: pointer; }

/* Attachments inside message bubbles */
.msg-image { display: block; max-width: 280px; max-height: 280px; border-radius: 8px; margin-top: 6px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 6px 10px;
  border-radius: 8px; font-size: 13px; text-decoration: none; background: var(--surface-2); color: var(--accent);
}
.msg.user .file-chip { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* Floating feedback button */
.fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 40; padding: 12px 18px; border: none;
  border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  box-shadow: 0 6px 20px rgba(2, 54, 93, 0.25);
}
.fab:hover { background: var(--accent-strong); }
.fab.pulse { animation: fabpulse 1.2s ease-in-out infinite; }
@keyframes fabpulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(2, 138, 191, 0.45); transform: translateY(0); }
  50% { box-shadow: 0 10px 32px rgba(2, 138, 191, 0.75); transform: translateY(-3px); }
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 45, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.modal { width: min(460px, 100%); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); }
.rating-row { display: flex; gap: 10px; margin-bottom: 16px; }
.rating-btn {
  flex: 1; padding: 12px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text-soft);
}
.rating-btn:hover { border-color: var(--accent); }
.rating-btn.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Charts (admin dashboard) */
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 22px; }
.chart-grid .card { padding: 16px 18px; }
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 120px; height: 120px; flex: 0 0 120px; }
.donut-seg { transition: stroke-width 0.12s ease; }
.donut-seg:hover { stroke-width: 7; }
.legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; max-height: 150px; overflow-y: auto; flex: 1; min-width: 0; }
.legend-item { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.legend-item:hover { color: var(--accent); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.legend-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Filter bars + sortable table headers */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-input { max-width: 280px; }
.filter-select { max-width: 190px; }
.filter-count { color: var(--muted); font-size: 13px; margin-left: auto; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--accent); }

/* Nav badge (count needing attention) */
.nav-badge {
  display: inline-flex; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  align-items: center; justify-content: center; vertical-align: middle; margin-left: 2px;
}

/* Toasts (admin attention alerts) */
#toast-root {
  position: fixed; right: 22px; bottom: 22px; z-index: 70;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
}
.toast {
  max-width: 340px; background: var(--dark-blue); color: #fff; padding: 12px 14px;
  border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: flex-start;
  font-size: 14px; animation: toastin 0.25s ease;
}
.toast-close { background: none; border: none; color: #c9d7dd; font-size: 18px; line-height: 1; cursor: pointer; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
}
