/* Diabolical CRM inside Hangar. Generated from the old CRM app.css: its dark
   palette is mapped onto Hangar's tokens (app.css) and every rule is scoped to
   .crm. Phones keep CRM's bottom tab bar; wider screens get a row of tabs. */
.crm {
  --surface: var(--panel); --surface-2: var(--bg); --border: var(--line); --text: var(--ink);
  --brand: var(--accent); --brand-2: var(--accent); --danger: var(--accent);
  --radius: 10px; --tabbar-h: 64px; --safe-bottom: env(safe-area-inset-bottom, 0px);
}
.main:has(.crm) { max-width: 1500px; }
.crm .page-title { font-size: 1.5rem; }
.crm a { color: var(--accent); text-decoration: none; }
.crm .tabbar { display: flex; gap: .25rem; margin: 0 0 1rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.crm .tab { flex-direction: row !important; font-size: .9rem !important; gap: .4rem !important; }
.crm .tab-icon svg { width: 18px !important; height: 18px !important; }
@media (max-width: 760px) {
  .crm { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom)); }
  .crm .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; justify-content: space-around; align-items: center;
    height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); background: var(--panel); border-top: 1px solid var(--line); border-bottom: 0; }
  .crm .tab { flex-direction: column !important; font-size: .68rem !important; gap: 2px !important; }
  .crm .tab-icon svg { width: 24px !important; height: 24px !important; }
  .crm .button-row.sticky-actions { position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-bottom)); }
}
.crm .page-title { font-size: 1.4rem; margin-bottom: 1rem; }
.crm .muted { color: var(--muted); }
.crm .small { font-size: .85rem; }
.crm .text-danger { color: var(--danger); }
.crm .tab { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .68rem; padding: .35rem .6rem; border-radius: 12px; min-width: 56px; }
.crm .tab-icon { line-height: 0; }
.crm .tab-icon svg { width: 24px; height: 24px; display: block; }
.crm .tab.active { color: var(--text); background: var(--surface-2); }
.crm .tab.active .tab-icon svg { color: var(--accent); }
.crm .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.crm .field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 480px) {
  .crm .field-grid { grid-template-columns: 1fr; }
}
.crm .field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }
.crm .field > span { font-size: .8rem; color: var(--muted); }
.crm input, .crm textarea, .crm select { width: 100%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 12px; padding: .75rem .85rem; font-size: 1rem; font-family: inherit; }
.crm input:focus, .crm textarea:focus, .crm select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(179,38,30,.2); }
.crm textarea { resize: vertical; }
.crm .checkbox { display: flex; align-items: center; gap: .6rem; margin: .5rem 0; }
.crm .checkbox input { width: auto; }
.crm .validation-message, .crm .field .validation-message { color: var(--danger); font-size: .8rem; }
.crm .btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1.1rem; font-size: 1rem; font-weight: 600; cursor: pointer; min-height: 48px; }
.crm .btn:active { transform: translateY(1px); }
.crm .btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border: none; color: #fff; }
.crm .btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.crm .btn-block { width: 100%; }
.crm .link-btn { background: none; border: none; color: var(--brand-2); font: inherit; cursor: pointer; padding: .4rem; }
.crm .link-btn.danger { color: var(--danger); }
.crm .button-row { display: flex; flex-direction: column; gap: .6rem; }
.crm .search-bar { margin-bottom: .75rem; }
.crm .search-input { width: 100%; }
.crm .tag-filter { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: .75rem; -webkit-overflow-scrolling: touch; }
.crm .chip { flex: 0 0 auto; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: .45rem .9rem; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.crm .chip.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: none; }
.crm .add-tag { display: flex; gap: .5rem; margin-top: .5rem; }
.crm .add-tag .search-input { flex: 1; }
.crm .contact-list { list-style: none; margin: 0; padding: 0; }
.crm .contact-item { display: flex; align-items: center; gap: .8rem; padding: .8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: .6rem; cursor: pointer; }
.crm .contact-item:active { background: var(--surface-2); }
.crm .avatar { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.crm .avatar-lg { width: 64px; height: 64px; font-size: 1.3rem; }
.crm .contact-main { flex: 1; min-width: 0; }
.crm .contact-name { font-weight: 600; }
.crm .contact-sub { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm .tag-row { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.crm .tag-badge { font-size: .7rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .1rem .4rem; color: var(--muted); }
.crm .followup-flag { flex: 0 0 auto; font-size: .78rem; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: .25rem .5rem; }
.crm .followup-flag.due { color: #fff; background: var(--danger); }
.crm .empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.crm .empty .btn { margin-top: 1rem; }
.crm .detail-header { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.crm .detail-name { font-size: 1.5rem; margin: 0; }
.crm .detail-sub { color: var(--muted); margin: .2rem 0 0; }
.crm .quick-actions { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.crm .qa { flex: 1 1 0; min-width: 68px; display: flex; flex-direction: column; align-items: center; gap: .25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .7rem .4rem; font-size: 1.3rem; color: var(--text); }
.crm .qa span { font-size: .72rem; color: var(--muted); }
.crm .kv { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.crm .kv:last-child { border-bottom: none; }
.crm .kv > span { color: var(--muted); }
.crm .kv.col { flex-direction: column; gap: .25rem; }
.crm .kv.col p { margin: 0; }
.crm .scan-drop { margin: 1rem 0; }
.crm .scan-cta { display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 2rem 1rem; text-align: center; border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.crm .scan-icon { font-size: 2.6rem; }
.crm .scan-cta input[type=file] { display: none; }
.crm .stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
.crm .stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; }
.crm .stat-value { font-size: 1.8rem; font-weight: 800; }
.crm .stat-label { color: var(--muted); font-size: .8rem; }
.crm .stat-alert { border-color: var(--danger); }
.crm .stat-alert .stat-value { color: var(--danger); }
.crm .bar-row { display: flex; align-items: center; gap: .6rem; margin: .4rem 0; }
.crm .bar-label { flex: 0 0 30%; font-size: .85rem; }
.crm .bar-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.crm .bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.crm .bar-count { flex: 0 0 auto; font-size: .85rem; color: var(--muted); min-width: 1.5rem; text-align: right; }
.crm .list { list-style: none; margin: 0; padding: 0; }
.crm .list-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.crm .list-row:last-child { border-bottom: none; }
.crm .list-row.clickable { cursor: pointer; }
.crm .row-actions { display: flex; gap: .4rem; flex: 0 0 auto; }
.crm .alert { border-radius: 12px; padding: .8rem 1rem; margin-bottom: 1rem; font-size: .9rem; }
.crm .alert.error { background: #f8dad7; border: 1px solid var(--danger); color: var(--ink); }
.crm .alert.success { background: #d8f0de; border: 1px solid var(--ok); color: var(--ink); }
.crm .alert.info { background: #f8dad7; border: 1px solid var(--brand); color: var(--ink); }
.crm .followup-add { padding: .5rem 0 1rem; border-bottom: 1px solid var(--border); margin-bottom: .75rem; }
.crm .followup-add textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: inherit; padding: .5rem; font: inherit; resize: vertical; }
.crm .followup-add input[type="date"] { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: inherit; padding: .5rem; font: inherit; }
.crm .followup-h { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: .9rem 0 .4rem; }
.crm .followup-row { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; padding: .6rem; border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: 8px; margin-bottom: .5rem; }
.crm .followup-row.due { border-left-color: var(--danger); }
.crm .followup-row.done { opacity: .7; }
.crm .followup-main { min-width: 0; }
.crm .followup-notes { margin: .25rem 0 0; font-size: .9rem; white-space: pre-line; }
.crm .followup-actions { display: flex; align-items: center; gap: .4rem; flex: 0 0 auto; }
.crm .btn-sm { padding: .3rem .55rem; font-size: .85rem; }

/* ---------- Desktop: use the width ---------- */
@media (min-width: 761px) {
  .crm .search-bar { max-width: 640px; }
  .crm .tag-filter { flex-wrap: wrap; overflow: visible; }
  .crm .contact-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .75rem; }
  .crm .contact-item { margin-bottom: 0; }
  .crm .contact-item:hover { border-color: var(--accent); }
  .crm .crm-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
  .crm .crm-cols > .card { margin-bottom: 0; }
  .crm .crm-cols + .card { margin-top: 1rem; max-width: 320px; }
  .crm .quick-actions .qa { flex: 0 0 110px; }
  .crm form, .crm .scan-drop { max-width: 900px; }
  .crm .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
.crm .card > h2:first-child { margin-top: 0; }
