﻿:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e3e7ee;
  --text: #1c2433;
  --muted: #6b7486;
  --primary: #2f5bea;
  --primary-soft: #eaf0ff;
  --green: #14804a;
  --green-soft: #e3f5ea;
  --amber: #a15c07;
  --amber-soft: #fdf1dc;
  --radius: 12px;
  --surface-2: #fafbfd;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131a; --surface: #171c25; --surface-2: #131820; --border: #2a3140;
    --text: #e6e9ef; --muted: #98a1b3; --primary: #5b80f5; --primary-soft: #1d2745;
    --green: #4cc38a; --green-soft: #15301f; --amber: #f0b45a; --amber-soft: #33260f;
  }
}
:root[data-theme="dark"] {
  --bg: #0f131a; --surface: #171c25; --surface-2: #131820; --border: #2a3140;
  --text: #e6e9ef; --muted: #98a1b3; --primary: #5b80f5; --primary-soft: #1d2745;
  --green: #4cc38a; --green-soft: #15301f; --amber: #f0b45a; --amber-soft: #33260f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab {
  border: 0; background: transparent; padding: 7px 16px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-weight: 500;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.demo-pill {
  font-size: 11px; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); padding: 3px 10px; border-radius: 99px;
}

.demo-banner {
  background: var(--amber-soft); color: var(--amber);
  text-align: center; font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
}

/* Stats */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  padding: 20px 28px 0;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; display: flex; flex-direction: column; gap: 4px;
}
.stat-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.pending { color: var(--amber); }

/* Layout */
.view { padding: 20px 28px 28px; }
.view.hidden { display: none; }
#view-messages {
  display: grid; grid-template-columns: 320px 1fr; gap: 20px;
  height: calc(100vh - 190px); min-height: 520px;
}

/* Sidebar */
.sidebar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
}
.search {
  margin: 12px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); outline: none;
}
.search:focus { border-color: var(--primary); }
.customer-list { list-style: none; overflow-y: auto; flex: 1; }
.customer {
  display: flex; gap: 12px; padding: 12px 16px; cursor: pointer;
  border-left: 3px solid transparent;
}
.customer:hover { background: var(--bg); }
.customer.active { background: var(--primary-soft); border-left-color: var(--primary); }
.customer-info { flex: 1; min-width: 0; }
.customer-top { display: flex; justify-content: space-between; gap: 8px; }
.customer-name { font-weight: 600; }
.customer-date { color: var(--muted); font-size: 11px; white-space: nowrap; }
.customer-preview {
  color: var(--muted); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 600; font-size: 13px; color: #fff;
}

/* Chat */
.chat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.chat-header h2 { font-size: 16px; }
.chat-header .sub { color: var(--muted); font-size: 12px; }
.chat-header .badge { margin-left: auto; }
.chat-body { flex: 1; display: grid; grid-template-columns: 1fr 280px; min-height: 0; }
.messages {
  overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface-2);
}
.day-divider {
  align-self: center; font-size: 11px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  padding: 2px 10px; border-radius: 99px; margin: 8px 0;
}
.bubble {
  max-width: 70%; padding: 10px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
}
.bubble.me {
  align-self: flex-end; background: var(--primary); color: #fff; border-color: var(--primary);
  border-bottom-right-radius: 4px;
}
.bubble.customer { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble-meta { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 4px; }
.bubble-time { font-size: 11px; opacity: .7; }
.unsend {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 11px; font-weight: 600; opacity: 0; padding: 1px 6px; border-radius: 6px;
  transition: opacity .15s;
}
.bubble:hover .unsend, .unsend:focus-visible, .unsend.armed { opacity: .85; }
.unsend:hover { opacity: 1; background: rgba(255,255,255,.18); }
.unsend.armed { opacity: 1; background: #d93b3b; color: #fff; }
@media (hover: none) { .unsend { opacity: .75; } }

/* Deal panel */
.deal { border-left: 1px solid var(--border); padding: 20px; overflow-y: auto; }
.deal h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 10px; }
.deal-section + .deal-section { margin-top: 22px; }
.deal-row { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; }
.deal-row span:first-child { color: var(--muted); }
.deal-row span:last-child { font-weight: 500; text-align: right; }
.progress { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.progress div { height: 100%; background: var(--green); border-radius: 99px; }
.payment {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
}
.payment-top { display: flex; justify-content: space-between; font-weight: 600; }
.payment-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.payment-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }

.badge { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.badge.paid, .badge.completed { background: var(--green-soft); color: var(--green); }
.badge.pending, .badge.awaiting-payment { background: var(--amber-soft); color: var(--amber); }
.badge.in-progress { background: var(--primary-soft); color: var(--primary); }

/* Composer */
.composer { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.composer input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; outline: none;
}
.composer input:focus { border-color: var(--primary); }
.composer button {
  border: 0; background: var(--primary); color: #fff; font-weight: 600;
  padding: 0 22px; border-radius: 10px; cursor: pointer;
}
.composer button:hover { filter: brightness(1.08); }

/* Transactions table */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; }
.table-toolbar h2 { font-size: 16px; }
.table-toolbar select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 20px; text-align: left; border-top: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg); }
.cell-customer { display: flex; align-items: center; gap: 10px; }
.cell-customer .avatar { width: 28px; height: 28px; font-size: 11px; }

/* Responsive */
@media (max-width: 1100px) {
  .chat-body { grid-template-columns: 1fr; }
  .deal { display: none; }
}
@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
  .tabs { margin-left: 0; order: 3; width: 100%; }
  .tab { flex: 1; }
  .demo-pill { margin-left: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); padding: 16px 16px 0; gap: 10px; }
  .view { padding: 16px; }
  #view-messages { grid-template-columns: 1fr; height: auto; }
  .customer-list { max-height: 260px; }
  .chat { height: 70vh; }
  .bubble { max-width: 85%; }
}
