/* ------------------------------------------------------------------
   CRM stylesheet — plain CSS, no framework, no build step.
   Layout: fixed sidebar + scrollable main column with a top bar.
   ------------------------------------------------------------------ */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1e2532;
  --muted: #6b7280;
  --line: #e4e7ee;
  --brand: #2f6fed;
  --brand-dark: #2457c5;
  --danger: #d64545;
  --ok: #1f9d61;
  --sidebar-w: 224px;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

.muted { color: var(--muted); }
code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; }

/* --- App shell ---------------------------------------------------- */
.layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar ------------------------------------------------------ */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -.02em;
  color: var(--ink);
  padding: 4px 10px 18px;
}

.brand span { color: var(--brand); }

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 6px;
  color: #4b5563;
  font-size: 14px;
}

.side-nav a:hover { background: #f1f4f9; text-decoration: none; }

.side-nav a.active {
  background: #e9f0ff;
  color: var(--brand);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 2px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.sidebar-foot a { color: var(--muted); }

.logout-form { margin: 0; }

.link-button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

.link-button:hover { color: var(--danger); }

/* --- Main column -------------------------------------------------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Account switcher sits on the right side of the top bar */
.account-switcher {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.account-switcher label {
  margin: 0;
  color: var(--muted);
}

.account-switcher select {
  width: auto;
  min-width: 170px;
  padding: 6px 10px;
  font-weight: 600;
}

.userbox {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
  font-size: 14px;
  color: #374151;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e9f0ff;
  color: var(--brand);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
}

.wrap {
  width: 100%;
  max-width: 1180px;
  padding: 24px 26px 48px;
}

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.account-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  background: #e9f0ff;
  border-radius: 99px;
  padding: 3px 10px;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 18px;
  border-top: 1px solid var(--line);
}

/* --- KPI cards ---------------------------------------------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin: 18px 0 22px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.card-accent {
  background: linear-gradient(160deg, #eef4ff, #ffffff 70%);
  border-color: #d7e3fb;
}

.card-label {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 6px;
}

.card-value {
  display: block;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: -.01em;
}

.card small { display: block; margin-top: 4px; }

/* --- Panels, tables, lists ---------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.panel-head h2 { margin: 0; }

.count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 99px;
  background: #f1f4f9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  vertical-align: 2px;
}

.link-sm { font-size: 13px; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }

.truncate {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions-col { width: 130px; }

td.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
}

.inline-delete { display: inline; }

/* --- Status pills ------------------------------------------------- */
.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  background: #eef1f6;
  color: #4b5563;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}

.pill-open, .pill-sent       { background: #e9f0ff; color: #2457c5; }
.pill-pending, .pill-draft   { background: #fdf1dc; color: #9a6512; }
.pill-resolved, .pill-accepted, .pill-paid { background: #e6f7ee; color: #146c43; }
.pill-closed, .pill-rejected { background: #f3f4f6; color: #6b7280; }

/* --- Recent list (dashboard) -------------------------------------- */
.recent-list { list-style: none; margin: 0; padding: 0; }

.recent-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.recent-list li:last-child { border-bottom: 0; padding-bottom: 0; }

.recent-main { min-width: 0; }

.recent-main strong {
  display: block;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-main small { color: var(--muted); font-size: 12px; }

.recent-side {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  white-space: nowrap;
}

/* --- Toolbar & forms ---------------------------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.search-form { flex: 1; max-width: 460px; }
.search-form input { flex: 1; min-width: 160px; }

label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

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

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cfd4de;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid #cddcff;
  border-color: var(--brand);
}

textarea { resize: vertical; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  align-items: start;
}

.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { width: auto; }

/* --- Buttons ------------------------------------------------------ */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid #cfd4de;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
}

.btn:hover { background: var(--bg); text-decoration: none; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-ghost { border-color: transparent; color: var(--muted); }

.btn-danger { color: var(--danger); border-color: #eccaca; background: #fff; }
.btn-danger:hover { background: #fdecec; }

.btn-sm { padding: 4px 10px; font-size: 12.5px; }

/* --- Quote line items --------------------------------------------- */
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 20px 0 8px;
}

.items-table { min-width: 620px; }
.items-table th { padding-top: 6px; padding-bottom: 6px; }
.items-table td { padding: 6px 6px; }
.items-table input[type="number"] { min-width: 84px; }

.line-amount {
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-right: 10px;
}

.items-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.quote-total {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.quote-total strong { font-size: 18px; }

#notify-result { margin-bottom: 18px; }

/* --- Flash messages ----------------------------------------------- */
.flash {
  padding: 10px 13px;
  border-radius: 6px;
  margin: 14px 0;
  font-size: 14px;
  border: 1px solid transparent;
}

.flash-success { background: #e7f7ef; border-color: #b6e6cb; color: #146c43; }
.flash-error   { background: #fdecec; border-color: #f5c2c2; color: #a52828; }

/* --- Two-column layouts (inbox, dashboard lists) ------------------ */
.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
  align-items: start;
}

/* --- Inbox -------------------------------------------------------- */
.inbox-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
  align-items: start;
}

.conv-panel { padding: 14px; }

.filter-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: #f1f4f9;
  border-radius: 8px;
  padding: 3px;
}

.filter-tab {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.filter-tab:hover { text-decoration: none; color: var(--ink); }

.filter-tab.active {
  background: #fff;
  color: var(--brand);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .07);
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: calc(100vh - 230px);
  overflow-y: auto;
}

.conv-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border-radius: 8px;
  color: var(--ink);
  border: 1px solid transparent;
}

.conv-item:hover { background: #f7f9fc; text-decoration: none; }
.conv-item.active { background: #eef3ff; border-color: #d5e2ff; }

.conv-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  background: #eef1f6;
  display: grid;
  place-items: center;
  font-size: 14px;
}

.conv-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.conv-name {
  font-weight: 600;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-preview {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.conv-time { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

.pill-email    { background: #e9f0ff; color: #2457c5; }
.pill-whatsapp { background: #e6f7ee; color: #146c43; }

.thread-panel {
  display: flex;
  flex-direction: column;
  min-height: 560px;
}

.thread-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.thread-head h2 { font-size: 16px; margin: 0; }
.thread-head .muted { font-size: 12.5px; margin: 2px 0 0; }

.thread-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 280px;
  max-height: calc(100vh - 380px);
  padding: 4px;
}

.bubble {
  max-width: 76%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.bubble small { color: var(--muted); font-size: 10.5px; }

.bubble-in  { align-self: flex-start; background: #f3f5f9; }
.bubble-out { align-self: flex-end; background: #e8f1ff; border-color: #d5e2ff; }

.empty-thread { margin: auto; }

.reply-box {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.reply-box textarea { min-height: 58px; }

.reply-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  font-size: 12.5px;
}

.plain-list { margin: 0; padding-left: 18px; }
.plain-list li { margin-bottom: 6px; }

/* --- Login -------------------------------------------------------- */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 26px;
  box-shadow: 0 10px 30px rgba(20, 30, 50, .07);
}

.login-card h1 { font-size: 21px; margin-bottom: 2px; }
.login-card label { margin-top: 12px; }
.login-card .btn { width: 100%; margin-top: 18px; }

/* --- Public support page ------------------------------------------ */
.public-page { background: var(--bg); }

.public-wrap {
  max-width: 660px;
  margin: 0 auto;
  padding: 48px 20px 64px;
}

.public-head { margin-bottom: 22px; }
.public-head .brand { display: inline-block; padding: 0 0 14px; }
.public-head h1 { margin-bottom: 6px; }

.public-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}

.public-card label { margin-top: 14px; }
.public-card .btn-block { width: 100%; margin-top: 20px; }

/* Honeypot: visually removed but still submitted. */
.hp {
  position: absolute !important;
  left: -9999px !important;
  top: auto !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.captcha-input { max-width: 130px; }

.success-box {
  background: #e7f7ef;
  border: 1px solid #b6e6cb;
  border-radius: var(--radius);
  padding: 24px;
  color: #146c43;
}

.success-box p { margin: 6px 0; }
.success-box .btn { margin-top: 10px; background: #fff; }

.small { font-size: 12px; }

/* --- Tickets ------------------------------------------------------ */
.ticket-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 18px;
  align-items: start;
}

.ticket-side { display: flex; flex-direction: column; }

.ticket-description { white-space: pre-line; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin: 18px 0;
  padding: 0;
}

.meta-grid dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 2px;
}

.meta-grid dd { margin: 0; font-size: 14px; }

.rule { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar select { width: auto; min-width: 130px; }

.history-list { list-style: none; margin: 0; padding: 0; }

.history-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.history-list li:last-child { border-bottom: 0; padding-bottom: 0; }

.history-type {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.history-list p { margin: 3px 0; font-size: 13px; }
.history-list small { color: var(--muted); font-size: 11px; }

.ticket-state label { margin-top: 10px; }
.ticket-state label:first-child { margin-top: 0; }
#ticket-save-status { min-height: 16px; margin: 8px 0 0; }

.pill-in_progress { background: #fdf1dc; color: #9a6512; }
.pill-medium { background: #e9f0ff; color: #2457c5; }
.pill-high { background: #fdecec; color: #a52828; }

/* --- Modal -------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 25, 35, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 56px 16px;
  overflow-y: auto;
}

.modal-overlay[hidden] { display: none !important; }

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 10px;
  padding: 20px 22px;
  box-shadow: 0 20px 50px rgba(15, 25, 45, .25);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.modal-head h2 { margin: 0; }
.modal-card label { margin-top: 12px; }

/* --- Pagination ---------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pagination .muted { font-size: 12.5px; }

/* --- Analytics ---------------------------------------------------- */
.analytics-toolbar .inline-form { flex: 1; flex-wrap: wrap; }
.analytics-toolbar input[type="search"] { min-width: 220px; max-width: 300px; }
.analytics-toolbar select { width: auto; min-width: 150px; }

.right { text-align: right; }

.sort-link { color: inherit; white-space: nowrap; }
.sort-link:hover { color: var(--brand); text-decoration: none; }

.segment {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.segment-champions { background: #e6f7ee; color: #146c43; }
.segment-loyal     { background: #e9f0ff; color: #2457c5; }
.segment-potential { background: #fdf1dc; color: #9a6512; }
.segment-at-risk   { background: #fdecec; color: #a52828; }
.segment-lost      { background: #f3f4f6; color: #6b7280; }

.customer-detail { border-color: #d5e2ff; }

.detail-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  align-items: start;
}

.quote-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.quote-block-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
}

.quote-block-head .muted { font-size: 12px; }
.quote-amount { margin-left: auto; font-weight: 600; }

.items-mini {
  width: 100%;
  margin-top: 8px;
  font-size: 12.5px;
}

.items-mini th {
  font-size: 10px;
  padding: 4px 6px;
}

.items-mini td { padding: 4px 6px; }

.detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.detail-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}

.detail-list li:last-child { border-bottom: 0; }
.detail-list small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* --- Responsive --------------------------------------------------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
  }

  .brand { padding: 0 4px 10px; }

  .side-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
    padding-bottom: 2px;
  }

  .side-nav a { white-space: nowrap; }

  .sidebar-foot { display: none; }

  .topbar { padding: 10px 14px; height: auto; flex-wrap: wrap; }
  .account-switcher { margin-left: 0; }
  .wrap { padding: 18px 14px 36px; }
  .truncate { max-width: 140px; }

  .inbox-layout { grid-template-columns: 1fr; }
  .conv-list { max-height: 300px; }
  .thread-body { max-height: none; }

  .ticket-grid { grid-template-columns: 1fr; }
  .public-wrap { padding: 28px 14px 48px; }
  .public-card { padding: 18px; }

  .detail-columns { grid-template-columns: 1fr; }
}
