:root{
  --bg:#06111f;
  --bg-2:#0b1830;
  --panel:rgba(12,21,39,.48);
  --panel-strong:rgba(12,21,39,.72);
  --panel-soft:rgba(255,255,255,.06);
  --line:rgba(255,255,255,.12);
  --line-2:rgba(255,255,255,.18);
  --text:#ecf4ff;
  --muted:#a9b9cf;
  --accent:#10B981;
  --accent-2:#059669;
  --accent-3:#32d3c9;
  --good:#34d399;
  --warn:#f59e0b;
  --danger:#fb7185;
  --bubble-in:rgba(255,255,255,.07);
  --bubble-out:linear-gradient(135deg,rgba(90,167,255,.35),rgba(124,92,255,.34));
  --shadow:0 18px 50px rgba(0,0,0,.28);
  --shadow-soft:0 10px 30px rgba(0,0,0,.18);
  --radius:22px;
  --blur:20px;
}

*{box-sizing:border-box}
html,body{margin:0;padding:0;min-height:100%;font-family:Inter,system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;background:
radial-gradient(circle at top left, rgba(90,167,255,.18), transparent 28%),
radial-gradient(circle at top right, rgba(124,92,255,.16), transparent 24%),
linear-gradient(180deg,var(--bg),var(--bg-2));color:var(--text)}
button,input,textarea{font:inherit}
.hidden{display:none !important}

body{position:relative;overflow-x:hidden}

.bg-orb{
  position:fixed;
  border-radius:999px;
  filter:blur(60px);
  opacity:.45;
  pointer-events:none;
  z-index:0;
}
.orb-1{width:260px;height:260px;background:#2dd4bf;top:90px;left:-60px}
.orb-2{width:320px;height:320px;background:#60a5fa;top:10%;right:-80px}
.orb-3{width:260px;height:260px;background:#8b5cf6;bottom:8%;left:32%}

.glass{
  background:var(--panel);
  backdrop-filter:blur(var(--blur)) saturate(140%);
  -webkit-backdrop-filter:blur(var(--blur)) saturate(140%);
  border:1px solid var(--line);
  box-shadow:var(--shadow);
}

.app-shell{
  position:relative;
  z-index:1;
  min-height:100vh;
  display:grid;
  grid-template-columns:300px 1fr;
  gap:18px;
  padding:18px;
}

.sidebar{
  padding:18px 16px;
  position:sticky;
  top:18px;
  height:calc(100vh - 36px);
  border-radius:28px;
}

.brand{
  display:flex;
  gap:14px;
  align-items:center;
  margin-bottom:26px;
  padding:6px 6px 18px;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.brand h1{font-size:18px;letter-spacing:.2px;margin:0}
.brand p{margin:4px 0 0;color:var(--muted);font-size:13px}

.brand-mark{
  width:50px;height:50px;border-radius:18px;
  background:
    linear-gradient(135deg, rgba(255,255,255,.22), rgba(255,255,255,.06)),
    linear-gradient(135deg,var(--accent),var(--accent-2));
  display:grid;place-items:center;font-weight:800;letter-spacing:.4px;
  border:1px solid rgba(255,255,255,.18);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.18), 0 12px 26px rgba(90,167,255,.22);
}

.nav{display:flex;flex-direction:column;gap:10px}
.nav-item{
  width:100%;
  text-align:left;
  border:1px solid transparent;
  background:rgba(255,255,255,.03);
  color:var(--text);
  padding:13px 14px;
  border-radius:16px;
  cursor:pointer;
  transition:all .18s ease;
}
.nav-item:hover{
  transform:translateY(-1px);
  background:rgba(255,255,255,.08);
  border-color:rgba(255,255,255,.12);
}
.nav-item.active{
  background:linear-gradient(135deg,rgba(90,167,255,.18),rgba(124,92,255,.15));
  border-color:rgba(145,181,255,.28);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.08), 0 10px 24px rgba(59,130,246,.12);
}

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

.topbar{
  border-radius:24px;
  padding:16px 18px;
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
}

.topbar-left{display:flex;gap:12px;align-items:flex-start}
.topbar h2{margin:0 0 4px;font-size:25px;letter-spacing:.2px}
.topbar p{margin:0;color:var(--muted)}
.menu-toggle{
  display:none;
  border:1px solid var(--line);
  background:rgba(255,255,255,.06);
  color:var(--text);
  border-radius:14px;
  padding:10px 12px;
  cursor:pointer;
}

.identity-card,.card{
  border-radius:22px;
}
.identity-card{
  padding:12px 14px;
  min-width:230px;
  background:rgba(255,255,255,.05);
}
.identity-row{
  display:flex;
  justify-content:space-between;
  gap:10px;
  padding:5px 0;
}
.muted{color:var(--muted)}

.card{padding:18px}

.token-panel-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
}
.token-panel-head h3{margin:0}
.token-panel-head p{margin:4px 0 0;color:var(--muted)}
.label{display:block;margin:14px 0 8px;color:var(--muted);font-size:13px}
.token-input{
  width:100%;
  min-height:96px;
  resize:vertical;
  border:1px solid var(--line);
  background:rgba(3,10,20,.42);
  color:var(--text);
  border-radius:16px;
  padding:13px;
  outline:none;
}
.token-input:focus{
  border-color:rgba(90,167,255,.45);
  box-shadow:0 0 0 4px rgba(90,167,255,.08);
}
.token-actions{
  margin-top:12px;
  display:flex;
  flex-wrap:wrap;
  gap:10px;
}
.btn{
  border:1px solid var(--line);
  background:rgba(255,255,255,.07);
  color:var(--text);
  padding:10px 14px;
  border-radius:14px;
  cursor:pointer;
  transition:all .18s ease;
}
.btn:hover{
  transform:translateY(-1px);
  filter:brightness(1.05);
}
.btn-primary{
  background:linear-gradient(135deg,rgba(90,167,255,.78),rgba(124,92,255,.78));
  border-color:rgba(159,184,255,.35);
}
.btn-danger{
  background:linear-gradient(135deg,rgba(190,24,93,.34),rgba(239,68,68,.24));
  border-color:rgba(251,113,133,.26);
}
.status-line{margin:12px 0 0;color:var(--muted);font-size:14px}

.view{display:none}
.view.active{display:block}

.grid{display:grid;gap:16px}
.grid.cards-4{grid-template-columns:repeat(4,minmax(0,1fr))}

.kpi,.placeholder,.conv-list,.thread-panel{
  border-radius:24px;
}

.kpi{
  padding:18px;
  background:rgba(255,255,255,.05);
  backdrop-filter:blur(18px) saturate(140%);
  -webkit-backdrop-filter:blur(18px) saturate(140%);
  border:1px solid var(--line);
  box-shadow:var(--shadow-soft);
}
.kpi:nth-child(1){background:linear-gradient(135deg,rgba(96,165,250,.14),rgba(255,255,255,.05))}
.kpi:nth-child(2){background:linear-gradient(135deg,rgba(45,212,191,.14),rgba(255,255,255,.05))}
.kpi:nth-child(3){background:linear-gradient(135deg,rgba(245,158,11,.14),rgba(255,255,255,.05))}
.kpi:nth-child(4){background:linear-gradient(135deg,rgba(251,113,133,.14),rgba(255,255,255,.05))}
.kpi .kpi-label{color:var(--muted);font-size:13px}
.kpi .kpi-value{font-size:27px;font-weight:800;margin-top:8px}

.placeholder{
  background:rgba(255,255,255,.05);
  border:1px solid var(--line);
  padding:20px;
  box-shadow:var(--shadow-soft);
}
.placeholder h3{margin-top:0}
.placeholder p{color:var(--muted)}

.conv-layout{
  display:grid;
  grid-template-columns:380px 1fr;
  gap:16px;
  min-height:60vh;
  height:calc(100vh - 140px);
}

.conv-list,.thread-panel{
  background:rgba(255,255,255,.05);
  border:1px solid var(--line);
  box-shadow:var(--shadow-soft);
  min-height:60vh;
}

/* FIX: enable proper scrolling */
.conv-list{
  display:flex;
  flex-direction:column;
  height: calc(100vh - 140px);
  min-width:0;
  min-height:0;
  overflow:hidden;
}

.conv-list-items{
  flex:1;
  overflow-y:auto;
  min-height:0;
}

.conv-list-head,.thread-head,.composer-head{
  padding:15px 16px;
  border-bottom:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.02);
}

.conv-list-items{
  display:flex;
  flex-direction:column;
}

.conv-item{
  width:100%;
  text-align:left;
  background:transparent;
  color:var(--text);
  border:0;
  border-bottom:1px solid rgba(255,255,255,.06);
  padding:15px 16px;
  cursor:pointer;
  transition:all .16s ease;
}
.conv-item:hover{background:rgba(255,255,255,.05)}
.conv-item.active{
  background:linear-gradient(135deg,rgba(90,167,255,.14),rgba(124,92,255,.12));
}
.conv-item-top,.thread-head-top,.meta-row{
  display:flex;
  justify-content:space-between;
  gap:12px;
}
.conv-name{font-weight:700}
.conv-phone,.conv-snippet,.small,.thread-sub{color:var(--muted);font-size:13px}
.badges{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}
.badge{
  padding:5px 10px;
  border-radius:999px;
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.1);
  color:#d7e6fb;
  font-size:12px;
}
.badge.warn{background:rgba(245,158,11,.12);border-color:rgba(245,158,11,.22)}
.badge.good{background:rgba(52,211,153,.12);border-color:rgba(52,211,153,.22)}
.badge.info{background:rgba(90,167,255,.12);border-color:rgba(90,167,255,.24)}

.thread-panel{
  display:flex;
  flex-direction:column;

  /* CRITICAL */
  height: calc(100vh - 140px);

  min-width:0;
}

.thread-body{
  padding:16px;
  overflow-y:auto;
  flex:1;
  min-height:0;
  display:flex;
  flex-direction:column;
  gap:12px;
}

.msg-wrap{display:flex}
.msg-wrap.inbound{justify-content:flex-start}
.msg-wrap.outbound{justify-content:flex-end}
.msg{
  max-width:min(78%,700px);
  padding:12px 14px;
  border-radius:18px;
  border:1px solid rgba(255,255,255,.09);
  box-shadow:var(--shadow-soft);
}
.msg.inbound{
  background:var(--bubble-in);
  backdrop-filter:blur(14px);
  -webkit-backdrop-filter:blur(14px);
}
.msg.outbound{
  background:var(--bubble-out);
  backdrop-filter:blur(14px);
  -webkit-backdrop-filter:blur(14px);
  border-color:rgba(159,184,255,.22);
}
.msg-meta{
  display:flex;
  justify-content:space-between;
  gap:10px;
  margin-bottom:8px;
  color:#dbeafe;
  font-size:12px;
}
.msg.inbound .msg-meta{color:#cad8ee}
.msg-text{white-space:pre-wrap;word-break:break-word}
.empty-state{
  padding:24px;
  color:var(--muted);
}

.composer{
  border-top:1px solid rgba(255,255,255,.08);
  padding:14px 16px 16px;
  background:rgba(255,255,255,.02);

  /* CRITICAL FIX */
  position:sticky;
  bottom:0;
  z-index:10;

  /* prevents shrinking */
  flex-shrink:0;
}
.composer-head{
  border:0;
  padding:0 0 12px;
  background:transparent;
}
.composer-grid{display:grid;gap:12px}
.composer-grid textarea{
  width:100%;
  min-height:104px;
  resize:vertical;
  border:1px solid var(--line);
  background:rgba(3,10,20,.42);
  color:var(--text);
  border-radius:16px;
  padding:13px;
  outline:none;
}
.composer-grid textarea:focus{
  border-color:rgba(90,167,255,.45);
  box-shadow:0 0 0 4px rgba(90,167,255,.08);
}
.composer-actions{
  display:flex;
  flex-wrap:wrap;
  justify-content:space-between;
  gap:12px;
  align-items:center;
}
.inline-controls{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
}
.inline-controls label{
  display:flex;
  gap:8px;
  align-items:center;
  color:var(--muted);
  font-size:14px;
  padding:7px 14px;
  border:1px solid var(--border);
  border-radius:8px;
  cursor:pointer;
  transition:background 0.15s, color 0.15s, border-color 0.15s;
  user-select:none;
}
.inline-controls label:hover{
  background:var(--surface2);
  color:var(--text);
  border-color:var(--accent);
}
.inline-controls label:has(input[type="checkbox"]:checked){
  background:rgba(99,102,241,0.12);
  color:var(--accent);
  border-color:var(--accent);
}
.inline-controls label input[type="checkbox"]{
  accent-color:var(--accent);
  width:15px;
  height:15px;
}
.attachment-label{
  display:flex;
  gap:8px;
  align-items:center;
}

@media (max-width: 1080px){
  .grid.cards-4{grid-template-columns:repeat(2,minmax(0,1fr))}
  .conv-layout{grid-template-columns:1fr}
}

@media (max-width: 820px){
  .app-shell{
    grid-template-columns:1fr;
    padding:12px;
  }
  .sidebar{
    position:fixed;
    left:12px;top:12px;bottom:12px;
    width:280px;
    transform:translateX(calc(-100% - 20px));
    transition:transform .2s ease;
    z-index:20;
    height:auto;
  }
  .sidebar.open{transform:translateX(0)}
  .menu-toggle{display:inline-block}
  .topbar{flex-direction:column}
  .identity-card{width:100%}
  .grid.cards-4{grid-template-columns:1fr}
}
/* =========================
   OVERVIEW UPGRADE
========================= */

/* Section header */
.section-head h2 {
  font-size: 22px;
  margin: 0;
}

.section-head p {
  opacity: 0.7;
  margin-top: 4px;
  font-size: 13px;
}

/* KPI cards */
.kpi {
  padding: 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  transition: all 0.2s ease;
}

.kpi:hover {
  transform: translateY(-2px);
}

.kpi-label {
  font-size: 12px;
  opacity: 0.7;
}

.kpi-value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 6px;
}

/* Priority tones */
.tone-danger {
  border: 1px solid rgba(255, 80, 80, 0.4);
  background: rgba(255, 80, 80, 0.05);
}

.tone-warn {
  border: 1px solid rgba(255, 180, 0, 0.4);
  background: rgba(255, 180, 0, 0.05);
}

.tone-accent {
  border: 1px solid rgba(120, 100, 255, 0.4);
  background: rgba(120, 100, 255, 0.05);
}

.tone-info {
  border: 1px solid rgba(0, 180, 255, 0.4);
  background: rgba(0, 180, 255, 0.05);
}

/* Conversation preview in Overview */
.conversation-item {
  padding: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
}

.conversation-item:hover {
  background: rgba(255,255,255,0.03);
}

.conversation-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.conversation-preview {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 4px;
}

/* Badge */
.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
}

/* Grid spacing refinement */
.grid {
  gap: 14px;
  margin-bottom: 16px;
}


/* =========================
   INVOICES MODULE
========================= */

.invoice-toolbar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  margin-bottom:16px;
  flex-wrap:wrap;
}

.invoice-filters{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}

.invoice-filters .btn.active{
  border-color:rgba(255,255,255,0.22);
  background:rgba(255,255,255,0.09);
}

.invoice-table-wrap{
  padding:0;
  overflow:hidden;
}

.invoice-table{
  width:100%;
}

.invoice-row{
  display:grid;
  grid-template-columns:32px 1.4fr 1.5fr 1fr 1fr 1.1fr 1fr 1.2fr;
  gap:10px;
  align-items:center;
  padding:14px 16px;
  border-bottom:1px solid rgba(255,255,255,0.06);
}

.invoice-head{
  font-size:12px;
  font-weight:600;
  letter-spacing:.02em;
  text-transform:uppercase;
  opacity:.72;
}

.invoice-row.empty{
  display:block;
  padding:18px;
}

@media (max-width: 980px){
  .invoice-row{
    grid-template-columns:32px 1fr 1fr;
  }
  .invoice-head{
    display:none;
  }
}


/* =========================
   PAYMENTS MODULE
========================= */
/* Reuses invoice toolbar and table styles intentionally */


/* =========================
   REVIEWER ASSIGNMENT
========================= */

.assignment-card{
  margin:16px 0;
  padding:16px;
  border:1px solid rgba(255,255,255,0.07);
  border-radius:14px;
  background:rgba(255,255,255,0.025);
}

.assignment-head{
  margin-bottom:14px;
}

.assignment-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:14px;
}

.field{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.field label{
  font-size:12px;
  color:var(--muted);
}

.field select,
.field input{
  width:100%;
  min-height:42px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,0.10);
  background:rgba(255,255,255,0.04);
  color:inherit;
  padding:10px 12px;
  outline:none;
}

.field select:focus,
.field input:focus{
  border-color:rgba(90,167,255,.45);
  box-shadow:0 0 0 3px rgba(90,167,255,.10);
}

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

.hidden{
  display:none !important;
}

@media (max-width: 980px){
  .assignment-grid{
    grid-template-columns:1fr;
  }
}


/* =========================
   SITE REGISTRY
========================= */

.panel-head{
  margin-bottom:14px;
}

.panel-head h3{
  margin:0 0 6px 0;
  font-size:16px;
}

.site-registry-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:12px;
}

.site-registry-card{
  padding:14px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,0.08);
  background:rgba(255,255,255,0.03);
}

.site-registry-top{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-bottom:8px;
}

.site-registry-name{
  font-weight:600;
  font-size:15px;
}

.site-registry-meta{
  color:var(--muted);
  font-size:12px;
}

@media (max-width: 980px){
  .site-registry-grid{
    grid-template-columns:1fr;
  }
}


/* PATCH: sticky composer */

.thread-panel{
  display:flex;
  flex-direction:column;
  height:100%;
}

.thread-body{
  flex:1;
  overflow-y:auto;
  padding-bottom:20px;
}

.composer{
  position:sticky;
  bottom:0;
  background:#111;
  padding:12px;
  border-top:1px solid rgba(255,255,255,0.1);
}


/* Sticky composer fix */
.composer{
  position:sticky;
  bottom:0;
  background:rgba(10,15,30,0.95);
  backdrop-filter:blur(8px);
  z-index:5;
}


/* Compact assignment header */
.assignment-card{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:12px 16px;
}

.assignment-card .meta-row{
  display:flex;
  gap:20px;
  flex-wrap:wrap;
}

.assignment-card .meta-block{
  display:flex;
  flex-direction:column;
  font-size:13px;
}

.assignment-card .meta-label{
  color:var(--muted);
  font-size:12px;
}

.assignment-card .meta-value{
  font-weight:600;
}

.assignment-card .edit-btn{
  white-space:nowrap;
}


/* ===== COMPACT SUPPLIER HEADER ===== */
.compact-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:12px 16px;
  gap:16px;
}

.compact-header .title{
  font-size:18px;
  font-weight:600;
}

.compact-header .subtitle{
  font-size:13px;
  opacity:0.7;
}

.compact-header .badges{
  display:flex;
  gap:8px;
}

/* shrink assignment */
.assignment-card{
  padding:10px 14px;
}

.assignment-head h3{
  font-size:16px;
}

.assignment-grid{
  grid-template-columns:repeat(3, 1fr);
  gap:12px;
}

.field label{
  font-size:11px;
}

.readonly-value{
  font-size:14px;
}

/* shrink edit button */
.assignment-actions button{
  padding:6px 12px;
  font-size:13px;
}


/* ===== INLINE ASSIGNMENT STRIP ===== */
.assignment-inline{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  padding:10px 14px;
  margin:8px 0 12px;
  border-radius:10px;
  background:rgba(255,255,255,0.03);
}

.assignment-inline .assignment-head{
  display:none;
}

.assignment-inline .assignment-grid{
  display:flex;
  gap:24px;
  align-items:center;
}

.assignment-inline .field{
  gap:2px;
}

.assignment-inline .field label{
  font-size:11px;
}

.assignment-inline .readonly-value{
  font-size:14px;
}

.assignment-inline .assignment-actions{
  margin:0;
}


/* ===== SUPPLIERS GRID ===== */
.suppliers-grid{
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(260px, 1fr));
  gap:14px;
}

.supplier-card{
  padding:14px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,0.08);
  background:rgba(255,255,255,0.03);
}

.supplier-name{
  font-weight:600;
  font-size:15px;
}

.supplier-phone{
  font-size:13px;
  color:var(--muted);
  margin-bottom:6px;
}

.supplier-meta{
  display:flex;
  gap:10px;
  font-size:12px;
  color:var(--muted);
}

.supplier-note{
  margin-top:6px;
  font-size:12px;
}


/* Mobile conversations: show list first, then thread */
@media (max-width: 1080px){
  .conv-layout.mobile-thread-open .conv-list{
    display:none;
  }

  .conv-layout.mobile-thread-open .thread-panel{
    display:flex;
  }

  .thread-back-btn{
    display:inline-flex;
    margin-bottom:10px;
  }
}


/* ===== MOBILE: COLLAPSE ASSIGNMENT ===== */
@media (max-width: 1080px){
  .assignment-card{
    padding:8px 12px;
  }

  .assignment-head{
    display:none;
  }

  .assignment-grid{
    display:flex;
    flex-wrap:wrap;
    gap:12px;
  }

  .assignment-actions{
    display:none;
  }
}


/* ===== MOBILE HEADER COMPRESSION ===== */
@media (max-width: 1080px){
  .thread-head{
    padding:10px 12px;
  }

  .thread-head-top{
    flex-direction:column;
    gap:6px;
  }

  .supplier-head-row{
    display:flex;
    justify-content:space-between;
    align-items:center;
  }

  .badges{
    margin-top:4px;
    flex-wrap:wrap;
  }
}


/* ===== MOBILE COMPOSER FIX ===== */
@media (max-width: 1080px){
  .composer{
    padding:10px 12px;
  }

  .composer-head{
    display:none;
  }

  .composer-grid textarea{
    min-height:60px;
    padding:10px;
  }

  .composer-actions{
    gap:8px;
  }

  .inline-controls{
    display:none;
  }
}


/* Mobile full-screen thread mode */
@media (max-width: 1080px){
  body.mobile-thread-open .topbar{
    display:none;
  }

  body.mobile-thread-open .main{
    gap:0;
  }

  body.mobile-thread-open #view-conversations{
    margin-top:0;
  }

  body.mobile-thread-open .conv-layout{
    height:calc(100vh - 24px);
    min-height:calc(100vh - 24px);
  }

  body.mobile-thread-open .thread-panel{
    height:calc(100vh - 24px);
    border-radius:18px;
  }

  body.mobile-thread-open .thread-head{
    padding:10px 12px;
  }

  body.mobile-thread-open .thread-back-btn{
    padding:8px 12px;
    font-size:14px;
    border-radius:12px;
  }
}


/* Mobile conversations: list screen first, thread screen second */
@media (max-width: 1080px){
  #view-conversations .thread-panel{
    display:none;
  }

  body.mobile-thread-open #view-conversations .conv-list{
    display:none;
  }

  body.mobile-thread-open #view-conversations .thread-panel{
    display:flex;
  }

  body.mobile-thread-open #view-conversations .conv-layout{
    grid-template-columns:1fr;
  }
}


/* Compact conversation thread header */
.thread-head.compact{
  padding:12px 16px;
}

.thread-head-row.compact{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
}

.thread-left.compact{
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:6px;
}

.thread-right.compact{
  display:flex;
  align-items:flex-start;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.supplier-head-row.compact{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.thread-sub.compact{
  margin:0;
  font-size:13px;
  opacity:.78;
}

.badges.compact{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.thread-actions.compact{
  display:flex;
  gap:8px;
  align-items:center;
}

.btn.small{
  padding:6px 10px;
  font-size:12px;
  line-height:1.1;
}

@media (max-width: 980px){
  .thread-head-row.compact{
    flex-direction:column;
    align-items:flex-start;
  }

  .thread-right.compact{
    width:100%;
    justify-content:space-between;
  }

  .badges.compact{
    justify-content:flex-start;
  }
}


/* Media message rendering */
.msg-text audio{
  max-width: 260px;
  width: 100%;
  margin-top: 4px;
}

.msg-text a{
  word-break: break-word;
}

.msg-media-fallback{
  opacity: .85;
  font-style: italic;
}


/* Daylight-safe conversation workspace */
.thread-panel{
  background:#0f172a;
}

.thread-body{
  background:
    linear-gradient(180deg, rgba(15,23,42,0.98) 0%, rgba(15,23,42,0.96) 100%);
}

.thread-head,
.composer,
.composer-head{
  background:rgba(17,24,39,0.92);
}

.assignment-card,
.assignment-card.glass{
  background:rgba(30,41,59,0.92);
  border-color:rgba(255,255,255,0.10);
}

.msg.inbound{
  background:#334155;
  border-color:rgba(255,255,255,0.14);
  color:#f8fafc;
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
}

.msg.outbound{
  background:#1d4ed8;
  border-color:rgba(191,219,254,0.22);
  color:#f8fafc;
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
}

.msg-text{
  color:#f8fafc;
}

.msg-meta{
  color:#dbeafe;
}

.thread-sub,
.conv-phone,
.conv-snippet,
.small{
  color:#cbd5e1;
}

.composer textarea{
  background:#020617;
  color:#f8fafc;
  border:1px solid rgba(255,255,255,0.12);
}

.composer textarea::placeholder{
  color:#94a3b8;
}

@media (max-width: 1080px){
  .thread-panel{
    background:#0b1220;
  }

  .thread-body{
    background:#0f172a;
  }

  .msg{
    max-width:min(86%, 700px);
  }

  .msg.inbound{
    background:#3f4d63;
  }

  .msg.outbound{
    background:#2563eb;
  }
}


/* Message content links — force visibility */
.msg a{
  color:#f8fafc !important;
  text-decoration:underline;
  font-weight:500;
}

.msg a:visited{
  color:#e2e8f0 !important;
}

.msg a:hover{
  color:#ffffff !important;
  text-decoration:underline;
}

/* File + media links (extra clarity) */
.msg a::before{
  opacity:0.85;
}


/* Message attachment cards (COMPACT) */
.msg-attachment-card{
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px 10px;
  border-radius:12px;
  background:rgba(255,255,255,0.06);
  border:1px solid rgba(255,255,255,0.10);
  text-decoration:none;
  color:#f8fafc !important;
  max-width:100%;
}

.msg-attachment-card:hover{
  background:rgba(255,255,255,0.10);
}

.msg-attachment-icon{
  font-size:16px;
  flex:0 0 auto;
}

.msg-attachment-meta{
  display:flex;
  flex-direction:column;
  min-width:0;
}

.msg-attachment-title{
  font-size:14px;
  font-weight:600;
  line-height:1.2;
  color:#f8fafc;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.msg-attachment-sub{
  font-size:11px;
  color:#94a3b8;
  margin-top:2px;
}

/* Even tighter on mobile */
@media (max-width:1080px){
  .msg-attachment-card{
    padding:7px 9px;
    gap:8px;
  }

  .msg-attachment-title{
    font-size:13px;
  }

  .msg-attachment-sub{
    font-size:10px;
  }
}


/* Ultra-compact inline attachment (chat-native) */
.msg-attachment-inline{
  display:inline-flex;
  align-items:center;
  gap:6px;
  margin-top:6px;
  text-decoration:none;
  color:#f8fafc !important;
  font-size:14px;
  line-height:1.3;
  max-width:100%;
}

.msg-attachment-inline:hover{
  text-decoration:underline;
}

.msg-attachment-inline .msg-attachment-icon{
  font-size:14px;
  opacity:0.9;
}

.msg-attachment-text{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:220px;
}

@media (max-width:1080px){
  .msg-attachment-text{
    max-width:180px;
  }
}



/* ===== RENAME INLINE CONTROL ===== */
.rename-inline {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.rename-input {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #1a1f2e;
  color: #fff;
  font-size: 0.85rem;
  width: 180px;
  min-width: 0;
}

.rename-input:focus {
  outline: none;
  border-color: var(--accent, #6c63ff);
}

/* ===== THREAD ACTIONS ROW ===== */
.thread-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn-danger {
  background: #7f1d1d;
  color: #fff;
  border: none;
}

.btn-danger:hover {
  background: #991b1b;
}

/* ===== MOBILE THREAD ACTIONS ===== */
@media (max-width: 1080px) {
  .thread-actions {
    width: 100%;
    justify-content: flex-start;
    margin-top: 8px;
  }

  .rename-input {
    width: 140px;
    font-size: 0.8rem;
  }

  .btn-sm {
    padding: 6px 10px;
    font-size: 0.78rem;
  }
}

/* ===== MOBILE GLOBAL IMPROVEMENTS ===== */
@media (max-width: 820px) {
  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .topbar h2 {
    font-size: 18px;
  }

  .identity-card {
    padding: 8px 12px;
    font-size: 0.82rem;
  }

  .brand h1 {
    font-size: 16px;
  }

  .nav-item {
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .badge {
    font-size: 0.7rem;
    padding: 2px 6px;
  }

  .conv-name {
    font-size: 0.95rem;
  }

  .conv-phone, .conv-snippet {
    font-size: 0.78rem;
  }

  .kpi {
    padding: 12px;
  }

  .kpi-value {
    font-size: 1.6rem;
  }

  .section-head h2 {
    font-size: 18px;
  }

  .card {
    padding: 14px;
  }
}

/* ===== TOUCH TARGETS ===== */
@media (max-width: 820px) {
  .btn {
    min-height: 40px;
    min-width: 40px;
  }

  .conv-item {
    padding: 12px;
    min-height: 72px;
  }

  .nav-item {
    min-height: 44px;
  }
}

/* ===== SUPPLIERS TAB ===== */
.supplier-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.supplier-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  flex-wrap: wrap;
}

.supplier-main {
  flex: 1;
  min-width: 140px;
}

.supplier-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.supplier-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 820px) {
  .supplier-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .supplier-actions {
    width: 100%;
  }

  .supplier-actions .btn {
    width: 100%;
    text-align: center;
  }
}

/* ================================================
   MOBILE CONVERSATION - COMPLETE REWRITE
   Mobile-first: list view by default, thread on tap
================================================ */

/* Desktop: side by side */
.conv-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  height: calc(100vh - 120px);
  min-height: 0;
}

.conv-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.conv-list-items {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.thread-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Back button - hidden on desktop */
.thread-back-btn {
  display: none;
}

/* Mobile: natural full-page list, thread on tap */
@media (max-width: 820px) {
  .conv-layout {
    display: block;
    height: auto;
    min-height: 0;
    gap: 0;
  }

  .conv-list {
    display: flex;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .conv-list-items {
    overflow: visible;
  }

  .thread-panel {
    display: none;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  body.mobile-thread-open .conv-list {
    display: none;
  }

  body.mobile-thread-open .thread-panel {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 24px);
  }

  body.mobile-thread-open .thread-back-btn {
    display: inline-flex;
    margin: 10px 12px 0;
    align-self: flex-start;
    background: transparent;
    border: 1px solid #444;
    color: #fff;
    font-size: 0.85rem;
    padding: 6px 14px;
    border-radius: 20px;
  }

  /* Thread head compact on mobile */
  .thread-head {
    padding: 8px 12px;
    flex-shrink: 0;
  }

  .thread-head-top {
    flex-direction: column;
    gap: 6px;
  }

  .thread-head-right {
    width: 100%;
  }

  .thread-actions {
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
  }

  .badges {
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
  }

  /* Thread body scrollable */
  .thread-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 12px;
  }

  /* Composer fixed at bottom */
  .composer {
    flex-shrink: 0;
    padding: 10px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
  }

  .composer-head {
    display: none;
  }

  .composer-grid textarea {
    min-height: 52px;
    font-size: 1rem;
  }

  .composer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .inline-controls {
    display: none;
  }

  /* Conv list items - comfortable touch targets */
  .conv-item {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    border-radius: 0;
    width: 100%;
    text-align: left;
    min-height: 76px;
  }

  .conv-name {
    font-size: 1rem;
    font-weight: 600;
  }

  .conv-phone {
    font-size: 0.78rem;
    color: var(--muted);
    margin: 2px 0;
  }

  .conv-snippet {
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Messages */
  .msg-wrap {
    margin-bottom: 10px;
  }

  .msg {
    max-width: 85%;
    font-size: 0.92rem;
  }

  /* Hide topbar on mobile when thread open to maximize space */
  body.mobile-thread-open .topbar {
    display: none;
  }
}

/* =========================
   MOBILE CONVERSATION FIX (AUTHORITATIVE)
========================= */

@media (max-width: 1080px){

  /* Default: show list, hide thread */
  #view-conversations .conv-list{
    display: block !important;
  }

  #view-conversations .thread-panel{
    display: none !important;
  }

  /* When thread is opened */
  body.mobile-thread-open #view-conversations .conv-list{
    display: none !important;
  }

  body.mobile-thread-open #view-conversations .thread-panel{
    display: flex !important;
  }
}

/* =========================
   MOBILE LAYOUT FIX (INBOX FULLSCREEN)
   Ensures mobile uses natural scroll instead of fixed-height panels
========================= */

@media (max-width: 820px){

  .conv-layout{
    display: block !important;
    height: auto !important;
  }

  .conv-list{
    height: auto !important;
    overflow: visible !important;
  }

  .thread-panel{
    height: auto !important;
  }

  .conv-list-items{
    overflow: visible !important;
  }
}


/* ===== KPI CARD CONTRAST FIX ===== */
.kpi {
  background: rgba(255,255,255,0.06) !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
}

.kpi-value {
  color: #ffffff !important;
  font-size: 2rem !important;
  font-weight: 700 !important;
}

.kpi-label {
  color: rgba(255,255,255,0.75) !important;
  font-size: 0.82rem !important;
  font-weight: 500 !important;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi.tone-danger { border-left: 3px solid #ef4444 !important; }
.kpi.tone-warn { border-left: 3px solid #f59e0b !important; }
.kpi.tone-accent { border-left: 3px solid #6c63ff !important; }
.kpi.tone-good { border-left: 3px solid #10b981 !important; }
.kpi.tone-info { border-left: 3px solid #3b82f6 !important; }

.kpi.tone-danger .kpi-value { color: #fca5a5 !important; }
.kpi.tone-warn .kpi-value { color: #fcd34d !important; }
.kpi.tone-accent .kpi-value { color: #a5b4fc !important; }
.kpi.tone-good .kpi-value { color: #6ee7b7 !important; }

/* ===== INVOICE DETAIL PANEL ===== */
.invoice-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 16px;
}

.invoice-detail-overlay.open {
  opacity: 1;
}

.invoice-detail-panel {
  width: 100%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.invoice-detail-overlay.open .invoice-detail-panel {
  transform: translateY(0);
}

.invoice-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.invoice-detail-head h2 {
  margin: 0 0 4px;
  font-size: 1.2rem;
}

.invoice-detail-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.invoice-detail-body {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.invoice-doc-viewer {
  padding: 16px;
  overflow: auto;
  border-right: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
}

.invoice-doc-frame {
  width: 100%;
  flex: 1;
  min-height: 400px;
  border: none;
  border-radius: 8px;
  background: #fff;
}

.invoice-doc-img {
  width: 100%;
  border-radius: 8px;
  object-fit: contain;
}

.invoice-doc-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 200px;
  color: var(--muted);
  font-size: 1rem;
}

.invoice-detail-sidebar {
  padding: 16px;
  overflow-y: auto;
}

.invoice-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.88rem;
}

.invoice-row.clickable {
  cursor: pointer;
  transition: background 0.15s;
}

.invoice-row.clickable:hover {
  background: rgba(255,255,255,0.04);
}

.label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@media (max-width: 820px) {
  .invoice-detail-body {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .invoice-doc-viewer {
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-height: 250px;
  }

  .invoice-detail-panel {
    max-height: 95vh;
  }
}

/* ===== INVOICE PANEL - MOBILE CEO OPTIMIZED ===== */
@media (max-width: 820px) {
  .invoice-detail-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .invoice-detail-panel {
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    width: 100%;
  }

  .invoice-detail-head {
    padding: 14px 16px;
  }

  .invoice-detail-head h2 {
    font-size: 1rem;
  }

  .invoice-detail-body {
    grid-template-columns: 1fr;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* On mobile - show sidebar first (actions), then document */
  .invoice-detail-body {
    display: flex;
    flex-direction: column-reverse;
  }

  .invoice-doc-viewer {
    border-right: none;
    border-top: 1px solid rgba(255,255,255,0.08);
    min-height: 220px;
    padding: 12px;
  }

  .invoice-doc-frame {
    min-height: 260px;
  }

  .invoice-detail-sidebar {
    padding: 12px;
  }

  /* Status and meta rows - bigger touch targets */
  .invoice-meta-row {
    padding: 10px 0;
    font-size: 0.92rem;
  }

  /* Workflow action buttons - large and thumb-friendly */
  .workflow-action-btn {
    min-height: 52px !important;
    font-size: 1rem !important;
    border-radius: 12px !important;
    font-weight: 600 !important;
  }

  /* Save button */
  #save-invoice-details-btn {
    min-height: 48px;
    font-size: 0.95rem;
    border-radius: 10px;
  }

  /* Inputs - larger for mobile */
  .rename-input {
    min-height: 44px;
    font-size: 1rem;
    padding: 10px 12px;
  }

  /* Close button */
  #close-invoice-panel {
    min-height: 40px;
    min-width: 80px;
    font-size: 0.88rem;
  }

  /* Invoice list rows - larger touch targets */
  .invoice-row.clickable {
    padding: 14px 12px;
    min-height: 56px;
  }

  /* Stack invoice table on mobile */
  .invoice-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .invoice-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
  }

  .invoice-head {
    display: none;
  }

  .invoice-row > div::before {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: block;
    margin-bottom: 2px;
  }

  .invoice-row > div:nth-child(1)::before { content: ""; }
  .invoice-row > div:nth-child(2)::before { content: "Invoice #"; }
  .invoice-row > div:nth-child(3)::before { content: "Supplier"; }
  .invoice-row > div:nth-child(4)::before { content: "Site"; }
  .invoice-row > div:nth-child(5)::before { content: "Status"; }
  .invoice-row > div:nth-child(6)::before { content: "Amount"; }
  .invoice-row > div:nth-child(7)::before { content: "Due Date"; }
  .invoice-row > div:nth-child(8)::before { content: "Received"; }
}

/* ===== DATE INPUT FIX ===== */
input[type="date"] {
  color-scheme: dark;
  color: #ffffff;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(1.5);
  cursor: pointer;
  opacity: 0.8;
}

input[type="date"]::-webkit-datetime-edit-fields-wrapper {
  color: #ffffff;
}

input[type="date"]::-webkit-datetime-edit-text {
  color: rgba(255,255,255,0.5);
}

/* ===== DATE PICKER ICON - FORCE VISIBLE ===== */
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(2) !important;
  opacity: 1 !important;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.15);
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
  background: rgba(255,255,255,0.25);
}

/* ===== DATE ICON CONTRAST ===== */
input[type="date"] {
  color-scheme: dark;
  background: #1e2640 !important;
  color: #ffffff !important;
}

::-webkit-calendar-picker-indicator {
  filter: invert(1) !important;
  opacity: 1 !important;
}

/* ===== DATE INPUT LIGHT BACKGROUND FIX ===== */
input[type="date"] {
  background: rgba(255,255,255,0.12) !important;
  color: #ffffff !important;
  color-scheme: dark !important;
}

/* ===== DATE INPUT - FORCE LIGHT ===== */
input[type="date"] {
  background: #f0f4ff !important;
  color: #1a1f2e !important;
  color-scheme: light !important;
  border: 1px solid rgba(255,255,255,0.3) !important;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: none !important;
  opacity: 1 !important;
  cursor: pointer;
}

/* ===== DATE INPUT - FINAL FIX ===== */
input[type="date"] {
  background: #2a3350 !important;
  color: #ffffff !important;
  color-scheme: dark !important;
  border: 1px solid rgba(108,99,255,0.5) !important;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  background-color: rgba(108,99,255,0.6) !important;
  border-radius: 4px !important;
  padding: 3px !important;
  filter: invert(1) !important;
  opacity: 1 !important;
  cursor: pointer !important;
}

/* ===== OVERVIEW MOBILE-FIRST REDESIGN ===== */
.overview-priority-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.overview-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.overview-card {
  padding: 16px;
}

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

.overview-card-head h3 {
  margin: 0;
  font-size: 0.95rem;
}

.overview-queue-item {
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: pointer;
  transition: background 0.15s;
}

.overview-queue-item:last-child {
  border-bottom: none;
}

.overview-queue-item:hover {
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  padding: 10px 6px;
}

.overview-queue-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  margin-bottom: 2px;
}

.overview-queue-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Mobile: 2x2 grid for KPIs, stack bottom cards */
@media (max-width: 820px) {
  .overview-priority-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .overview-bottom-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .kpi {
    padding: 14px 12px;
  }

  .kpi-value {
    font-size: 1.6rem !important;
  }

  .kpi-label {
    font-size: 0.72rem !important;
  }

  .overview-card {
    padding: 14px;
  }

  .overview-card-head h3 {
    font-size: 0.88rem;
  }
}

/* ===== MOBILE INVOICE LIST - CLEAN CARDS ===== */
@media (max-width: 820px) {
  .invoice-table-wrap {
    padding: 8px !important;
  }

  .invoice-table {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
  }

  .invoice-head {
    display: none !important;
  }

  .invoice-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
  }

  .invoice-row.clickable {
    background: rgba(255,255,255,0.04) !important;
    border: 1px solid rgba(255,255,255,0.08) !important;
    border-radius: 12px !important;
    padding: 14px !important;
    cursor: pointer !important;
  }

  .invoice-row.clickable:active {
    background: rgba(255,255,255,0.08) !important;
  }

  /* Hide the ::before labels we added earlier - use custom layout */
  .invoice-row > div::before {
    display: none !important;
  }

  /* Custom mobile card layout */
  .invoice-row.clickable > div:nth-child(1) {
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 2px;
  }

  .invoice-row.clickable > div:nth-child(2) {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 2px;
  }

  .invoice-row.clickable > div:nth-child(3) {
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 8px;
  }

  .invoice-row.clickable > div:nth-child(4) {
    margin-bottom: 8px;
  }

  .invoice-row.clickable > div:nth-child(5) {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
  }

  .invoice-row.clickable > div:nth-child(6),
  .invoice-row.clickable > div:nth-child(7) {
    font-size: 0.78rem;
    color: var(--muted);
  }
}

/* ===== INVOICE CARD - MOBILE PROPER ===== */
@media (max-width: 820px) {
  .inv-cell { display: block; }

  .inv-number {
    font-size: 0.72rem !important;
    color: var(--muted) !important;
    font-weight: 400 !important;
    margin-bottom: 2px !important;
  }

  .inv-supplier {
    font-size: 1rem !important;
    font-weight: 700 !important;
    color: #fff !important;
    margin-bottom: 2px !important;
  }

  .inv-site {
    font-size: 0.82rem !important;
    color: var(--muted) !important;
    margin-bottom: 8px !important;
  }

  .inv-status {
    margin-bottom: 8px !important;
  }

  .inv-amount {
    font-size: 1.15rem !important;
    font-weight: 700 !important;
    color: #fff !important;
    margin-bottom: 6px !important;
  }

  .inv-due, .inv-received {
    font-size: 0.78rem !important;
    color: var(--muted) !important;
    display: inline !important;
    margin-right: 12px !important;
  }
}

/* Desktop - keep table layout */
@media (min-width: 821px) {
  .inv-cell { display: contents; }
}

/* ===== INVOICE CARD CONTRAST FIX ===== */
@media (max-width: 820px) {
  .invoice-row.clickable {
    background: rgba(255,255,255,0.08) !important;
    border: 1px solid rgba(255,255,255,0.15) !important;
    border-radius: 14px !important;
    padding: 16px !important;
    margin-bottom: 2px;
  }

  .invoice-row.clickable:active {
    background: rgba(255,255,255,0.14) !important;
    transform: scale(0.99);
  }

  /* Remove the stacked header row on mobile */
  .invoice-row:not(.clickable) {
    display: none !important;
  }
}

/* ===== INVOICE TABLE - DESKTOP RESTORE ===== */
@media (min-width: 821px) {
  .invoice-row {
    display: grid !important;
    grid-template-columns: 1fr 1.5fr 1fr 1.5fr 1fr 1fr 1fr !important;
    flex-direction: unset !important;
    padding: 12px 16px !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    border-bottom: 1px solid rgba(255,255,255,0.05) !important;
  }

  .invoice-row.invoice-head {
    background: rgba(255,255,255,0.03) !important;
    font-size: 0.75rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    color: var(--muted) !important;
  }

  .invoice-row > div::before {
    display: none !important;
  }
}

/* ===== INVOICE PANEL HEADER - MOBILE FIX ===== */
@media (max-width: 820px) {
  .invoice-detail-head {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 14px 16px !important;
  }

  .invoice-detail-head > div:last-child {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .invoice-detail-head .workflow-action-btn {
    flex: 1 !important;
    min-width: 120px !important;
    min-height: 48px !important;
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    border-radius: 10px !important;
  }

  .invoice-detail-head #close-invoice-panel {
    width: 100% !important;
    min-height: 40px !important;
    text-align: center !important;
    opacity: 0.7 !important;
  }
}

/* ===== ACTIVE KPI TILE ===== */
.kpi-active {
  border: 2px solid rgba(255,255,255,0.4) !important;
  transform: scale(1.02);
  box-shadow: 0 0 20px rgba(255,255,255,0.1);
}

.kpi[onclick] {
  transition: transform 0.15s, box-shadow 0.15s;
}

.kpi[onclick]:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.kpi[onclick]:active {
  transform: scale(0.98);
}

/* ===== MOBILE INVOICE CARD - ENHANCED VISIBILITY ===== */
@media (max-width: 820px) {
  .invoice-row.clickable {
    background: linear-gradient(135deg, rgba(255,255,255,0.07) 0%, rgba(255,255,255,0.03) 100%) !important;
    border: 1px solid rgba(255,255,255,0.18) !important;
    border-radius: 16px !important;
    padding: 16px !important;
    margin-bottom: 8px !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.08) !important;
    backdrop-filter: blur(10px) !important;
    transition: transform 0.15s, box-shadow 0.15s !important;
  }

  .invoice-row.clickable:active {
    transform: scale(0.98) !important;
    box-shadow: 0 1px 6px rgba(0,0,0,0.2) !important;
  }

  /* Color accent on left border based on status badge inside */
  .invoice-row.clickable:has(.badge.warn) {
    border-left: 3px solid rgba(245, 158, 11, 0.6) !important;
  }

  .invoice-row.clickable:has(.badge.good) {
    border-left: 3px solid rgba(16, 185, 129, 0.6) !important;
  }

  .invoice-row.clickable:has(.badge.info) {
    border-left: 3px solid rgba(59, 130, 246, 0.6) !important;
  }

  .invoice-row.clickable:has(.badge.danger) {
    border-left: 3px solid rgba(239, 68, 68, 0.6) !important;
  }

  /* Better text hierarchy */
  .inv-number {
    font-size: 0.7rem !important;
    color: rgba(255,255,255,0.4) !important;
    letter-spacing: 0.05em !important;
    text-transform: uppercase !important;
    margin-bottom: 3px !important;
  }

  .inv-supplier {
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    color: #ffffff !important;
    margin-bottom: 2px !important;
  }

  .inv-site {
    font-size: 0.82rem !important;
    color: rgba(255,255,255,0.55) !important;
    margin-bottom: 10px !important;
  }

  .inv-amount {
    font-size: 1.2rem !important;
    font-weight: 700 !important;
    color: #ffffff !important;
    margin-top: 8px !important;
    margin-bottom: 6px !important;
  }

  .inv-due, .inv-received {
    font-size: 0.75rem !important;
    color: rgba(255,255,255,0.45) !important;
  }
}

/* ===== MOBILE CONVERSATION LIST - POLISH ===== */
@media (max-width: 820px) {
  /* Hide redundant list header */
  .conv-list-head {
    display: none !important;
  }

  .conv-list-items {
    padding: 8px !important;
  }

  /* Conversation cards */
  .conv-item {
    background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.02) 100%) !important;
    border: 1px solid rgba(255,255,255,0.12) !important;
    border-radius: 14px !important;
    padding: 14px 16px !important;
    margin-bottom: 8px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2) !important;
    width: 100% !important;
    text-align: left !important;
  }

  .conv-item.active,
  .conv-item:active {
    border-color: rgba(108,99,255,0.5) !important;
    background: linear-gradient(135deg, rgba(108,99,255,0.12) 0%, rgba(108,99,255,0.04) 100%) !important;
  }

  .conv-item-top {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 3px !important;
  }

  .conv-name {
    font-size: 1rem !important;
    font-weight: 700 !important;
    color: #ffffff !important;
  }

  .conv-phone {
    font-size: 0.75rem !important;
    color: rgba(255,255,255,0.4) !important;
    margin-bottom: 4px !important;
  }

  .conv-snippet {
    font-size: 0.82rem !important;
    color: rgba(255,255,255,0.55) !important;
    margin-bottom: 8px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .conv-item .small {
    font-size: 0.72rem !important;
    color: rgba(255,255,255,0.35) !important;
  }

  /* ===== MOBILE CHAT VIEW - POLISH ===== */

  /* Back button */
  .thread-back-btn {
    margin: 10px 12px 6px !important;
    background: rgba(255,255,255,0.08) !important;
    border: 1px solid rgba(255,255,255,0.15) !important;
    border-radius: 20px !important;
    padding: 8px 18px !important;
    font-size: 0.85rem !important;
    color: #fff !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-weight: 500 !important;
  }

  /* Thread header */
  .thread-head {
    padding: 10px 14px 8px !important;
    border-bottom: 1px solid rgba(255,255,255,0.06) !important;
  }

  .thread-head-identity .conv-name {
    font-size: 1.05rem !important;
    font-weight: 700 !important;
  }

  .thread-head-identity .thread-sub {
    font-size: 0.75rem !important;
    color: rgba(255,255,255,0.45) !important;
    margin-top: 1px !important;
  }

  .thread-head-right .badges {
    margin-top: 6px !important;
    flex-wrap: wrap !important;
    gap: 4px !important;
  }

  .thread-actions {
    margin-top: 8px !important;
    gap: 6px !important;
    flex-wrap: wrap !important;
  }

  /* Messages */
  .thread-body {
    padding: 12px 10px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
  }

  .msg-wrap {
    display: flex !important;
    margin-bottom: 0 !important;
  }

  .msg-wrap.inbound { justify-content: flex-start !important; }
  .msg-wrap.outbound { justify-content: flex-end !important; }

  .msg {
    max-width: 80% !important;
    border-radius: 16px !important;
    padding: 10px 14px !important;
  }

  .msg.inbound {
    background: rgba(255,255,255,0.09) !important;
    border-bottom-left-radius: 4px !important;
  }

  .msg.outbound {
    background: rgba(108,99,255,0.4) !important;
    border-bottom-right-radius: 4px !important;
  }

  .msg-meta {
    font-size: 0.68rem !important;
    color: rgba(255,255,255,0.4) !important;
    margin-bottom: 4px !important;
    display: flex !important;
    justify-content: space-between !important;
    gap: 8px !important;
  }

  .msg-text {
    font-size: 0.92rem !important;
    line-height: 1.5 !important;
    color: #ffffff !important;
    word-break: break-word !important;
  }

  /* Sticky composer */
  .composer {
    padding: 10px 12px !important;
    background: rgba(8,12,28,0.97) !important;
    border-top: 1px solid rgba(255,255,255,0.08) !important;
    backdrop-filter: blur(12px) !important;
    flex-shrink: 0 !important;
  }

  .composer-head { display: none !important; }

  .composer-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  .composer-grid textarea {
    border-radius: 12px !important;
    padding: 12px 14px !important;
    font-size: 0.95rem !important;
    min-height: 48px !important;
    max-height: 120px !important;
    resize: none !important;
    background: rgba(255,255,255,0.08) !important;
    border: 1px solid rgba(255,255,255,0.12) !important;
    color: #fff !important;
    line-height: 1.5 !important;
  }

  .composer-actions {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
  }

  .inline-controls { display: none !important; }

  #send-message-btn {
    min-height: 44px !important;
    min-width: 90px !important;
    border-radius: 22px !important;
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    padding: 0 24px !important;
  }
}

/* ===== INVOICE TABLE WITH CHECKBOX COLUMN ===== */
@media (min-width: 821px) {
  .invoice-row {
    grid-template-columns: 32px 1fr 1.5fr 1fr 1.5fr 1fr 1fr 1fr !important;
  }
}

.invoice-checkbox {
  accent-color: #6c63ff;
}

#bulk-delete-invoices-btn {
  white-space: nowrap;
}

/* ===== COMPACT REVIEWER ASSIGNMENT ===== */
.assignment-compact {
  padding: 6px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.02);
}

.assignment-compact-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}

.assignment-compact-label {
  font-size: 0.85rem;
}

.assignment-compact-edit {
  margin-left: auto;
  font-size: 0.8rem;
  opacity: 0.5;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: opacity 0.15s;
}

.assignment-compact-edit:hover {
  opacity: 1;
  background: rgba(255,255,255,0.08);
}

.assignment-body {
  padding: 8px 0 4px;
}

.assignment-inline-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.assignment-select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: #1a1f2e;
  color: #fff;
  font-size: 0.82rem;
  flex: 1;
  min-width: 120px;
  color-scheme: dark;
  appearance: auto;
}
.assignment-select option {
  background: #1a1f2e;
  color: #fff;
}

.assignment-input {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 0.82rem;
  width: 100%;
}

@media (max-width: 820px) {
  .assignment-inline-grid {
    flex-direction: column;
    align-items: stretch;
  }

  .assignment-select {
    width: 100%;
  }
}

/* ===== INVOICE AMOUNT COLUMN FIX ===== */
@media (min-width: 821px) {
  .invoice-row {
    grid-template-columns: 32px 1fr 1.5fr 1fr 1.5fr 1.2fr 1fr 1fr !important;
  }

  .inv-amount {
    font-size: 0.88rem !important;
    white-space: nowrap !important;
  }
}

/* ===== COMPACT THREAD HEADER ===== */
.thread-head-compact {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-wrap: wrap;
  min-height: 48px;
}

.thread-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.thread-supplier-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
}

.thread-phone {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.4);
}

.thread-head-center {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  flex: 1;
}

.thread-head-right {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.btn-xs {
  padding: 4px 10px !important;
  font-size: 0.78rem !important;
  border-radius: 6px !important;
  min-height: 28px !important;
}

.rename-input-inline {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(108,99,255,0.5);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 0.9rem;
  width: 150px;
}

#thread-edit-panel {
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

@media (max-width: 820px) {
  .thread-head-compact {
    gap: 8px;
    padding: 8px 12px;
  }

  .thread-head-center {
    width: 100%;
    order: 3;
  }

  .thread-head-right {
    margin-left: auto;
  }

  .btn-xs {
    min-height: 34px !important;
    padding: 6px 12px !important;
  }
}

/* ===== THREAD HEADER ACCENT LINE ===== */
.thread-head-compact {
  border-left: 3px solid rgba(108,99,255,0.6) !important;
  background: linear-gradient(90deg, rgba(108,99,255,0.06) 0%, transparent 100%) !important;
}

/* ===== MOBILE THREAD HEADER FIX ===== */
@media (max-width: 820px) {
  .thread-head-compact {
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    grid-template-rows: auto auto !important;
    gap: 6px 8px !important;
    padding: 10px 12px !important;
    align-items: center !important;
  }

  .thread-head-left {
    grid-column: 1 !important;
    grid-row: 1 !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 2px !important;
  }

  .thread-head-right {
    grid-column: 2 !important;
    grid-row: 1 !important;
    flex-direction: row !important;
    gap: 6px !important;
  }

  .thread-head-center {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    width: 100% !important;
    order: unset !important;
    gap: 4px !important;
  }

  .thread-supplier-name {
    font-size: 1rem !important;
    font-weight: 700 !important;
  }

  .thread-phone {
    font-size: 0.72rem !important;
  }

  .btn-xs {
    min-height: 34px !important;
    padding: 6px 14px !important;
    font-size: 0.82rem !important;
  }
}

/* ===== THREAD HEADER BOTTOM ACCENT LINE ===== */
.thread-head-compact {
  border-left: none !important;
  border-bottom: 2px solid rgba(108,99,255,0.5) !important;
  background: linear-gradient(180deg, rgba(108,99,255,0.05) 0%, transparent 100%) !important;
  box-shadow: 0 2px 12px rgba(108,99,255,0.08) !important;
}


/* Payments table spacing hardening */
.payments-grid .invoice-row,
.payments-grid .invoice-table-head {
  grid-template-columns: minmax(120px,1.2fr) minmax(140px,1.4fr) minmax(120px,1fr) minmax(90px,0.9fr) minmax(120px,1fr) minmax(120px,1fr) minmax(120px,1fr) minmax(180px,1.3fr);
  column-gap: 14px;
}

.payments-grid .invoice-row > div,
.payments-grid .invoice-table-head > div {
  min-width: 0;
}

.payments-grid .invoice-table-head > div {
  white-space: normal;
  line-height: 1.2;
}

.payments-grid .invoice-row > div:nth-child(1),
.payments-grid .invoice-row > div:nth-child(2),
.payments-grid .invoice-row > div:nth-child(3) {
  overflow-wrap: anywhere;
}

.payments-grid .invoice-row > div:last-child {
  display: flex;
  justify-content: flex-end;
}

.payments-grid .invoice-row > div:last-child > div {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}


/* ===== Payments Table FIX (direct override) ===== */
.invoice-table {
  column-gap: 16px !important;
}

.invoice-table .invoice-row,
.invoice-table .invoice-head {
  display: grid !important;
  align-items: center !important;
}

.invoice-table .invoice-row > div,
.invoice-table .invoice-head > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

.invoice-table .invoice-head > div {
  white-space: normal;
  line-height: 1.2;
}

.invoice-table .invoice-row > div:nth-child(1),
.invoice-table .invoice-row > div:nth-child(2) {
  padding-right: 8px;
}

.invoice-table .invoice-row > div:last-child {
  display: flex;
  justify-content: flex-end;
}

.invoice-table .invoice-row > div:last-child > div {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}


/* ===== Payments table isolated layout fix ===== */
.invoice-table-wrap {
  overflow-x: auto;
}

.payments-table {
  min-width: 1180px;
  column-gap: 16px !important;
}

.payments-table .invoice-row,
.payments-table .invoice-head {
  display: grid !important;
  align-items: center !important;
}

.payments-table .invoice-row > div,
.payments-table .invoice-head > div {
  min-width: 0;
}

.payments-table .invoice-head > div:nth-child(1),
.payments-table .invoice-row > div:nth-child(1),
.payments-table .invoice-head > div:nth-child(2),
.payments-table .invoice-row > div:nth-child(2),
.payments-table .invoice-head > div:nth-child(8),
.payments-table .invoice-row > div:nth-child(8) {
  white-space: nowrap;
}

.payments-table .invoice-row > div:last-child {
  display: flex;
  justify-content: flex-end;
}

.payments-table .invoice-row > div:last-child > div {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}


/* ===== Payments table: force desktop behavior ===== */
.payments-table {
  min-width: 1100px;
}

.payments-table .invoice-row {
  display: grid !important;
  flex-direction: unset !important;
}

.payments-table .invoice-head {
  display: grid !important;
}

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


/* Payments table: isolate from invoice clickable/card behavior */
.payments-table .payment-row {
  cursor: default !important;
  display: grid !important;
  flex-direction: unset !important;
}

.payments-table .invoice-head {
  display: grid !important;
}

.payments-table .payment-row > div,
.payments-table .invoice-head > div {
  white-space: nowrap;
}

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


/* ===== Dedicated Payments Table Rebuild ===== */
.payments-table-wrap {
  overflow-x: auto;
}

.payments-table-grid {
  min-width: 1180px;
}

.payments-head,
.payments-row {
  display: grid;
  grid-template-columns: 170px 190px 120px 110px 150px 150px 150px 170px;
  column-gap: 16px;
  align-items: center;
}

.payments-head {
  padding: 14px 16px;
  background: rgba(255,255,255,0.03);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.payments-row {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.payments-head > div,
.payments-row > div {
  min-width: 0;
}

.payments-head > div:nth-child(1),
.payments-head > div:nth-child(2),
.payments-row > div:nth-child(1),
.payments-row > div:nth-child(2),
.payments-row > div:nth-child(3) {
  white-space: nowrap;
}

.payments-row > div:nth-child(1) {
  font-weight: 600;
}

.payments-row > div:last-child {
  display: flex;
  justify-content: flex-end;
}

.payments-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.payments-actions .btn {
  width: max-content;
}

@media (max-width: 820px) {
  .payments-table-grid {
    min-width: 1180px;
  }
}


/* ===== Payments scroll UX improvement ===== */
.payments-table-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.25) transparent;
  cursor: grab;
}

.payments-table-wrap:active {
  cursor: grabbing;
}

/* Webkit (Chrome/Safari) */
.payments-table-wrap::-webkit-scrollbar {
  height: 8px;
}

.payments-table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.payments-table-wrap::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.25);
  border-radius: 6px;
}

.payments-table-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.4);
}

/* ===== REPORTS TABLE FIX ===== */
.report-table-row {
  display: grid !important;
  grid-template-columns: 1.5fr 0.7fr 1.2fr 1.2fr 1.2fr 1.5fr !important;
  gap: 12px !important;
  padding: 12px 16px !important;
  border-bottom: 1px solid rgba(255,255,255,0.05) !important;
  align-items: center !important;
  font-size: 0.88rem !important;
}

.report-table-head div {
  font-size: 0.72rem !important;
  text-transform: uppercase !important;
  letter-spacing: 0.05em !important;
  color: rgba(255,255,255,0.45) !important;
  font-weight: 600 !important;
}

/* Summary stats row - make horizontal */
.report-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.report-stat-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.report-stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.5);
  margin-bottom: 6px;
}

.report-stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
}

/* Chart containers */
.report-chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.report-chart-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 16px;
}

.report-chart-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@media (max-width: 820px) {
  .report-chart-grid {
    grid-template-columns: 1fr;
  }

  .report-stats-row {
    grid-template-columns: 1fr;
  }

  .report-table-row {
    grid-template-columns: 1fr 1fr !important;
    font-size: 0.82rem !important;
  }

  .report-table-head {
    display: none !important;
  }

  .report-table-row > div:nth-child(1) {
    grid-column: 1 / -1;
    font-weight: 700;
    font-size: 0.95rem !important;
  }
}

/* ===== CHARTS SIZE REDUCTION ===== */
.report-chart-card canvas {
  max-height: 200px !important;
}

.report-chart-card {
  padding: 14px !important;
}

/* ===== NEW CONVERSATION MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.hidden {
  display: none;
}
.modal-box {
  width: 100%;
  max-width: 440px;
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-body {
  display: flex;
  flex-direction: column;
}
.modal-label {
  font-size: 0.82em;
  color: var(--muted);
  margin-bottom: 4px;
  display: block;
}

/* ===== REPORT SECTION TITLES — GLASSMORPHIC ===== */
.report-section-title {
  font-size: 0.82rem !important;
  font-weight: 700 !important;
  letter-spacing: 0.06em !important;
  text-transform: uppercase !important;
  color: var(--text) !important;
  background: linear-gradient(135deg, rgba(99,102,241,0.18) 0%, rgba(139,92,246,0.10) 100%) !important;
  border: 1px solid rgba(99,102,241,0.25) !important;
  border-left: 3px solid var(--accent) !important;
  border-radius: 8px !important;
  padding: 10px 16px !important;
  margin-bottom: 12px !important;
  margin-top: 8px !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
}
