:root {
  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #666;
  --accent: #2d6a4f;
  --accent-light: #40916c;
  --danger: #d62828;
  --warning: #f77f00;
  --success: #2d6a4f;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 12px;
}

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

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

#app { padding-bottom: 140px; }

/* Login */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: var(--text);
}
.login-box {
  background: white;
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
}
.login-box h1 { font-size: 24px; margin-bottom: 4px; }
.login-sub { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.login-box label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; margin-top: 12px; }
.login-box button { padding: 14px; font-size: 16px; border: none; border-radius: 8px; font-family: inherit; cursor: pointer; }
.login-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* Top bar */
.topbar {
  background: var(--text);
  color: white;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar .date { font-size: 13px; opacity: 0.7; }

.user-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.user-dropdown {
  display: none;
  position: fixed;
  top: 56px;
  right: 12px;
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  z-index: 150;
  min-width: 200px;
  overflow: hidden;
}
.user-dropdown.active { display: block; }
.user-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.user-dropdown button:hover { background: var(--bg); }

/* Bottom nav */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 2px;
  font-size: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  transition: color 0.2s;
  min-width: 0;
}
.nav-item.active { color: var(--accent); font-weight: 600; }
.nav-item svg { width: 22px; height: 22px; margin-bottom: 1px; }

.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: var(--text-secondary);
}

/* Sections */
.section { display: none; padding: 16px; max-width: 800px; margin: 0 auto; }
.section.active { display: block; }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Progress bar */
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-sub { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.stat-link { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.stat-link:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.stat-link:active { transform: scale(0.97); }
.dash-link { cursor: pointer; transition: background 0.15s; border-radius: 8px; }
.dash-link:hover { background: #f0f0f0; }
.dash-link:active { background: var(--border); }
.dash-view-all { padding: 10px 12px; font-size: 13px; color: var(--accent); font-weight: 600; text-align: center; border-top: 1px solid var(--border); }
.dash-section-link { font-size: 12px; font-weight: 600; color: var(--accent); cursor: pointer; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); padding: 8px 12px; border-bottom: 2px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-complete { background: #d4edda; color: #155724; }
.badge-progress { background: #cce5ff; color: #004085; }
.badge-pending { background: #fff3cd; color: #856404; }
.badge-overdue { background: #f8d7da; color: #721c24; }
.badge-paid { background: #d4edda; color: #155724; }
.badge-unpaid { background: #f8d7da; color: #721c24; }

/* Timeline */
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}
.timeline-content { flex: 1; }
.timeline-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  cursor: pointer;
}
.timeline-title:hover { text-decoration: underline; }
.timeline-edit-icon {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.timeline-title:hover .timeline-edit-icon { opacity: 1; }
.timeline-dates { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.timeline-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.timeline-bar-fill { height: 100%; border-radius: 3px; }

/* Decisions */
.decision-item {
  padding: 12px 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.decision-item:hover { background: #f0f0f0; }
.decision-item:active { background: var(--border); }
.decision-item:last-child { border-bottom: none; }
.decision-topic { font-weight: 600; font-size: 15px; }
.decision-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.decision-deadline { font-size: 12px; margin-top: 4px; }

/* Contacts */
.contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.contact-card:hover { background: #f0f0f0; }
.contact-card:active { background: var(--border); }
.contact-card:last-child { border-bottom: none; }
.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.contact-info { flex: 1; }
.contact-name { font-weight: 600; font-size: 15px; }
.contact-role { font-size: 12px; color: var(--text-secondary); }
.contact-actions { display: flex; gap: 8px; }
.contact-actions a {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  text-decoration: none;
}

/* Notes */
.note-item {
  position: relative;
  padding: 12px 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  transition: background 0.15s;
}
.note-item:last-child { border-bottom: none; }
.note-head { cursor: pointer; padding-right: 36px; border-radius: 6px; }
.note-head:hover { background: #f0f0f0; }
.note-head:active { background: var(--border); }
.note-date { font-size: 12px; color: var(--text-secondary); }
.note-title { font-weight: 600; font-size: 15px; margin-top: 2px; }
.note-preview {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  position: relative;
}
.note-item:not(.expanded):not(.note-no-overflow) .note-preview::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22px;
  background: linear-gradient(to bottom, rgba(255,255,255,0), var(--card));
  pointer-events: none;
}
.note-item.expanded .note-preview {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}
.note-edit-btn {
  position: absolute;
  top: 10px;
  right: 6px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 16px;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.note-edit-btn:hover { background: var(--border); color: var(--text); }
.note-expand-btn {
  display: inline-block;
  margin-top: 6px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
}
.note-expand-btn:hover { text-decoration: underline; }
.note-chevron { font-size: 10px; }
.note-no-overflow .note-expand-btn { display: none; }

/* FAB */
.fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(45,106,79,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  transition: transform 0.2s;
}
.fab:active { transform: scale(0.9); }

/* Quick menu */
.quick-menu {
  display: none;
  position: fixed;
  bottom: 144px;
  right: 20px;
  z-index: 98;
  flex-direction: column;
  gap: 8px;
}
.quick-menu.active { display: flex; }
.quick-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: white;
  border-radius: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  border: none;
  white-space: nowrap;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: flex-end;
  overflow: hidden;
}
.modal-overlay.active { display: flex; }
.modal {
  background: white;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
  animation: slideUp 0.2s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; margin-top: 12px; }
.modal input, .modal select, .modal textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.modal textarea { resize: vertical; min-height: 80px; }
#note-content, #issue-desc, #dec-notes, #dec-chosen { min-height: 160px; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; }
.modal-actions button {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--bg); color: var(--text); }

/* Budget bars */
.budget-row {
  padding: 10px 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.budget-row:hover { background: #f0f0f0; }
.budget-row:active { background: var(--border); }
.budget-row:last-child { border-bottom: none; }
.budget-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.budget-bar {
  height: 20px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.budget-bar-fill {
  height: 100%;
  border-radius: 4px;
  position: absolute;
  top: 0;
  left: 0;
}
.budget-contracted { background: #b7e4c7; }
.budget-paid { background: var(--accent); }
.budget-amount { font-size: 11px; color: var(--text-secondary); display: flex; justify-content: space-between; margin-top: 2px; }

/* Filter tabs */
.filter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.filter-tab {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: white;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.filter-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.sort-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: white;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.sort-toggle:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Phase task cards */
.phase-task-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--bg);
}
.phase-task-row:last-child { margin-bottom: 0; }
.phase-task-header {
  display: flex;
  gap: 8px;
  align-items: center;
}
.phase-task-done { width: 20px; height: 20px; flex-shrink: 0; cursor: pointer; }
.phase-task-text {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
}
/* Override .modal input width for task row inputs */
.phase-task-header input { width: auto; }
.phase-task-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 0 4px;
  flex-shrink: 0;
}
.phase-task-details {
  display: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.phase-task-details.expanded { display: block; }
.phase-task-dates {
  display: flex;
  gap: 8px;
}
.phase-task-dates > div { flex: 1; min-width: 0; }
.phase-task-dates input[type="date"] { width: 100%; box-sizing: border-box; }
.phase-task-dates label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 2px;
  margin-top: 0;
}
.phase-task-details select,
.phase-task-details textarea {
  margin-top: 8px;
}
.phase-task-details label.phase-task-field-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 8px;
  margin-bottom: 2px;
}
.phase-task-delete {
  margin-top: 10px;
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
}
@media (max-width: 480px) {
  .phase-task-dates { flex-direction: column; gap: 4px; }
}

/* Issue type badges */
.badge-type-snag { background: #fff3cd; color: #856404; }
.badge-type-change_order { background: #cce5ff; color: #004085; }
.badge-type-delay { background: #f8d7da; color: #721c24; }

/* Severity badges */
.badge-severity-minor { background: #e2e3e5; color: #383d41; }
.badge-severity-major { background: #fff3cd; color: #856404; }
.badge-severity-critical { background: #f8d7da; color: #721c24; }

/* Budget overrun bar */
.budget-overrun { background: var(--danger); opacity: 0.7; }

/* Offer status badges */
.badge-received { background: #fff3cd; color: #856404; }
.badge-accepted { background: #d4edda; color: #155724; }
.badge-rejected { background: #f8d7da; color: #721c24; }

/* Offer cards */
.offer-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}

/* Budget log items */
.budget-log-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.budget-log-item:last-child { border-bottom: none; }
.budget-log-amount { font-weight: 600; margin-top: 2px; }
.budget-log-reason { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }

/* Issue items */
.issue-item {
  padding: 12px 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.issue-item:hover { background: #f0f0f0; }
.issue-item:active { background: var(--border); }
.issue-item:last-child { border-bottom: none; }

/* Modal delete */
.modal-delete button:hover { text-decoration: underline; }

/* Nav overflow for 7 items */
.nav { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.nav-item { min-width: 0; }

@media (min-width: 600px) {
  .stats-row { grid-template-columns: repeat(4, 1fr); }
  .section { padding: 24px; }
}

.topbar{flex-wrap:wrap;gap:12px}.topbar>div:last-child{flex-wrap:wrap}
