/* Sun & Steel CRM — lives at /crm on the main site, so this shares
   style.css's tokens (--green-800, --gold, --sage-400, etc.) rather than
   redefining them. Every rule here is scoped under .crm-page or prefixed
   .crm-* — this page loads alongside style.css, which already owns
   .btn/.badge/.panel-style names, and those must not collide. */

.crm-page { background: var(--paper); min-height: 100vh; }
.crm-shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 1px); }

.crm-sidebar { background: var(--green-900); color: #fff; padding: 22px 0; }
.crm-sidebar nav button { all: unset; display: block; padding: 11px 22px; color: rgba(255,255,255,.8); width: 100%; cursor: pointer; font: inherit; }
.crm-sidebar nav button:hover { background: rgba(255,255,255,.08); }
.crm-sidebar nav button.crm-active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
/* `all: unset` above also wipes the UA's [hidden] rule — put it back,
   or reps would see the Admin button. */
.crm-sidebar nav button[hidden] { display: none; }
/* Admin sits first, set apart from the everyday views below it. */
.crm-sidebar nav .crm-nav-admin { color: var(--gold); font-weight: 600; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: 10px; padding-bottom: 13px; }
.crm-sidebar .crm-back { display: block; padding: 0 22px 18px; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: 10px; color: var(--gold); font-size: 13px; }

.crm-main { padding: 26px 30px; overflow-x: auto; }
.crm-topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.crm-topbar h1 { font-size: 20px; margin: 0; flex: none; }
.crm-topbar .crm-spacer { flex: 1; }

.crm-select, .crm-input { padding: 8px 11px; border: 1px solid var(--line-dark); border-radius: 8px; background: #fff; color: var(--text); font: inherit; }
.crm-btn { padding: 9px 16px; border-radius: 8px; border: 1px solid var(--green-800); background: var(--green-800); color: #fff; font-weight: 600; cursor: pointer; font: inherit; }
.crm-btn:hover { background: var(--green-900); }
.crm-btn.crm-secondary { background: #fff; color: var(--green-800); }
.crm-btn.crm-small { padding: 5px 10px; font-size: 12px; border-radius: 6px; }

.crm-tablewrap { background: #fff; border: 1px solid var(--line-dark); border-radius: var(--radius-sm); overflow: auto; box-shadow: var(--shadow-sm); }
.crm-tablewrap table { border-collapse: collapse; width: 100%; min-width: 760px; }
.crm-tablewrap th, .crm-tablewrap td { padding: 10px 9px; text-align: left; border-bottom: 1px solid var(--line-dark); font-size: 13px; white-space: nowrap; }
.crm-tablewrap th { background: var(--paper-2); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
.crm-tablewrap tbody tr:hover { background: var(--paper); cursor: pointer; }
.crm-tablewrap td.crm-wrap { white-space: normal; max-width: 220px; }

.crm-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.crm-badge.not_contacted { background: var(--paper-2); color: var(--muted); }
.crm-badge.contacted { background: #fbf0d6; color: #8a6a1f; }
.crm-badge.replied { background: var(--peri-100); color: #3a5a82; }
.crm-badge.quoted { background: #eadff3; color: #6a3f8f; }
.crm-badge.won { background: var(--mint-200); color: var(--green-800); }
.crm-badge.lost { background: #f4dede; color: #b3453a; }
.crm-badge.dead { background: #e7e7e7; color: #777; }

.crm-dir { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11px; font-weight: 700; }
.crm-dir.inbound { background: var(--sage-400); color: #133127; }
.crm-dir.outbound { background: var(--peri); color: #1c2742; }

.crm-fires { letter-spacing: 1px; }
.crm-fires.crm-tier0 { filter: grayscale(1) opacity(.7); }

.crm-overlay { position: fixed; inset: 0; background: rgba(20,28,24,.45); display: flex; justify-content: flex-end; z-index: 500; }
.crm-panel { background: #fff; width: min(620px,100%); height: 100%; overflow-y: auto; padding: 24px 26px; box-shadow: -8px 0 24px rgba(0,0,0,.14); }
.crm-panel h2 { margin: 0 0 4px; font-size: 19px; }
.crm-panel .crm-close { float: right; background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; }
.crm-field { margin-bottom: 13px; }
.crm-field label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }
.crm-field input, .crm-field select, .crm-field textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line-dark); border-radius: 8px; font: inherit; }
.crm-field textarea { min-height: 64px; resize: vertical; }
.crm-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.crm-row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; align-items: end; }

.crm-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; border-top: 1px solid var(--line-dark); padding-top: 15px; }
.crm-items-row { display: grid; grid-template-columns: 2fr 70px 90px 28px; gap: 8px; align-items: center; margin-bottom: 7px; }
.crm-items-total { text-align: right; font-weight: 700; margin-top: 7px; }

.crm-timeline { list-style: none; margin: 0; padding: 0; }
.crm-timeline li { padding: 9px 0; border-bottom: 1px solid var(--line-dark); font-size: 13px; }
.crm-timeline .crm-meta { color: var(--muted); font-size: 11px; }
.crm-log-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.crm-score-why { font-size: 11px; color: var(--muted); margin-top: 4px; }

.crm-cadence-grid { display: grid; gap: 10px; }
.crm-cadence-card { background: #fff; border: 1px solid var(--line-dark); border-radius: var(--radius-sm); padding: 13px 15px; display: flex; justify-content: space-between; align-items: center; gap: 10px; box-shadow: var(--shadow-sm); }
.crm-cadence-card.crm-overdue { border-color: #b3453a; background: #fdf3f2; }
.crm-cadence-card .crm-city { font-weight: 700; }
.crm-cadence-card .crm-meta { font-size: 12px; color: var(--muted); }

.crm-gate { max-width: 480px; margin: 90px auto; text-align: center; padding: 0 24px; }
.crm-gate h1 { font-size: 22px; }

[hidden] { display: none !important; }

/* Admin: the four sales divisions */
.crm-divisions { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.crm-division { background: #fff; border: 1px solid var(--line-dark); border-radius: var(--radius-sm); padding: 14px 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 6px; }
.crm-division-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.crm-division-head h3 { margin: 0; font-size: 15px; }
.crm-division-count { font-size: 12px; font-weight: 600; color: var(--green-800); white-space: nowrap; }
.crm-division-meta { font-size: 12px; color: var(--muted); }
.crm-division-areas { font-size: 11px; color: var(--muted); line-height: 1.5; }
.crm-division-people { font-size: 13px; margin: 4px 0 6px; }
.crm-division .crm-btn { align-self: flex-start; }

/* Posting: segmented toggles, stored logins, copy-ready ad fields */
.crm-seg { display: inline-flex; border: 1px solid var(--line-dark); border-radius: 8px; overflow: hidden; background: #fff; flex-wrap: wrap; }
.crm-seg button { all: unset; padding: 7px 13px; font-size: 13px; cursor: pointer; color: var(--muted); border-right: 1px solid var(--line-dark); }
.crm-seg button:last-child { border-right: none; }
.crm-seg button.crm-on { background: var(--green-800); color: #fff; font-weight: 600; }
.crm-accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.crm-account { background: #fff; border: 1px solid var(--line-dark); border-radius: var(--radius-sm); padding: 12px 14px; display: flex; flex-direction: column; gap: 7px; align-items: flex-start; box-shadow: var(--shadow-sm); }
.crm-account-head { display: flex; flex-direction: column; gap: 2px; }
.crm-account .crm-meta { font-size: 12px; color: var(--muted); }
.crm-account-add { all: unset; border: 1px dashed var(--line-dark); border-radius: var(--radius-sm); padding: 12px 14px; color: var(--green-800); font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; min-height: 60px; }
.crm-copyline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.crm-copyline span { margin-right: 4px; word-break: break-all; }
.crm-linkbtn { all: unset; color: var(--green-800); font-size: 12px; cursor: pointer; text-decoration: underline; }
.crm-copyfield { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: start; margin-top: 12px; }
.crm-copyfield label { grid-column: 1 / -1; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.crm-copybox { background: var(--paper); border: 1px solid var(--line-dark); border-radius: 8px; padding: 8px 11px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.crm-copybody { max-height: 220px; overflow-y: auto; }
.crm-btn.crm-copied { background: var(--sage-400); border-color: var(--sage-400); color: #133127; }
.crm-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 10px; }
.crm-photo { all: unset; cursor: pointer; border-radius: 8px; overflow: hidden; border: 1px solid var(--line-dark); aspect-ratio: 4 / 3; }
.crm-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.crm-photo:hover { outline: 2px solid var(--green-800); }

/* Leads table: stacked cells so every field fits without sideways scrolling */
.crm-cell-main { font-weight: 600; color: var(--ink, #1d2a28); }
.crm-cell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.crm-cell-note { font-size: 12px; color: var(--muted); margin-top: 4px; font-style: italic; }
.crm-cell-company { min-width: 190px; max-width: 280px !important; }
.crm-heat-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.15); }
.crm-tablewrap td { vertical-align: top; }
.crm-cell-status { min-width: 120px; max-width: 180px !important; }
.crm-tablewrap td.crm-wrap { overflow-wrap: anywhere; }
.crm-tablewrap td.crm-wrap:nth-child(4) { max-width: 200px; }

/* Work queues above the leads table */
.crm-queues { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.crm-queues button { all: unset; cursor: pointer; padding: 6px 12px; border: 1px solid var(--line-dark); border-radius: 999px; background: #fff; font-size: 13px; color: var(--muted); }
.crm-queues button.crm-on { background: var(--green-800); border-color: var(--green-800); color: #fff; font-weight: 600; }
.crm-queue-count { margin-left: 4px; opacity: .75; font-size: 12px; }
/* Importance picker and contact dropdowns */
.crm-imp-select { display: block; margin-top: 4px; font-size: 11px; padding: 1px 2px; border: 1px solid var(--line-dark); border-radius: 4px; background: #fff; color: var(--muted); }
.crm-contact-drop summary { cursor: pointer; list-style: none; }
.crm-contact-drop summary::-webkit-details-marker { display: none; }
.crm-contact-drop summary::after { content: ' \25BE'; color: var(--muted); font-size: 11px; }
.crm-contact-drop[open] summary::after { content: ' \25B4'; }
.crm-contact-drop summary .crm-cell-sub { display: block; }
.crm-contact-drop a { color: var(--green-800); }
.crm-panel-drop { border: 1px solid var(--line-dark); border-radius: 8px; padding: 8px 12px; margin: 10px 0; }
.crm-panel-drop summary { cursor: pointer; font-weight: 600; }
.crm-panel-drop summary .crm-cell-sub { display: inline; font-weight: 400; margin-left: 6px; }
.crm-rating { font-size: 10px; font-weight: 600; color: #b8860b; margin-left: 1px; vertical-align: super; line-height: 0; white-space: nowrap; }

/* Replies view (CRM inbox) */
.crm-new-reply{display:inline-block;font-size:11px;font-weight:700;line-height:16px;padding:0 6px;border-radius:8px;background:#f4ca6d;color:#14201a;vertical-align:1px}
.crm-timeline-body{white-space:pre-wrap}

/* "Where it left off" column: latest message preview */
.crm-preview{margin-top:4px;font-size:13px;line-height:18px;color:inherit;opacity:.85;max-width:420px}
.crm-preview:empty{display:none}
.crm-preview-who{font-weight:700}

/* Lead view: conversation on the left, details on the right */
.crm-panel.crm-panel-split { width: min(1240px,100%); padding: 0; display: grid; grid-template-columns: minmax(0,1.25fr) minmax(0,1fr); grid-template-rows: minmax(0,1fr); overflow: hidden; }
.crm-convo { display: flex; flex-direction: column; height: 100%; min-height: 0; border-right: 1px solid var(--line-dark); background: #f4f7f5; }
.crm-convo-head { padding: 20px 22px 12px; border-bottom: 1px solid var(--line-dark); background: #fff; }
.crm-convo-list { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.crm-msg { max-width: 82%; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; line-height: 19px; border: 1px solid var(--line-dark); }
.crm-msg-in { align-self: flex-start; background: #fff; }
.crm-msg-out { align-self: flex-end; background: #e3efe8; }
.crm-msg-note { align-self: center; max-width: 90%; background: transparent; border-style: dashed; font-size: 12.5px; color: var(--muted); }
.crm-msg-subject { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
.crm-msg-body { white-space: pre-wrap; word-break: break-word; }
.crm-msg-meta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.crm-convo-reply { border-top: 1px solid var(--line-dark); background: #fff; padding: 12px 16px; }
.crm-convo-reply textarea { width: 100%; box-sizing: border-box; resize: vertical; min-height: 80px; }
.crm-convo-reply-bar { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.crm-convo-reply-bar .crm-cell-sub:first-child { flex: 1; }
.crm-convo-log { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 14px; background: #fff; border-top: 1px solid var(--line-dark); }
.crm-details { height: 100%; overflow-y: auto; padding: 24px 26px; box-sizing: border-box; }
@media (max-width: 860px) {
  .crm-panel.crm-panel-split { display: block; overflow-y: auto; }
  .crm-convo { height: auto; border-right: 0; border-bottom: 1px solid var(--line-dark); }
  .crm-convo-list { max-height: 55vh; }
  .crm-details { height: auto; overflow: visible; }
}
