* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a3a5c;
  --primary-light: #2d5f8a;
  --accent: #e8a838;
  --danger: #c0392b;
  --bg: #f5f7fa;
  --card-bg: #fff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dfe6e9;
  --radius: 6px;
  --sidebar-width: 260px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* App Layout */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: #12253a;
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-header {
  padding: 0.6rem 1rem 0.25rem;
  text-align: center;
}
.sidebar-logo {
  height: 48px;
  width: auto;
  display: inline-block;
}
.sidebar-actions {
  padding: 0.4rem 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Collapsible new project */
.sidebar-collapse-toggle {
  width: 100%;
  padding: 0.3rem 0;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.35);
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.sidebar-collapse-toggle:hover { color: rgba(255,255,255,0.7); background: rgba(255,255,255,0.03); }
.sidebar-collapse-arrow {
  display: inline-block;
  transition: transform 0.25s ease;
  font-size: 0.7rem;
}
.sidebar-collapse-toggle.open .sidebar-collapse-arrow { transform: rotate(180deg); }
.sidebar-collapsible {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 0.75rem;
}
.sidebar-collapsible.expanded {
  max-height: 50px;
  padding: 0.25rem 0.75rem 0.4rem;
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

/* Module tabs */
.module-tabs {
  display: flex;
  padding: 0.5rem 0.65rem 0;
  gap: 0.3rem;
}
.module-tab {
  flex: 1;
  padding: 0.42rem 0.4rem 0.38rem;
  text-align: center;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 600;
  transition: all 0.15s;
  background: rgba(255,255,255,0.03);
  color: rgba(255,255,255,0.4);
  border: none;
  border-bottom: 2px solid transparent;
}
.module-tab:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.7); }
.module-tab.active { background: rgba(255,255,255,0.07); color: #fff; border-bottom-color: var(--accent); }
.module-tab-icon { display: none; }
.module-tab-count { font-size: 0.57rem; opacity: 0.45; display: block; margin-top: 0.05rem; font-weight: 400; }

/* Sidebar search */
.sidebar-search {
  margin: 0.4rem 0.65rem;
  padding: 0.32rem 0.5rem;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 4px;
  background: rgba(255,255,255,0.02);
  color: #fff;
  font-size: 0.74rem;
  width: calc(100% - 1.3rem);
  outline: none;
}
.sidebar-search::placeholder { color: rgba(255,255,255,0.2); }
.sidebar-search:focus { border-color: rgba(255,255,255,0.15); background: rgba(255,255,255,0.04); }

/* Project items */
.nav-project {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.55);
  text-align: left;
  cursor: pointer;
  font-size: 0.78rem;
  border-left: 3px solid transparent;
  transition: all 0.12s;
  gap: 0.4rem;
}
.nav-project:hover {
  background: rgba(255,255,255,0.03);
  color: rgba(255,255,255,0.9);
}
.nav-project.active {
  background: rgba(255,255,255,0.05);
  color: #fff;
  border-left-color: var(--accent);
}
.nav-project .nav-project-name {
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-project-status {
  font-size: 0.6rem;
  padding: 0.12rem 0.35rem;
  border-radius: 3px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0.2px;
}
.nav-status-live { background: rgba(34,197,94,0.18); color: #86efac; }
.nav-status-proposal { background: rgba(168,85,247,0.18); color: #d8b4fe; }
.nav-status-deploy { background: rgba(59,130,246,0.18); color: #93c5fd; }
.nav-status-created { background: rgba(234,179,8,0.18); color: #fde047; }
.nav-status-hidden { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.4); }

/* Hidden toggle */
.sidebar-hidden-toggle {
  padding: 0.5rem 1rem;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  text-align: center;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.sidebar-hidden-toggle:hover { color: rgba(255,255,255,0.6); background: rgba(255,255,255,0.03); }

/* Main Content */
.app-main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Views */
.view { display: none; }
.view.active { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
#view-empty.active { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
#view-project-form.active { display: block; overflow-y: auto; padding: 2rem; }

/* Project Header (sticky top) */
.project-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem 0.5rem;
  flex-shrink: 0;
}
.project-header h1 { font-size: 1.5rem; }
.project-header-actions { display: flex; gap: 0.5rem; }

/* Tabs (sticky below header) */
.project-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  padding: 0 2rem;
  flex-shrink: 0;
}
.tab-btn {
  padding: 0.6rem 1.5rem;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Tab content (scrollable body) */
.tab-content { flex: 1; overflow: hidden; position: relative; }
.tab-panel { display: none; height: 100%; overflow-y: auto; padding: 1.5rem 2rem; }
.tab-panel.active { display: block; }

.tab-panel-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}
.tab-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.proposal-type-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.proposal-type-label select {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: opacity 0.2s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }

/* Document Preview */
.document-preview {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  max-width: 8.7in;
  overflow: visible;
}

/* Forms */
.view-header { margin-bottom: 1.5rem; }
.view-header h1 { font-size: 1.5rem; }

.form-grid fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--card-bg);
}
.form-grid legend { font-weight: 600; padding: 0 0.5rem; }
.form-row {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.form-row label {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-light);
}
.form-row input, .form-row select, .form-row textarea {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text);
}
.form-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-light);
  font-size: 1rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal.hidden { display: none; }
.modal-content {
  background: #fff;
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-content h2 { margin-bottom: 0.5rem; }
.modal-content p { color: var(--text-light); margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }

.import-preview { margin-top: 1rem; }
.import-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.import-preview th, .import-preview td {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  text-align: left;
}
.import-preview th { background: var(--bg); font-weight: 600; }
.import-row { cursor: pointer; }
.import-row:hover { background: #f0f4ff; }
.import-row.selected { background: #dbeafe; }

/* Print/PDF styles */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  body { background: #fff; }
  .sidebar, .project-header, .project-tabs, .tab-panel-header, #sync-status { display: none !important; }
  .app-layout { display: block; height: auto; overflow: visible !important; }
  .app-main { padding: 0; overflow: visible !important; display: block; height: auto; }
  .view { display: none !important; }
  .view.active { display: block !important; overflow: visible !important; height: auto !important; }
  .tab-content { overflow: visible !important; height: auto !important; position: static !important; }
  .tab-panel { display: none !important; height: auto !important; overflow: visible !important; padding: 0 !important; }
  .tab-panel.active { display: block !important; }
  .document-preview { border: none !important; box-shadow: none !important; max-width: none !important; overflow: visible !important; }
}

/* Overview Tab */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.overview-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.overview-card h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.overview-card-wide {
  grid-column: 1 / -1;
}
.overview-dl {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.4rem 0.75rem;
  font-size: 0.85rem;
}
.overview-dl dt {
  font-weight: 600;
  color: var(--text-light);
}
.overview-dl dd {
  color: var(--text);
}
.overview-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
}
.overview-badge.badge-as2 { background: #dbeafe; color: #1e40af; }
.overview-badge.badge-pd { background: #dcfce7; color: #166534; }
.overview-status {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #f3e8ff;
  color: #7c3aed;
}
.overview-money {
  font-weight: 600;
  font-family: 'SF Mono', 'Consolas', monospace;
}
.overview-total {
  font-size: 1rem;
  color: var(--primary);
}
.overview-briefing {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
}

/* Proposal Versioning */
.btn-purple { background: #7c3aed; color: #fff; }

.versions-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.versions-panel.hidden { display: none; }

.version-row {
  display: flex;
  align-items: center;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  gap: 0.75rem;
  font-size: 0.85rem;
}
.version-row:last-child { border-bottom: none; }
.version-row.version-active { background: #f0f4ff; }
.version-name { font-weight: 600; flex: 1; }
.version-date { color: var(--text-light); font-size: 0.8rem; min-width: 90px; }
.version-actions { display: flex; gap: 0.4rem; }
.version-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 0.4rem;
}
.version-badge-initial { background: #dcfce7; color: #166534; }
.version-badge-revised { background: #f3e8ff; color: #7c3aed; }
.version-badge-latest { background: #dbeafe; color: #1e40af; }

/* Proposal locked state */
.proposal-locked-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
}
.proposal-locked-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e2e8f0;
  color: #475569;
}
.proposal-locked-hint {
  font-size: 0.8rem;
  color: var(--text-light);
}
.proposal-status-info {
  font-size: 0.8rem;
  color: var(--text-light);
}

@media print {
  .versions-panel, .proposal-locked-header, #proposal-panel-header { display: none !important; }
}

/* Invoice Tab - Sub-tabs & Records List */
.inv-subtabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
}
.inv-subtab {
  padding: 0.35rem 0.9rem;
  background: #fff;
  color: #555;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  border: none;
  border-right: 1px solid var(--border);
}
.inv-subtab:last-child { border-right: none; }
.inv-subtab.active { background: var(--primary); color: #fff; }

.inv-summary-text {
  font-size: 0.8rem;
  color: var(--text-light);
}

.inv-records-list {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
  max-height: 280px;
  overflow-y: auto;
}
.inv-records-list.hidden { display: none; }

.inv-list-header {
  display: flex;
  align-items: center;
  padding: 0.45rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  gap: 0.75rem;
  position: sticky;
  top: 0;
}
.inv-list-row {
  display: flex;
  align-items: center;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.85rem;
  gap: 0.75rem;
  cursor: default;
}
.inv-list-row:last-child { border-bottom: none; }
.inv-list-row:hover { background: #f8fafc; }

.col-inv { min-width: 75px; font-weight: 600; }
.col-desc { flex: 1; }
.col-amount { min-width: 85px; text-align: right; font-weight: 600; font-family: 'SF Mono', Consolas, monospace; font-size: 0.8rem; }
.col-due { min-width: 90px; color: var(--text-light); font-size: 0.8rem; }
.col-status { min-width: 110px; }
.col-actions { min-width: 130px; display: flex; gap: 0.3rem; justify-content: flex-end; }

.status-badge { display: inline-flex; align-items: center; gap: 0.2rem; padding: 0.15rem 0.45rem; border-radius: 4px; font-size: 0.7rem; font-weight: 600; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-invoiced { background: #dbeafe; color: #1e40af; }
.status-paid { background: #dcfce7; color: #166534; }

/* Paid overlay */
.invoice-doc.is-paid { position: relative; }
.invoice-doc.is-paid > *:not(.paid-overlay) { opacity: 0.55; }
.paid-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-25deg);
  font-size: 5.5rem;
  font-weight: 900;
  color: rgba(22, 163, 74, 0.14);
  text-transform: uppercase;
  letter-spacing: 0.3rem;
  pointer-events: none;
  z-index: 10;
  border: 8px solid rgba(22, 163, 74, 0.14);
  padding: 0.4rem 2rem;
  border-radius: 14px;
}

@media print {
  .inv-records-list, .inv-subtabs, .inv-summary-text, #invoice-panel-header { display: none !important; }
  .invoice-doc.is-paid > *:not(.paid-overlay) { opacity: 0.55 !important; }
  .paid-overlay {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* API Fetch Modal - Redesigned */
.modal-api-wide {
  max-width: 900px !important;
  width: 95% !important;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  overflow: hidden;
}
.modal-api-header {
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-api-header h2 { margin-bottom: 0.25rem; }
.modal-api-header p { font-size: 0.8rem; color: var(--text-light); margin: 0; }

.modal-api-toolbar {
  padding: 0.6rem 1.5rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  background: var(--bg);
  flex-wrap: wrap;
}
.api-search-input {
  width: 260px;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.82rem;
  outline: none;
}
.api-search-input:focus { border-color: var(--primary); }
.api-search-input::placeholder { color: #b0b8c4; }
.api-toolbar-filters {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.api-filter-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: #555;
  cursor: pointer;
  font-weight: 500;
}
.api-cat-toggles {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
}
.api-cat-btn {
  padding: 0.28rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  border: none;
  background: #fff;
  color: #7f8c8d;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.api-cat-btn:last-child { border-right: none; }
.api-cat-btn.active { background: var(--primary); color: #fff; }
.api-cat-btn[data-cat="AS2"].active { background: #1e40af; color: #fff; }
.api-cat-btn[data-cat="PD"].active { background: #166534; color: #fff; }
.api-toolbar-count {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-left: auto;
}

.modal-api-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  min-height: 200px;
}
.modal-api-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.modal-api-body thead {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 5;
}
.modal-api-body th {
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
}
.modal-api-body td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.modal-api-body tr:hover td { background: #f8fafc; }
.modal-api-body .api-cat-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
}
.modal-api-body .cat-as2 { background: #dbeafe; color: #1e40af; }
.modal-api-body .cat-pd { background: #dcfce7; color: #166534; }
.modal-api-body .api-status-tag {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
  background: #f3e8ff;
  color: #7c3aed;
}
.modal-api-body .api-imported-tag {
  font-size: 0.65rem;
  background: #e2e8f0;
  color: #475569;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-weight: 600;
  margin-left: 0.3rem;
}

.modal-api-footer {
  padding: 0.7rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: #fff;
}
.modal-api-footer-left {
  font-size: 0.8rem;
  color: #555;
  font-weight: 500;
}
.modal-api-footer-right {
  display: flex;
  gap: 0.5rem;
}

/* Invoice list - line items summary */
.line-items-summary {
  font-size: 0.75rem;
  color: #555;
  line-height: 1.4;
}
.line-items-summary span {
  display: block;
}

/* Overview Pricing Pills */
.overview-pills-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.overview-pills-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.overview-pill {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.5rem;
  text-align: center;
}
.overview-pill-full { grid-column: 1 / -1; }
.overview-pill-sm { padding: 0.4rem 0.4rem; }
.overview-pill-label {
  font-size: 0.6rem;
  color: var(--text-light);
  text-transform: uppercase;
  font-weight: 600;
  display: block;
  margin-bottom: 0.15rem;
}
.overview-pill-value {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--primary);
  font-family: 'SF Mono', Consolas, monospace;
}
.overview-pill-value-lg { font-size: 0.9rem; }
.overview-pill-red { color: #c0392b; }
.overview-pill-green { color: #27ae60; }

/* Past Due badge */
.overview-past-due {
  display: inline-block;
  font-size: 0.55rem;
  background: #c0392b;
  color: #fff;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-left: 0.3rem;
  vertical-align: middle;
}

/* Sync All status */
.sidebar-sync-status {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.6);
  text-align: center;
  padding: 0.2rem 0;
}

/* Per-project last synced */
.project-last-synced {
  font-size: 0.72rem;
  color: var(--text-light);
  margin-right: 0.5rem;
}

/* Dashboard */
.dashboard-container {
  padding: 1.5rem 2rem;
  overflow-y: auto;
  height: 100%;
}
.dashboard-header { margin-bottom: 1.25rem; }
.dashboard-header h1 { font-size: 1.4rem; margin-bottom: 0.2rem; }
.dashboard-header p { font-size: 0.82rem; color: var(--text-light); }

.dash-stats {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.dash-stat {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.75rem;
  text-align: center;
}
.dash-stat-value { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.dash-stat-value-red { color: #c0392b; }
.dash-stat-value-yellow { color: #92400e; }
.dash-stat-label { font-size: 0.62rem; color: var(--text-light); text-transform: uppercase; font-weight: 600; margin-top: 0.15rem; }

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.dash-grid-full { grid-column: 1 / -1; }

.dash-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.dash-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid #f1f5f9;
}
.dash-card-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.dash-count {
  font-size: 0.62rem;
  background: #e2e8f0;
  color: #475569;
  padding: 0.12rem 0.4rem;
  border-radius: 10px;
  font-weight: 700;
}
.dash-count-red { background: #fee2e2; color: #b91c1c; }
.dash-count-yellow { background: #fef3c7; color: #92400e; }
.dash-count-purple { background: #f3e8ff; color: #7c3aed; }

.dash-card-empty { padding: 1.25rem; text-align: center; color: var(--text-light); font-size: 0.82rem; }

.action-row {
  display: flex;
  align-items: center;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid #f8fafc;
  gap: 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.1s;
}
.action-row:last-child { border-bottom: none; }
.action-row:hover { background: #f8fafc; }
.action-row-icon {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.icon-red { background: #fee2e2; }
.icon-yellow { background: #fef3c7; }
.icon-blue { background: #dbeafe; }
.icon-purple { background: #f3e8ff; }
.action-row-content { flex: 1; min-width: 0; }
.action-row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.8rem; }
.action-row-sub { font-size: 0.7rem; color: var(--text-light); margin-top: 0.05rem; }
.action-row-meta { text-align: right; flex-shrink: 0; }
.action-row-amount { font-weight: 600; font-family: 'SF Mono', Consolas, monospace; font-size: 0.78rem; }
.action-row-days { font-size: 0.65rem; color: var(--text-light); margin-top: 0.05rem; }

/* Notes */
.note-item {
  padding: 0.55rem 1rem;
  border-bottom: 1px solid #f8fafc;
  font-size: 0.82rem;
}
.note-item:last-child { border-bottom: none; }
.note-item-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.2rem; }
.note-item-project { font-weight: 600; font-size: 0.78rem; }
.note-item-date { font-size: 0.65rem; color: var(--text-light); }
.note-item-text { font-size: 0.78rem; color: #555; line-height: 1.5; }
.note-tag {
  display: inline-block;
  font-size: 0.58rem;
  padding: 0.08rem 0.3rem;
  border-radius: 3px;
  font-weight: 600;
  margin-right: 0.25rem;
  vertical-align: middle;
}
.note-tag-invoice { background: #dbeafe; color: #1e40af; }
.note-tag-renewal { background: #fef3c7; color: #92400e; }
.note-tag-proposal { background: #f3e8ff; color: #7c3aed; }
.note-tag-general { background: #e2e8f0; color: #475569; }

.dash-add-note {
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.4rem;
}
.dash-add-note select {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
  max-width: none;
}
.dash-add-note input {
  flex: 1;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.78rem;
  outline: none;
}
.dash-add-note button {
  padding: 0.3rem 0.6rem;
  border: none;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}

/* Note actions */
.note-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.note-item-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.note-action-btn {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.note-item:hover .note-action-btn { opacity: 1; }
.note-resolve-btn { background: #dcfce7; color: #166534; }
.note-resolve-btn:hover { background: #bbf7d0; }
.note-archive-btn { background: #fee2e2; color: #b91c1c; }
.note-archive-btn:hover { background: #fecaca; }
.note-reopen-btn, .note-restore-btn { background: #dbeafe; color: #1e40af; }
.note-reopen-btn:hover, .note-restore-btn:hover { background: #bfdbfe; }

/* Resolved/Archived notes */
.note-item-resolved .note-item-text { text-decoration: line-through; opacity: 0.6; }
.note-item-archived { opacity: 0.5; }

.note-section-toggle {
  padding: 0.4rem 1rem;
  font-size: 0.72rem;
  color: var(--text-light);
  cursor: pointer;
  border-top: 1px solid #f1f5f9;
  font-weight: 500;
}
.note-section-toggle:hover { color: var(--text); background: #f8fafc; }

/* Dashboard top row */
.dash-top-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* Dashboard invoice filter tabs */
.dash-filter-tabs { display: flex; gap: 0; }
.dash-filter-tab { padding: 0.28rem 0.6rem; font-size: 0.66rem; font-weight: 600; border: 1px solid var(--border); background: #fff; color: var(--text-light); cursor: pointer; }
.dash-filter-tab:first-child { border-radius: 4px 0 0 4px; }
.dash-filter-tab:last-child { border-radius: 0 4px 4px 0; }
.dash-filter-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.dash-filter-tab-red.active { background: #c0392b; border-color: #c0392b; }

.dash-invoices-card { margin-bottom: 1rem; }
.dash-notes-card { }

.dash-total-row { display: flex; justify-content: flex-end; padding: 0.45rem 1rem; border-top: 1px solid var(--border); background: var(--bg); font-size: 0.75rem; gap: 0.4rem; }
.dash-total-label { color: var(--text-light); font-weight: 600; }
.dash-total-value { font-weight: 700; color: var(--primary); font-family: 'SF Mono', Consolas, monospace; }

.dash-badge-overdue { font-size: 0.52rem; background: #c0392b; color: #fff; padding: 0.08rem 0.22rem; border-radius: 3px; font-weight: 700; text-transform: uppercase; margin-left: 0.2rem; }
.action-row-amount-red { color: #c0392b; }

/* Sidebar action buttons */
.sidebar-actions .btn { font-size: 0.76rem; padding: 0.45rem 0.5rem; }
.sidebar-collapsible .btn { font-size: 0.76rem; padding: 0.45rem 0.5rem; }

/* Sidebar-specific button styles */
.sidebar .btn-primary { background: rgba(45,95,138,0.5); color: rgba(255,255,255,0.9); border: 1px solid rgba(45,95,138,0.6); }
.sidebar .btn-primary:hover { background: rgba(45,95,138,0.7); }
.sidebar .btn-secondary { background: rgba(255,255,255,0.04); color: rgba(255,255,255,0.7); border: 1px solid rgba(255,255,255,0.08); }
.sidebar .btn-secondary:hover { background: rgba(255,255,255,0.07); border-color: rgba(255,255,255,0.15); color: rgba(255,255,255,0.9); }

/* AI Gradient Sync Button */
@property --sync-turn {
  syntax: "<number>";
  initial-value: 0;
  inherits: false;
}
@keyframes sync-spin {
  to { --sync-turn: 1; }
}
@keyframes sync-roll {
  0% { transform: translateY(0); }
  12% { transform: translateY(0); }
  16% { transform: translateY(-16px); }
  28% { transform: translateY(-16px); }
  32% { transform: translateY(-32px); }
  44% { transform: translateY(-32px); }
  48% { transform: translateY(-48px); }
  60% { transform: translateY(-48px); }
  64% { transform: translateY(-64px); }
  76% { transform: translateY(-64px); }
  80% { transform: translateY(-80px); }
  92% { transform: translateY(-80px); }
  96% { transform: translateY(-96px); }
  100% { transform: translateY(-96px); }
}

.ai-sync-border {
  position: relative;
  padding: 1px;
  border-radius: 5px;
  cursor: pointer;
  width: 100%;
  background: linear-gradient(135deg, rgba(56,189,248,0.2), rgba(192,132,252,0.2), rgba(45,212,191,0.2));
}
.ai-sync-border::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: conic-gradient(
    from calc(var(--sync-turn) * 1turn),
    transparent 0%, #f472b600 5%, #f472b6 10%, #c084fc 18%,
    #818cf8 26%, #38bdf8 34%, #2dd4bf 42%, #fbbf24 46%,
    #fbbf2400 52%, transparent 56%
  );
  opacity: 0;
  transition: opacity 0.4s;
  animation: sync-spin 3s linear infinite;
}
.ai-sync-border.syncing::before { opacity: 1; }

.ai-sync-inner {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  background: #12253a;
}
.ai-sync-border.syncing .ai-sync-inner { background: rgba(18, 37, 58, 0.92); }

.ai-sync-content {
  position: relative;
  z-index: 2;
  padding: 0.55rem 0.6rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  overflow: hidden;
}
.ai-sync-label {
  font-size: 0.76rem;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  transition: transform 0.3s ease, font-size 0.3s ease;
}
.ai-sync-border.syncing .ai-sync-label {
  transform: translateY(-2px);
  font-size: 0.72rem;
}

.ai-sync-roll {
  height: 0;
  overflow: hidden;
  transition: height 0.3s ease;
  width: 100%;
}
.ai-sync-border.syncing .ai-sync-roll { height: 16px; }

.ai-sync-track {
  display: flex;
  flex-direction: column;
}
.ai-sync-border.syncing .ai-sync-track { animation: sync-roll 8s linear infinite; }

.ai-sync-item {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.45);
  text-align: center;
  height: 16px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Interior glow */
.ai-sync-glow {
  position: absolute;
  inset: 0;
  background: conic-gradient(
    from calc(var(--sync-turn) * 1turn),
    transparent 0%, #f472b600 5%, #f472b6 10%, #c084fc 18%,
    #818cf8 26%, #38bdf8 34%, #2dd4bf 42%, #fbbf24 46%,
    #fbbf2400 52%, transparent 56%
  );
  filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  animation: sync-spin 3s linear infinite;
  transition: opacity 0.4s;
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 50%, transparent 40%, rgba(0,0,0,0.2) 60%, rgba(0,0,0,0.6) 80%, black 100%);
  mask-image: radial-gradient(ellipse 80% 70% at 50% 50%, transparent 40%, rgba(0,0,0,0.2) 60%, rgba(0,0,0,0.6) 80%, black 100%);
}
.ai-sync-border.syncing .ai-sync-glow { opacity: 0.9; }

/* ============================================
   LOGIN OVERLAY & AUTH (backend-migration)
   ============================================ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2a0a3f 0%, #6B10A0 100%);
}
.login-overlay.hidden { display: none; }

.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  text-align: center;
}
.login-logo { height: 48px; width: auto; margin: 0 auto 0.5rem; }
.login-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0;
}
.login-subtitle { font-size: 0.85rem; color: #888; margin: 0 0 0.5rem; }
.login-input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid #dfe6e9;
  border-radius: 6px;
  font-size: 0.95rem;
  box-sizing: border-box;
}
.login-input:focus {
  outline: none;
  border-color: #A023E1;
  box-shadow: 0 0 0 3px rgba(160, 35, 225, 0.15);
}
.login-error {
  background: #fdecea;
  color: #b71c1c;
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
}

/* Sidebar footer with user + logout */
.sidebar-footer {
  margin-top: auto;
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sidebar-user-email {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* User-admin modal (backend-migration) */
.admin-users table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-users th, .admin-users td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid #eee; }
.admin-users th { font-weight: 700; color: #555; }
.admin-users .admin-locked { color: #b71c1c; font-weight: 600; }
.admin-create-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.admin-create-form input[type="email"], .admin-create-form input[type="password"] {
  padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.85rem;
}
.admin-checkbox { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; }
.admin-row-actions { display: flex; gap: 0.35rem; }
.admin-row-actions button {
  font-size: 0.72rem; padding: 0.2rem 0.45rem; border: none; border-radius: 4px; cursor: pointer;
}
.admin-btn-reset { background: #e2e8f0; color: #334155; }
.admin-btn-unlock { background: #fef3c7; color: #92400e; }
.admin-btn-delete { background: #fdecea; color: #b71c1c; }

/* DOit import progress bar (backend-migration) */
.api-import-progress { margin-top: 0.5rem; }
.api-import-progress.hidden { display: none; }
.api-import-bar-track {
  width: 100%;
  height: 6px;
  background: #ece3f5;
  border-radius: 999px;
  overflow: hidden;
}
.api-import-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #A023E1, #6B10A0);
  border-radius: 999px;
  transition: width 0.25s ease;
}
