:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e0e2e7;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #c0392b;
  --primary-dark: #962d22;
  --spagnotti: #b5622c;
  --total-elevated: #2f8fd8;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 20px;
  margin: 0;
  white-space: nowrap;
}

.topbar-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

select, input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--panel);
  color: var(--text);
}

#searchBox { width: 240px; }

.btn-primary, .btn-secondary, .btn-danger, .btn-icon {
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eceff2; color: var(--text); }
.btn-secondary:hover { background: #dfe3e8; }
.btn-danger { background: #fdecea; color: #b91c1c; }
.btn-danger:hover { background: #f8d7d4; }
.btn-icon { background: transparent; font-size: 22px; line-height: 1; color: var(--text-muted); padding: 4px 8px; }

.board {
  display: flex;
  gap: 12px;
  padding: 16px;
  overflow-x: auto;
  align-items: flex-start;
}

.column {
  background: var(--panel);
  border-radius: var(--radius);
  min-width: 250px;
  max-width: 250px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 90px);
}

.column-header {
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--panel);
  border-radius: var(--radius) var(--radius) 0 0;
}

.column-count {
  background: var(--bg);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.stage-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}

.column-body {
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 120px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.card:hover {
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  border-color: #c7cad1;
}

.column-body.drag-over {
  background: rgba(37, 99, 235, 0.06);
  outline: 2px dashed #c7cad1;
  outline-offset: -4px;
  border-radius: 6px;
}

.substatus-popup {
  position: fixed;
  z-index: 200;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 200px;
}

.substatus-popup .popup-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 4px 10px;
  font-weight: 700;
}

.substatus-popup button {
  text-align: left;
  border: none;
  background: transparent;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}

.substatus-popup button:hover {
  background: var(--bg);
}

.card-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}

.company-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  color: white;
  margin-bottom: 6px;
}

.company-badge.spagnotti { background: var(--spagnotti); }
.company-badge.total-elevated { background: var(--total-elevated); }

.card-services {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.service-chip {
  font-size: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1px 6px;
  color: var(--text-muted);
}

.card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.card-substatus {
  display: inline-block;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 8px;
  padding: 1px 7px;
  margin-bottom: 4px;
}

.tracker-substatus {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  width: 640px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { margin: 0; font-size: 18px; }

.modal-body { padding: 16px 20px 20px; }

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.form-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-muted);
  gap: 4px;
}

.form-row label.full { flex: 1 1 100%; }

.form-row input, .form-row select {
  font-size: 14px;
  color: var(--text);
}

.services-fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 16px 0;
  padding: 10px 14px;
}

.services-fieldset legend {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 6px;
}

.services-columns {
  display: flex;
  gap: 24px;
}

.services-columns h4 {
  margin: 4px 0 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.services-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.services-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  flex-direction: row;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  align-items: center;
}

.spacer { flex: 1; }

.activity-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.activity-section h3 { font-size: 14px; margin: 0 0 10px; }

.note-add {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.note-add input { flex: 1; }

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.activity-item {
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
}

.activity-item time {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.schedule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.schedule-item-delete {
  font-size: 16px;
  padding: 0 4px;
}

.address-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.address-row input { flex: 1; }

.address-maps-link {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--border);
  text-decoration: none;
  font-size: 16px;
}

.measurement-card {
  display: flex;
  gap: 14px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  margin-top: 12px;
}

.measurement-card img {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 6px;
  flex: none;
  background: var(--panel);
  cursor: pointer;
}

.facet-details {
  margin-top: 10px;
}

.facet-details summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 0;
}

.facet-details .activity-list {
  margin-top: 8px;
}

.measurement-stats {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 16px;
  row-gap: 4px;
  align-content: start;
  font-size: 13px;
}

.measurement-stats .stat-label {
  color: var(--text-muted);
}

.measurement-stats .stat-value {
  font-weight: 600;
}

.measurement-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}

.attachment-size {
  color: var(--text-muted);
  font-size: 11px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 300;
}

.lightbox-overlay.hidden { display: none; }

.lightbox-track {
  display: flex;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.lightbox-slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  box-sizing: border-box;
  padding: 40px 20px;
}

.lightbox-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 301;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.hidden { display: none !important; }

.login-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  max-width: 440px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.login-card p {
  color: var(--text-muted);
  margin: 0 0 20px;
}

.login-logos {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
}

.login-logos img {
  height: 56px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
}

.login-description {
  font-size: 14px;
  line-height: 1.5;
  text-align: left;
}

.current-user-label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.field-readonly {
  font-size: 14px;
  color: var(--text);
  padding: 7px 0;
  display: block;
}

.users-panel {
  padding: 16px 20px;
  max-width: 640px;
  margin: 0 auto;
}

.users-header h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.add-user-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.add-user-form input {
  flex: 1;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.users-table th, .users-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.users-table th {
  background: var(--bg);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.api-keys-header {
  margin-top: 32px;
}

.api-keys-header .field-hint {
  margin-top: 4px;
}

.api-key-reveal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.api-key-reveal p {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
}

.gmail-connections {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.gmail-connection-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
}

.gmail-connection-row .gmail-company-name {
  font-weight: 600;
  min-width: 160px;
}

.email-import-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 13px;
}

.api-key-reveal code {
  display: block;
  word-break: break-all;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  margin-bottom: 10px;
  user-select: all;
}

.view-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}

.view-tab {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 5px;
  cursor: pointer;
}

.view-tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.tracker {
  padding: 16px 20px;
}

.tracker-summary {
  display: flex;
  gap: 24px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.summary-stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
}

.summary-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-value {
  font-size: 18px;
  font-weight: 700;
}

.tracker-table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.tracker-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tracker-table th, .tracker-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.tracker-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--bg);
  position: sticky;
  top: 0;
}

.tracker-table tbody tr:hover { background: var(--bg); }

.tracker-name {
  font-weight: 600;
  cursor: pointer;
}

.tracker-name:hover { text-decoration: underline; }

.tracker-money { font-weight: 600; }

.tracker-input {
  width: 90px;
  padding: 5px 7px;
  font-size: 13px;
}

.tracker-status {
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  border: none;
  color: white;
}

.tracker-status.status-pending, .summary-label.status-pending { background: #2563eb; }
.tracker-status.status-in_progress, .summary-label.status-in_progress { background: #d97706; }
.tracker-status.status-won, .summary-label.status-won { background: #059669; }
.tracker-status.status-lost, .summary-label.status-lost { background: #6b7280; }

.summary-label {
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
  width: fit-content;
}

.tracker-empty {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
}

.calendar {
  padding: 16px 20px;
}

.calendar-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.calendar-header h2 {
  font-size: 16px;
  margin: 0;
  min-width: 0;
  text-align: center;
}

.calendar-nav {
  font-size: 16px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.calendar-day-name {
  background: var(--bg);
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

.calendar-cell {
  background: var(--panel);
  min-height: 100px;
  min-width: 0;
  padding: 6px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calendar-cell.other-month {
  background: #fafafb;
}

.calendar-cell.other-month .calendar-day-num {
  color: #c7cad1;
}

.calendar-cell.today .calendar-day-num {
  background: var(--primary);
  color: white;
  border-radius: 50%;
}

.calendar-cell.drag-over {
  background: #fdecea;
}

.calendar-day-num {
  font-size: 12px;
  font-weight: 600;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}

.calendar-day-num:hover {
  background: var(--bg);
  border-radius: 50%;
}

.calendar-cell.today .calendar-day-num:hover {
  background: var(--primary-dark);
}

.calendar-events {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-width: 0;
}

.calendar-event-pill {
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  cursor: grab;
  max-width: 100%;
  overflow: hidden;
}

.calendar-event-pill:hover {
  border-color: var(--primary);
}

.pill-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill-time {
  margin-top: 1px;
  overflow: hidden;
}

.calendar-add-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  align-self: flex-start;
  padding: 0 2px;
  line-height: 1;
}

.calendar-add-btn:hover {
  color: var(--primary);
}

.event-modal {
  width: 480px;
}

.calendar-view-tabs {
  margin-left: 4px;
}

.day-view {
  max-width: 640px;
  margin: 0 auto;
}

.week-view {
  max-width: 640px;
  margin: 0 auto;
}

.week-day-group {
  margin-bottom: 20px;
}

.week-day-header {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 6px 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
}

.week-day-header:hover {
  color: var(--text);
}

.week-day-header.today {
  color: var(--primary);
}

.week-day-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 2px 4px;
}

.day-event-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.day-event-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-color: #c7cad1;
}

.day-event-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.day-event-name {
  font-weight: 700;
  font-size: 16px;
}

.day-event-company-badge {
  flex: none;
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
  color: white;
  line-height: 1.4;
}

.day-event-company-badge.spagnotti { background: var(--spagnotti); }
.day-event-company-badge.total-elevated { background: var(--total-elevated); }

.day-event-time-row {
  margin-bottom: 6px;
}

.day-event-time-row .event-time {
  font-size: 12px;
  padding: 2px 8px;
}

.day-event-notes {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  white-space: pre-wrap;
}

.day-view-empty {
  padding: 50px 20px;
  text-align: center;
  color: var(--text-muted);
}

.day-add-row {
  text-align: center;
  margin-top: 8px;
}

.time-mode-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
  width: fit-content;
}

.time-mode-btn {
  border: none;
  background: transparent;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 5px;
  cursor: pointer;
}

.time-mode-btn.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.time-fields {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.time-fields label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-muted);
  gap: 4px;
}

.event-time {
  display: inline-block;
  font-weight: 700;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  margin-right: 4px;
  vertical-align: middle;
  white-space: nowrap;
}

.event-time.set-time {
  background: var(--text);
  color: white;
}

.event-time.window-time {
  background: transparent;
  border: 1px solid var(--text-muted);
  color: var(--text-muted);
}

.field-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: normal;
}

.form-row input:disabled,
.form-row select:disabled {
  background: var(--bg);
  color: var(--text-muted);
}
