/* ============================================================
   1. CSS VARIABLES & RESET
   ============================================================ */
:root {
  --brand-primary: #111827;
  --rh-gray: #f4f7f9;
  --rh-text: #2c3e50;
  --rh-border: #dfe3e8;
  --rh-muted: #999;
  --rh-muted-dark: #888;
  --rh-muted-light: #666;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --font-xs: 0.6rem;
  --font-sm: 0.65rem;
  --font-md: 0.7rem;
  --font-base: 0.75rem;
  --font-body: 0.8rem;
  --font-input: 0.85rem;
}

* { box-sizing: border-box; font-family: 'Inter', sans-serif; }

body {
  margin: 0;
  background: var(--rh-gray);
  color: var(--rh-text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Auth Overlay Styles */
#auth-overlay {
  position: fixed; inset: 0; background: #111827; z-index: 10000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: white;
}
.auth-card {
  background: white; padding: 40px; border-radius: 16px; text-align: center; color: #111827;
  max-width: 420px; width: 100%; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
}
.btn-google {
  background: #ffffff; color: #3c4043; border: 1px solid #dadce0; padding: 12px 24px;
  border-radius: 8px; font-weight: 600; cursor: pointer; width: 100%; font-size: 1rem;
  display: flex; align-items: center; justify-content: center; transition: background 0.2s, border-color 0.2s;
}
.btn-google:hover { background: #f8f9fa; border-color: #d2e3fc; }

/* ============================================================
   2. LOADING OVERLAY & SPINNER
   ============================================================ */
#loading-overlay {
  position: fixed; inset: 0; background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(2px); display: none; align-items: center; justify-content: center;
  z-index: 9999; pointer-events: all; cursor: wait;
}
.spinner {
  border: 3px solid #f3f3f3; border-top: 3px solid var(--brand-primary);
  border-radius: 50%; width: 30px; height: 30px; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   3. HEADER
   ============================================================ */
header {
  background: #fff; padding: 15px 30px; border-bottom: 1px solid var(--rh-border);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.header-actions { display: flex; gap: 10px; }
.view-toggle { background: #eee; padding: 4px; border-radius: var(--radius-md); display: flex; gap: 4px; }

/* Module Switcher — context indicator dropdown */
.module-switcher { position: relative; display: flex; align-items: center; }

.module-switcher-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 4px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--brand-primary);
  letter-spacing: -0.01em;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.module-switcher-btn:hover { background: var(--rh-gray); }
.module-switcher-btn svg { color: var(--rh-muted); flex-shrink: 0; transition: transform 0.2s; }
.module-switcher-btn.open svg { transform: rotate(180deg); }

.module-switcher-drop {
  width: 220px;
  left: auto;
  right: 0;
  padding: 6px;
}

.module-drop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.module-drop-item:hover { background: var(--rh-gray); }
.module-drop-item.active { background: #f0f4ff; }

.module-drop-icon {
  font-size: 1.2rem;
  color: var(--rh-muted);
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.module-drop-label { font-weight: 700; font-size: 0.875rem; color: var(--brand-primary); }
.module-drop-desc { font-size: 0.75rem; color: var(--rh-muted); margin-top: 1px; }

/* Vertical separator between switcher and view toggle */
.header-sep {
  width: 2px;
  height: 22px;
  background: #c5c9d0;
  margin: 0 6px;
  align-self: center;
  border-radius: 1px;
}

/* ============================================================
   4. FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex; gap: 20px; background: #fff; padding: 10px 30px;
  border-bottom: 1px solid var(--rh-border); align-items: flex-end; flex-shrink: 0;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; position: relative; }
.filter-group label { font-size: var(--font-sm); font-weight: 700; text-transform: uppercase; color: var(--rh-muted); }
.filter-group .btn-ghost { min-width: 110px; display: flex; justify-content: space-between; align-items: center; }

.dropdown-content {
  position: absolute; top: 100%; left: 0; background: white; border: 1px solid var(--rh-border);
  border-radius: var(--radius-sm); z-index: 100; padding: 10px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  width: 220px; display: none; margin-top: 5px;
}
.dropdown-content.show { display: block; }
.dropdown-option { 
  display: flex; 
  align-items: center;
  gap: 8px;
  padding: 6px 8px; 
  font-size: var(--font-sm); 
  font-weight: 700;
  text-transform: uppercase;
  color: var(--rh-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}
.dropdown-option:hover { background: var(--rh-gray); color: var(--rh-muted-dark); }
.dropdown-option input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; flex-shrink: 0; }
.comp-search-list { margin-top: 6px; max-height: 200px; overflow-y: auto; }

.btn-clear-filters { color: var(--brand-primary); border-color: var(--brand-primary); }
#gamification-stats { margin-left: auto; display: flex; align-items: flex-end; padding-bottom: 2px; }
.gamification-bar {
  color: #166534; background: #f0fdf4; padding: 6px 12px; border-radius: var(--radius-md);
  border: 1px solid #bbf7d0; display: flex; gap: 15px; font-size: var(--font-base); font-weight: 700;
}

/* ============================================================
   5. FORM INPUTS & LAYOUT
   ============================================================ */
input, select, textarea {
  padding: 8px 12px; border: 1px solid var(--rh-border); border-radius: var(--radius-sm);
  font-size: var(--font-input); outline: none;
}
input:disabled, select:disabled, textarea:disabled { background: #f9f9f9 !important; cursor: not-allowed; opacity: 0.7; }

#app-container { display: flex; flex-direction: column; height: 100vh; }
main { display: grid; grid-template-columns: 400px 1fr; flex: 1; overflow: hidden; }

.inline-edit-input {
  font-size: inherit;
  font-weight: inherit;
  border: 2px solid #1a73e8; /* Google Sheets Blue */
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  margin: -4px -8px;
  width: 100%;
  outline: none;
  background: #fff;
  color: var(--brand-primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.tag-selection-container {
  display: flex;
  gap: 10px;
  margin-top: 5px;
  flex-wrap: wrap;
}
.tag-select-pill {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: var(--font-xs);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--rh-border);
  background: white;
  color: var(--rh-muted-light);
  transition: all 0.2s ease;
  user-select: none;
}
.tag-select-pill:hover { background: var(--rh-gray); }

/* Specific Colors for Active Tags */
.tag-select-pill.active[data-tag="Sales"] {
  background: #e0e7ff; color: #3730a3; border-color: #c7d2fe;
}
.tag-select-pill.active[data-tag="Partnerships"] {
  background: #dcfce7; color: #166534; border-color: #bbf7d0;
}
.tag-select-pill.active[data-tag="Inbound"] {
  background: #f3e8ff; color: #6b21a8; border-color: #d8b4fe;
}
.tag-select-pill.active[data-tag="Invoices"] {
  background: #d1fae5; color: #065f46; border-color: #a7f3d0;
}
/* Fallback color for any future tags */
.tag-select-pill.active {
  background: #f1f5f9; color: #475569; border-color: #e2e8f0;
}

/* ============================================================
   7. PROJECT LIST (LEFT PANEL) & KANBAN
   ============================================================ */
#project-list { border-right: 1px solid var(--rh-border); overflow-y: auto; padding: 20px 20px 80px 20px; background: #fff; }
#list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; border-bottom: 1px solid #eee; padding-bottom: 10px; }
#list-header-title { font-weight: 700; }
#result-count { font-size: var(--font-md); font-weight: 700; color: var(--rh-muted); text-transform: uppercase; }

#kanban-view { display: none; padding: 20px 20px 80px 20px; gap: 20px; overflow-x: auto; flex: 1; background: var(--rh-gray); }
.kanban-col { min-width: 300px; max-width: 300px; display: flex; flex-direction: column; gap: 12px; }
.col-title { font-size: var(--font-base); font-weight: 700; text-transform: uppercase; color: var(--rh-muted-light); margin-bottom: 5px; display: flex; justify-content: space-between; }

/* ============================================================
   9. CARDS
   ============================================================ */
.project-card, .kanban-card {
  border: 1px solid var(--rh-border); border-radius: var(--radius-lg); padding: 15px;
  cursor: pointer; border-left: 4px solid transparent; transition: all 0.2s ease; position: relative;
}
.project-card:hover, .kanban-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}
.project-card.is-planned, .kanban-card.is-planned {
  opacity: 0.75;
  border-style: dashed;
}
.project-card { margin-bottom: 12px; }
.kanban-card { background: #fff; white-space: normal; overflow-wrap: break-word; }
.project-card.active, .kanban-card.active { outline: 2px solid var(--brand-primary); border-color: var(--brand-primary); background: #fff8f8; z-index: 10; }

.card-company { font-size: var(--font-sm); font-weight: 700; color: var(--rh-muted); display: flex; align-items: center; gap: 6px; }
.card-title { font-weight: 700; margin-top: 4px; }
.kanban-card .card-title { margin: 5px 0; }
.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.card-meta { display: flex; align-items: center; gap: 8px; }
.card-due { font-size: var(--font-xs); font-weight: 700; color: var(--rh-muted-dark); }
.card-task-count { font-size: var(--font-sm); color: var(--rh-muted-dark); font-weight: 600; }
.kanban-card .card-company, .kanban-card .card-due { font-size: var(--font-xs); }

/* ============================================================
   10. DETAIL PANEL (RIGHT)
   ============================================================ */
#details-view { padding: 40px; overflow-y: auto; border-left: 1px solid var(--rh-border); display: flex; flex-direction: column; gap: 20px; }
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; }
.detail-header h1 { margin: 0; font-size: 1.25rem; }
#det-company { color: var(--rh-muted-dark); font-weight: 600; margin: 5px 0 0 0; }
#det-created-at { font-size: 0.7rem; font-weight: 600; color: var(--rh-muted); margin: 6px 0 30px 0; letter-spacing: 0.5px; text-transform: uppercase; }
.detail-actions { display: flex; gap: 10px; }
#empty-state { text-align: center; padding-top: 100px; color: var(--rh-muted-dark); }
.empty-tasks { padding: 40px 20px; text-align: center; color: var(--rh-muted-dark); font-size: var(--font-body); background: #f8fafc; border: 2px dashed #cbd5e1; border-radius: var(--radius-lg); display: flex; flex-direction: column; align-items: center; gap: 15px; }

/* ============================================================
   11. TASK ITEMS & STATUS PILLS
   ============================================================ */
.task-item {
  background: white; padding: 15px; border-radius: var(--radius-md); border: 1px solid var(--rh-border);
  margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; cursor: grab; transition: 0.2s;
}
.task-item.is-planned {
  opacity: 0.8;
  border-style: dashed;
}
.task-info { flex: 1; }
.task-name { font-weight: 600; }
.task-assignee { font-size: var(--font-base); color: var(--rh-muted-dark); }
.task-controls { display: flex; gap: 10px; align-items: center; }
.task-date-input { background: white; border: 1px solid #ddd; text-transform: none; width: 110px; }

.status-pill {
  font-size: var(--font-xs); font-weight: 700; border: 1px solid #e2e8f0; padding: 0 10px;
  border-radius: 20px; cursor: pointer; height: 24px; display: inline-flex; align-items: center;
  justify-content: center; outline: none; text-transform: uppercase;
}
.status-Planned      { background: #f8fafc; color: #64748b; border-color: #cbd5e1; }
.status-In-Progress   { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.status-On-Hold       { background: #fefce8; color: #854d0e; border-color: #fef08a; }
.status-Blocked       { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.status-Completed     { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }

.tag-pill {
  background: #e2e8f0; color: #475569; padding: 2px 6px; border-radius: var(--radius-sm);
  font-size: var(--font-xs); font-weight: 700; text-transform: uppercase; display: inline-block; vertical-align: middle;
}
/* ============================================================
   12. COMMENTS
 ============================================================ */
/* Communication Feed Styles */
.comment-block { background: #fff; padding: 12px; border-radius: var(--radius-md); border: 1px solid var(--rh-border); display: flex; flex-direction: column; gap: 5px; }
.comment-meta { display: flex; justify-content: space-between; font-size: var(--font-xs); color: var(--rh-muted-dark); font-weight: 700; text-transform: uppercase; }
.comment-author.lateral-team { color: #1a73e8; } 
.comment-text { font-size: var(--font-body); line-height: 1.4; color: var(--rh-text); white-space: pre-wrap; }
.comment-edit-btn { background: none; border: none; color: var(--rh-muted-dark); font-size: 11px; cursor: pointer; text-transform: uppercase; font-weight: 600; padding: 0 4px; opacity: 0.6; transition: opacity 0.2s; }
.comment-edit-btn:hover { opacity: 1; color: var(--brand-primary); }
.comment-edited { font-weight: 400; text-transform: none; font-style: italic; opacity: 0.7; font-size: 10px; }
.comment-edit-textarea { width: 100%; min-height: 60px; padding: 8px; border: 1px solid var(--rh-border); border-radius: var(--radius-sm); font-size: var(--font-body); font-family: inherit; resize: vertical; margin-bottom: 8px; }
.comment-edit-actions { display: flex; gap: 8px; }

/* ============================================================
   13. BUTTONS
   ============================================================ */
.btn-primary { background: var(--brand-primary); color: white; border: none; padding: 10px 20px; border-radius: var(--radius-sm); font-weight: 700; cursor: pointer; font-size: var(--font-body); }
.btn-ghost { background: transparent; color: var(--rh-muted-light); border: 1px solid #ddd; padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: var(--font-body); }
.btn-toggle { background: #eee; color: var(--rh-muted-light); border: none; padding: 8px 15px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 700; font-size: var(--font-md); }
.btn-toggle.active { background: var(--brand-primary); color: #fff; }
.btn-delete { background: transparent; color: #ccc; border: none; cursor: pointer; font-size: 1.1rem; padding: 5px; }
.btn-delete:hover { color: var(--brand-primary); }
.btn-danger { color: var(--brand-primary); border-color: var(--brand-primary); }

.btn-drive {
  display: inline-flex; align-items: center; gap: 8px; background: #fff; color: #3c4043;
  border: 1px solid var(--rh-border); padding: 6px 12px; border-radius: var(--radius-md);
  font-size: var(--font-base); font-weight: 600; text-decoration: none; transition: background 0.2s; cursor: pointer; margin-top: 10px;
}
.btn-drive:hover { background: #f1f3f4; }
.btn-drive svg { width: 16px; height: 16px; }

/* ============================================================
   14. NOTES AREA & MODALS
   ============================================================ */
.notes-area { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; padding-top: 20px; border-top: 1px solid #eee; }
.notes-area label { font-size: var(--font-md); font-weight: 700; text-transform: uppercase; color: var(--rh-muted); }
.notes-header { display: flex; justify-content: space-between; align-items: center; }
textarea#det-notes { width: 100%; min-height: 200px; resize: none; overflow-y: hidden; background: #fff; border: 1px solid var(--rh-border); border-radius: var(--radius-md); padding: 15px; font-size: var(--font-input); line-height: 1.5; }
#notes-status { font-size: var(--font-xs); color: var(--rh-muted); font-weight: 700; transition: opacity 0.5s ease-in-out; }

#modal, #task-modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: none; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: white; padding: 30px; border-radius: var(--radius-lg); width: 400px; display: flex; flex-direction: column; gap: 15px; }
.modal-init-row { display: flex; gap: 10px; margin-top: 10px; }
.modal-init-row > * { flex: 1; }

.hidden { display: none !important; }
.kanban-status-select { font-size: 0.55rem; padding: 2px 6px; }
.unread-badge {
    position: absolute; top: -5px; right: -5px; width: 12px; height: 12px;
    background: #ef4444; border-radius: 50%; border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* ============================================================
   15. SMART TAGGING
   ============================================================ */
.autocomplete-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    width: 250px;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border: 1px solid var(--rh-border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    margin: 0 0 5px 0;
    padding: 0;
    list-style: none;
}
.autocomplete-dropdown li {
    padding: 8px 12px;
    font-size: var(--font-sm);
    color: var(--rh-text);
    cursor: pointer;
    border-bottom: 1px solid #f1f3f4;
}
.autocomplete-dropdown li:last-child {
    border-bottom: none;
}
.autocomplete-dropdown li:hover,
.autocomplete-dropdown li.active {
    background: #f8fafc;
    color: var(--rh-blue);
    font-weight: 600;
}
.tagged-user {
    color: var(--rh-blue);
    font-weight: 600;
    background: #eff6ff;
    padding: 0 4px;
    border-radius: 4px;
}
/* --- AGREEMENTS MODULE --- */
#module-agreements {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  overflow: hidden;
}

/* Health Strip */
.agreements-health-strip {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background-color: #fff;
  border-bottom: 1px solid var(--rh-border);
}

.health-pill {
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  transition: all 0.15s;
  user-select: none;
}
.health-pill:hover { filter: brightness(0.96); }
.health-pill.active-filter {
  box-shadow: 0 0 0 2px var(--brand-primary);
  border-color: var(--brand-primary);
}

/* CSS dot inside health pill */
.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.health-green { background-color: #dcfce7; color: #166534; }
.health-green .health-dot { background: #16a34a; }
.health-yellow { background-color: #fef9c3; color: #854d0e; }
.health-yellow .health-dot { background: #ca8a04; }
.health-red { background-color: #fee2e2; color: #991b1b; }
.health-red .health-dot { background: #dc2626; }
.health-gray { background-color: #f3f4f6; color: #374151; }
.health-gray .health-dot { background: #9ca3af; }


/* Main table area */
.agreements-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 20px;
  background-color: #f9fafb;
}

.agreements-table-container {
  flex: none;
  background: white;
  border: 1px solid var(--rh-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: visible;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.agreements-table-header {
  display: flex;
  padding: 10px 16px;
  background-color: #f8f9fa;
  border-bottom: 1px solid var(--rh-border);
  font-weight: 700;
  font-size: 0.7rem;
  color: var(--rh-muted-dark);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 5;
  border-radius: 8px 8px 0 0;
}

#agreements-table-body {
  flex: 1;
  overflow-y: auto;
}

/* Shipper Group Header */
.shipper-group-header {
  display: flex;
  align-items: center;
  padding: 9px 16px;
  background-color: #f9fafb;
  border-bottom: 1px solid var(--rh-border);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  user-select: none;
}
.shipper-group-header:hover { background-color: #f3f4f6; }

.shipper-group-stats {
  margin-left: 10px;
  font-size: 0.775rem;
  color: var(--rh-muted);
  font-weight: 400;
}

/* Agreement Row */
.agreement-row {
  display: flex;
  padding: 11px 16px;
  border-bottom: 1px solid #f3f4f6;
  align-items: center;
  font-size: 0.84rem;
  transition: background-color 0.1s;
  position: relative;
}
.agreement-row:hover { background-color: #fafafa; }
.agreement-row.expanded {
  background-color: #f0f9ff;
  border-bottom: none;
}

/* Expand chevron cell */
.agr-cell-chevron {
  width: 30px;
  flex-shrink: 0;
  color: var(--rh-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}
.agr-cell-chevron:hover { color: var(--brand-primary); }
.agreement-row.expanded .agr-cell-chevron svg { transform: rotate(90deg); }

/* Health indicator dot in table rows */
.health-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Type Pills */
.type-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
}
.type-csp { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.type-blanket { background: #f3e8ff; color: #6b21a8; border: 1px solid #e9d5ff; }
.type-spot { background: #ffedd5; color: #c2410c; border: 1px solid #fed7aa; }

/* Drive Chip */
.drive-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font-size: 0.7rem;
  color: #374151;
  text-decoration: none;
  transition: all 0.15s;
}
.drive-chip:hover {
  background: #f9fafb;
  border-color: #d1d5db;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.drive-chip svg { width: 12px; height: 12px; }

.drive-chip.missing {
  color: var(--brand-primary);
  border-style: dashed;
  border-color: #c7d2fe;
  background: #f8faff;
  cursor: pointer;
  opacity: 0.9;
}
.drive-chip.missing:hover {
  opacity: 1;
  background: #eef2ff;
  border-color: var(--brand-primary);
}

/* Row Actions (hover reveal) */
.row-actions {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(90deg, transparent 0%, #fafafa 20%, #fafafa 100%);
  padding-left: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.agreement-row:hover .row-actions {
  opacity: 1;
  pointer-events: auto;
}

.action-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.15s;
  background: white;
  border: 1px solid #e5e7eb;
  padding: 0;
  flex-shrink: 0;
}
.action-icon:hover {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
  background: #f8faff;
}
.action-icon.danger:hover {
  color: #ef4444;
  border-color: #fca5a5;
  background: #fef2f2;
}

/* Expanded Detail Card */
.agreement-detail-card {
  background-color: #f8fbff;
  border-bottom: 1px solid #e0f2fe;
  padding: 14px 20px 18px 46px;
  font-size: 0.84rem;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.detail-section-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #0369a1;
  margin-bottom: 8px;
}
.detail-notes-box {
  background: white;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  padding: 10px;
  min-height: 52px;
  color: #334155;
  white-space: pre-wrap;
  font-size: 0.84rem;
  line-height: 1.5;
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
.detail-notes-box:focus {
  border-color: #0284c7;
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}
.detail-dates {
  display: flex;
  gap: 20px;
  color: #475569;
  line-height: 1.6;
}

/* Agreement Modal */
.agr-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex !important;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

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

.agr-modal-panel {
  background: white;
  border-radius: 10px;
  padding: 28px;
  width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

/* ============================================================
   BILLING MODULE
   ============================================================ */
#module-billing {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  overflow: hidden;
}

/* Billing Summary Strip (mirrors .agreements-health-strip) */
.billing-summary-strip {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background-color: #fff;
  border-bottom: 1px solid var(--rh-border);
  flex-wrap: wrap;
}

.billing-stat-pill {
  padding: 5px 14px;
  border-radius: 16px;
  font-size: 0.78rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.billing-stat-pill .billing-stat-value { font-weight: 700; }

.billing-stat-retainers { background-color: #dbeafe; color: #1e40af; }
.billing-stat-rfps { background-color: #f3e8ff; color: #6b21a8; }
.billing-stat-analyses { background-color: #dcfce7; color: #166534; }
.billing-stat-routing { background-color: #fef3c7; color: #92400e; }
.billing-stat-grand {
  background-color: #111827;
  color: #fff;
  padding: 6px 18px;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
/* Active filter ring on clickable billing pills */
.billing-stat-pill.active-filter {
  box-shadow: 0 0 0 2px var(--brand-primary);
  border-color: var(--brand-primary);
}
.billing-stat-pill:not(.billing-stat-grand):hover {
  filter: brightness(0.95);
}

/* Billing Filter Bar */
.billing-filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid var(--rh-border);
  flex-shrink: 0;
}

.billing-month-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}
.billing-month-btn {
  background: none;
  border: 1px solid var(--rh-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--rh-muted-dark);
  transition: all 0.15s;
}
.billing-month-btn:hover { background: var(--rh-gray); color: var(--brand-primary); }
.billing-month-btn.active {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
}

.billing-filter-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Billing Main Content */
.billing-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px 40px 20px;
  background-color: #f9fafb;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Invoice Card (mirrors .agreements-table-container) */
.billing-card {
  background: white;
  border: 1px solid var(--rh-border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  flex-shrink: 0;
}

.billing-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: #f8f9fa;
  border-bottom: 1px solid var(--rh-border);
}
.billing-card-company {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.billing-card-period {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--rh-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.billing-card-body {
  padding: 0;
}

/* Line Item Rows */
.billing-line-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  font-size: 0.84rem;
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.1s;
}
.billing-line-item:last-child { border-bottom: none; }
.billing-line-item:hover { background-color: #fafafa; }

.billing-line-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #334155;
}
.billing-line-amount {
  font-weight: 600;
  color: #1e293b;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.billing-line-item.is-recurring {
  background-color: #fafbff;
}

.billing-line-separator {
  border: none;
  border-top: 1px dashed #e2e8f0;
  margin: 0 16px;
}

/* Warning state for missing RFP tier */
.billing-line-item.needs-tier {
  background-color: #fffbeb;
}
.billing-line-item.needs-tier .billing-line-amount {
  color: #d97706;
}
.billing-tier-btn {
  background: none;
  border: 1px dashed #f59e0b;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #d97706;
  cursor: pointer;
  transition: all 0.15s;
}
.billing-tier-btn:hover {
  background: #fef3c7;
  border-style: solid;
}

/* Total Row */
.billing-card-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: #f8f9fa;
  border-top: 1px solid var(--rh-border);
}
.billing-total-label {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand-primary);
}
.billing-total-amount {
  font-weight: 700;
  font-size: 1rem;
  color: var(--brand-primary);
  font-variant-numeric: tabular-nums;
}
.billing-edit-rates-btn {
  background: none;
  border: none;
  color: var(--rh-muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.billing-edit-rates-btn:hover {
  color: var(--brand-primary);
  background: var(--rh-gray);
}

/* Type Pills (project_type indicators) */
.type-pill-rfp {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.65rem;
  font-weight: 700;
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.type-pill-analysis {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.65rem;
  font-weight: 700;
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Billing tier pill in line items */
.billing-tier-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--rh-muted);
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 8px;
}

/* Empty billing state */
.billing-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--rh-muted-dark);
  font-size: var(--font-body);
}
.billing-empty svg { margin-bottom: 12px; color: #cbd5e1; }

/* Show all toggle */
.billing-show-all-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--rh-muted-dark);
  cursor: pointer;
  margin: 0;
}
.billing-show-all-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
}

/* RFP tier selector (reuses tag-select-pill) */
.tag-select-pill.active[data-tier="small"] {
  background: #dbeafe; color: #1e40af; border-color: #bfdbfe;
}
.tag-select-pill.active[data-tier="medium"] {
  background: #e0e7ff; color: #3730a3; border-color: #c7d2fe;
}
.tag-select-pill.active[data-tier="large"] {
  background: #f3e8ff; color: #6b21a8; border-color: #d8b4fe;
}

/* Billing config modal form layout */
.billing-config-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rh-border);
}
.billing-config-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
.billing-config-section-title {
  font-size: var(--font-sm);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--rh-muted);
  margin-bottom: 10px;
}
.billing-config-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.billing-config-row label {
  flex: 1;
  font-size: 0.84rem;
  color: #334155;
  font-weight: 500;
}
.billing-config-row input[type="number"] {
  width: 120px;
  text-align: right;
}

/* Tier quick-select dropdown on billing cards */
.billing-tier-dropdown {
  position: absolute;
  background: white;
  border: 1px solid var(--rh-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  padding: 4px;
  z-index: 100;
}
.billing-tier-option {
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
  white-space: nowrap;
}
.billing-tier-option:hover { background: var(--rh-gray); }

