/* ============================================================
   Service Visit Tracker — Mobile-First Responsive CSS
   ============================================================ */

/* --- Custom Properties ------------------------------------ */
:root {
  /* Brand / sidebar */
  --sidebar-bg: #1a1a2e;
  --sidebar-width: 240px;
  --sidebar-text: #ffffff;
  --sidebar-hover: rgba(255, 255, 255, 0.12);
  --sidebar-active: rgba(255, 255, 255, 0.2);

  /* Activity type colors */
  --color-green: #28a745;
  --color-blue: #007bff;
  --color-purple: #9b59b6;
  --color-olive: #8B8000;
  --color-red: #dc3545;
  --color-gray: #6c757d;

  /* Status badge colors */
  --status-open: #007bff;
  --status-closed: #6c757d;
  --status-po-received: #28a745;
  --status-waiting: #f0850a;

  /* Surfaces */
  --bg-body: #f4f6f9;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --border-color: #dee2e6;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);
  --radius-sm: 4px;
  --radius-md: 8px;

  /* Spacing scale */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 32px;

  /* Touch target */
  --tap-min: 44px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* --- Reset & Base ----------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--color-blue);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

/* --- Layout: Sidebar + Main ------------------------------- */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform var(--transition-normal);
  overflow-y: auto;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  padding: var(--sp-lg) var(--sp-md);
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .logo {
  max-width: 140px;
  margin-bottom: var(--sp-sm);
}

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-md) 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-md) var(--sp-lg);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.95rem;
  min-height: var(--tap-min);
  transition: background var(--transition-fast);
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--sidebar-active);
  font-weight: 600;
}

.sidebar-nav a .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.sidebar-overlay.active {
  display: block;
}

/* Main content */
.main-content {
  flex: 1;
  min-width: 0;
  padding: var(--sp-md);
}

/* Top bar (mobile) */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 2px 0;
  margin-bottom: var(--sp-xs);
  flex-shrink: 0;
}

.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-min);
  height: var(--tap-min);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 1.5rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.hamburger:hover {
  background: rgba(0, 0, 0, 0.06);
}

.topbar h1,
.topbar-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

/* --- Filter Bar ------------------------------------------- */
.filter-bar {
  display: flex;
  gap: var(--sp-sm);
  padding: var(--sp-sm) 0;
  margin-bottom: var(--sp-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.filter-bar::-webkit-scrollbar {
  height: 4px;
}
.filter-bar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.filter-bar select,
.filter-bar input {
  min-width: 140px;
  height: var(--tap-min);
  padding: var(--sp-sm) var(--sp-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-bar select:focus,
.filter-bar input:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

.filter-bar .search-input {
  min-width: 200px;
  flex: 1;
}

.activity-count {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--sp-md);
}

/* --- Activity Cards (mobile) ------------------------------ */
.activity-cards {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

.activity-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border-left: 5px solid var(--color-gray);
  padding: var(--sp-md);
  cursor: pointer;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
  min-height: var(--tap-min);
}

.activity-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.activity-card:active {
  transform: translateY(0);
}

/* Color borders by activity type */
.activity-card[data-color="green"]  { border-left-color: var(--color-green); }
.activity-card[data-color="blue"]   { border-left-color: var(--color-blue); }
.activity-card[data-color="purple"] { border-left-color: var(--color-purple); }
.activity-card[data-color="olive"]  { border-left-color: var(--color-olive); }
.activity-card[data-color="red"]    { border-left-color: var(--color-red); }
.activity-card[data-color="gray"]   { border-left-color: var(--color-gray); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--sp-sm);
}

.card-company {
  font-weight: 600;
  font-size: 1rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-date {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  margin-left: var(--sp-sm);
}

.card-body {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-xs) var(--sp-md);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.card-body span {
  white-space: nowrap;
}

.card-assignee {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  margin-top: var(--sp-sm);
  padding-top: var(--sp-sm);
  border-top: 1px solid var(--border-color, #e5e7eb);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.card-assignee svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.card-assignee .assignee-label {
  font-weight: 500;
}

.card-assignee .assignee-name {
  font-weight: 600;
  color: var(--text-primary, inherit);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* --- Activity Table (desktop) ----------------------------- */
.activity-table-wrapper {
  display: none;
  overflow-x: auto;
}

.activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.activity-table th,
.activity-table td {
  padding: var(--sp-sm) var(--sp-md);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.activity-table th {
  background: var(--bg-body);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.activity-table tbody tr {
  cursor: pointer;
  transition: background var(--transition-fast);
}

.activity-table tbody tr:hover {
  background: rgba(0, 123, 255, 0.04);
}

.activity-table .color-indicator {
  width: 4px;
  padding: 0;
}

.activity-table .color-indicator span {
  display: block;
  width: 4px;
  height: 100%;
  min-height: 20px;
  border-radius: 2px;
}

.color-indicator-green  span { background: var(--color-green); }
.color-indicator-blue   span { background: var(--color-blue); }
.color-indicator-purple span { background: var(--color-purple); }
.color-indicator-olive  span { background: var(--color-olive); }
.color-indicator-red    span { background: var(--color-red); }
.color-indicator-gray   span { background: var(--color-gray); }

/* --- Status Badges ---------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-open       { background: rgba(0, 123, 255, 0.12); color: var(--status-open); }
.badge-closed     { background: rgba(108, 117, 125, 0.12); color: var(--status-closed); }
.badge-po-received { background: rgba(40, 167, 69, 0.12); color: var(--status-po-received); }
.badge-waiting    { background: rgba(240, 133, 10, 0.12); color: var(--status-waiting); }

/* --- Calendar --------------------------------------------- */
/* --- Calendar pages: flex column so the grid fills viewport ---- */
.calendar-page,
.team-calendar-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.calendar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-xs);
  flex-shrink: 0;
}

/* Inline the personal-calendar Person dropdown with the nav so it
   doesn't take its own row. */
.calendar-controls .calendar-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.calendar-controls .calendar-filter .filter-label {
  display: inline;
  margin: 0;
  font-size: 0.7rem;
}

.calendar-controls .calendar-filter .filter-select {
  width: auto;
  min-width: 140px;
  height: 32px;
  padding: 2px 8px;
}

.calendar-controls .month-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
}

.calendar-controls .month-label {
  font-size: 1.1rem;
  font-weight: 600;
  min-width: 160px;
  text-align: center;
}

.calendar-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.calendar-controls button:hover {
  background: var(--bg-body);
}

.calendar-controls select {
  height: var(--tap-min);
  padding: var(--sp-sm) var(--sp-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 0.875rem;
  color: var(--text-primary);
}

/* The grid wrapper expands to fill the remaining vertical space so the
   whole month is visible without scrolling. */
.calendar-grid-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--border-color);
  overflow: hidden;
  background: var(--bg-card);
}

.calendar-grid-wrapper .calendar-header-grid {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  border-bottom: none;
  flex-shrink: 0;
}

.calendar-grid-wrapper .calendar-body-grid {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  /* The body is now a flex column of .cal-week rows. Each week is its own
     7-column grid so we can absolutely-position multi-day bars within it. */
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: 1fr;
  position: relative;
  flex: 1;
  min-height: 0;
  border-bottom: 1px solid var(--border-color);
  overflow: hidden;
}

.cal-week:last-child {
  border-bottom: none;
}

/* A multi-day bar segment, absolutely positioned within its week.
   `left` and `width` are set inline as percentages of the week width,
   `top` is set based on the bar's assigned lane. */
.cal-bar-span {
  position: absolute;
  height: 13px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 0.65rem;
  line-height: 1;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 2px;
  z-index: 2;
  text-decoration: none;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.cal-bar-span:hover {
  opacity: 0.88;
  text-decoration: none;
}

.calendar-grid .day-header,
.calendar-grid .calendar-day-header {
  padding: 4px;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--bg-body);
  border-bottom: 1px solid var(--border-color);
}

.calendar-grid .day-cell {
  min-height: 0;
  padding: 2px;
  border-right: 1px solid var(--border-color);
  position: relative;
  overflow: hidden;
}

.calendar-grid .day-cell:nth-child(7n) {
  border-right: none;
}

.calendar-grid .day-cell.outside-month {
  background: #f9fafb;
  color: #ccc;
}

.calendar-grid .day-cell.today {
  background: rgba(0, 123, 255, 0.06);
}

.day-number {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  position: absolute;
  top: 2px;
  right: 4px;
  line-height: 1;
}

.day-cell.today .day-number {
  color: var(--color-blue);
}

.day-cell.outside-month .day-number {
  color: #ccc;
}

.day-events {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: calc(100% - 14px);
  /* Vertical clipping only — horizontal must stay visible so the negative
     margins on .cal-bar.bar-start/middle/end can bridge across day cells
     and form one continuous multi-day bar. */
  overflow-y: hidden;
}

/* Activity bar inside calendar */
.cal-bar {
  display: block;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.65rem;
  line-height: 1.3;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.cal-bar:hover {
  opacity: 0.85;
}

/* Multi-day bar spanning */
.cal-bar.bar-start {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  margin-right: -4px;
}

.cal-bar.bar-middle {
  border-radius: 0;
  margin-left: -4px;
  margin-right: -4px;
}

.cal-bar.bar-end {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  margin-left: -4px;
}

/* --- Team Calendar Extras --------------------------------- */
/* Engineer toggles are now tucked inside a <details> so by default
   they don't push the calendar off-screen. When opened, the list is
   capped to a few rows tall and scrolls internally. */
.team-engineer-bar {
  margin-bottom: var(--sp-xs);
  flex-shrink: 0;
}

.team-engineer-bar > summary {
  cursor: pointer;
  padding: 4px 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.team-engineer-bar > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 0.7rem;
}

.team-engineer-bar[open] > summary::before {
  transform: rotate(90deg);
}

.team-engineer-bar > summary::-webkit-details-marker {
  display: none;
}

.team-toggles,
.team-engineer-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 4px 0;
  max-height: 110px;
  overflow-y: auto;
}

.team-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 0.75rem;
  user-select: none;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.team-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  margin: 0;
}

.team-engineer-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.team-engineer-actions .btn-small {
  padding: 2px 8px;
  font-size: 0.7rem;
}

.color-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: middle;
}

.legend-swatch-clickable {
  cursor: pointer;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  transition: transform 0.1s ease;
}

.legend-swatch-clickable:hover {
  transform: scale(1.15);
  border-color: rgba(255, 255, 255, 0.8);
}

.team-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-bottom: var(--sp-xs);
  font-size: 0.72rem;
  flex-shrink: 0;
  max-height: 40px;
  overflow-y: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
}

/* --- Detail Page ------------------------------------------ */
.detail-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-lg);
}

.detail-header .btn {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
}

.detail-header h2 {
  flex: 1;
  font-size: 1.2rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-lg);
  margin-bottom: var(--sp-lg);
}

.detail-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--sp-md);
  padding-bottom: var(--sp-sm);
  border-bottom: 1px solid var(--border-color);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-md);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.field-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
}

.field-value {
  font-size: 0.95rem;
  word-break: break-word;
}

.field-value:empty::before {
  content: "\2014";
  color: #ccc;
}

/* --- Forms / Edit mode ------------------------------------ */
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--sp-sm) var(--sp-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  min-height: var(--tap-min);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

/* --- Buttons ---------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-xs);
  padding: var(--sp-sm) var(--sp-md);
  min-height: var(--tap-min);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-blue);
  color: #fff;
}
.btn-primary:hover { background: #0069d9; }

.btn-success {
  background: var(--color-green);
  color: #fff;
}
.btn-success:hover { background: #218838; }

.btn-danger {
  background: var(--color-red);
  color: #fff;
}
.btn-danger:hover { background: #c82333; }

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-body); }

.btn-group {
  display: flex;
  gap: var(--sp-sm);
  flex-wrap: wrap;
}

/* --- Read-only sub-tables --------------------------------- */
.sub-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: var(--sp-sm);
}

.sub-table th,
.sub-table td {
  padding: var(--sp-sm);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.sub-table th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.sub-table td {
  color: var(--text-primary);
}

.empty-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-style: italic;
  padding: var(--sp-md) 0;
}

/* --- Utilities -------------------------------------------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.mt-md { margin-top: var(--sp-md); }
.mb-md { margin-bottom: var(--sp-md); }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--color-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  padding: var(--sp-xl);
  color: var(--text-secondary);
}

/* --- Responsive: Tablet (>=768px) ------------------------- */
@media (min-width: 768px) {
  .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none !important;
  }

  .hamburger {
    display: none;
  }

  /* On desktop the sidebar already shows the active page, so the topbar
     title is redundant — hide it to reclaim vertical space. */
  .topbar {
    display: none;
  }

  .main-content {
    margin-left: var(--sidebar-width);
    padding: var(--sp-lg);
  }

  .filter-bar {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .filter-bar select,
  .filter-bar input {
    min-width: 160px;
  }

  /* Switch from cards to table */
  .activity-cards {
    display: none;
  }

  .activity-table-wrapper {
    display: block;
  }

  .field-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Day cells are now flex-driven (see .calendar-body-grid) so they
     auto-stretch to fill the viewport. No fixed min-height needed. */

  .cal-bar {
    font-size: 0.7rem;
  }
}

/* --- Responsive: Desktop (>=1024px) ----------------------- */
@media (min-width: 1024px) {
  .main-content {
    padding: var(--sp-lg) var(--sp-xl);
  }

  .field-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }

  /* Day cells are flex-driven; no fixed min-height in desktop mode. */

  .cal-bar {
    font-size: 0.72rem;
    padding: 2px 5px;
  }
}

/* ============================================================
   Settings Page
   ============================================================ */

.settings-page {
  max-width: 700px;
  margin: 0 auto;
  padding: 1rem;
}

.settings-section {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.settings-section h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: #1a1a2e;
  border-bottom: 1px solid #eee;
  padding-bottom: 0.5rem;
}

.settings-section h3 {
  margin: 1rem 0 0.5rem;
  font-size: 0.95rem;
  color: #333;
}

.setting-row {
  margin-bottom: 0.75rem;
}

.setting-row label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 0.25rem;
}

.setting-row input[type="text"],
.setting-row input[type="password"],
.setting-row input[type="number"] {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.95rem;
  box-sizing: border-box;
}

.setting-row small {
  display: block;
  color: #888;
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.btn-primary {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  background: #007bff;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: #0056b3; }
.btn-primary:disabled { background: #6c757d; cursor: not-allowed; }

.btn-secondary {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  background: #6c757d;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover { background: #545b62; }

.btn-danger {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  background: #dc3545;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-danger:hover { background: #c82333; }

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  background: #007bff;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 0.5rem;
}
.btn-sm:hover { background: #0056b3; }

.btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.api-key-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.api-key-display code {
  background: #f4f4f4;
  padding: 0.4rem 0.7rem;
  border-radius: 4px;
  font-size: 0.85rem;
  word-break: break-all;
  flex: 1;
}

.status-msg {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.hint {
  color: #888;
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
}

.sync-status {
  margin-bottom: 1rem;
}

.status-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}

.status-label {
  font-weight: 600;
  color: #555;
}

.field-map-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.field-map-table th {
  text-align: left;
  padding: 0.4rem 0.5rem;
  background: #f4f4f4;
  border-bottom: 2px solid #ddd;
}

.field-map-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid #eee;
}

.field-map-table select {
  width: 100%;
  padding: 0.3rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.85rem;
}

/* --- New Activity Button ---------------------------------- */
.results-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
}

.btn-new-activity {
  font-size: 0.85rem;
  white-space: nowrap;
  text-decoration: none !important;
}

/* --- Detail View Header ----------------------------------- */
.detail-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
  padding-bottom: var(--sp-sm);
  border-bottom: 1px solid var(--border-color);
}

.detail-view-header h3 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* --- Sub-record Section Header ----------------------------- */
.sub-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-md);
  padding-bottom: var(--sp-sm);
  border-bottom: 1px solid var(--border-color);
}

.sub-section-header h3 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.sub-section-header .btn-sm {
  padding: 4px 12px;
  font-size: 0.8rem;
  min-height: 32px;
}

.section-count {
  font-weight: 400;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* --- Sub-record Action Buttons ----------------------------- */
.sub-actions-col {
  width: 80px;
  text-align: center;
}

.sub-actions-cell {
  white-space: nowrap;
  text-align: center;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon:hover {
  background: rgba(0, 123, 255, 0.1);
  color: var(--color-blue);
}

.btn-icon-danger:hover {
  background: rgba(220, 53, 69, 0.1);
  color: var(--color-red);
}

/* --- Sub-record Modal -------------------------------------- */
.sub-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: var(--sp-md);
}

.sub-modal .modal-dialog {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--sp-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.sub-modal .modal-dialog h3 {
  margin: 0 0 var(--sp-md);
  font-size: 1.1rem;
}

.sub-modal-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  margin-bottom: var(--sp-lg);
}

.modal-actions {
  display: flex;
  gap: var(--sp-sm);
  justify-content: flex-end;
}

.modal-actions .btn {
  min-width: 80px;
}

/* --- Detail Toolbar Fix ----------------------------------- */
.detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-lg);
}

.detail-actions {
  display: flex;
  gap: var(--sp-sm);
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  min-height: var(--tap-min);
  padding: var(--sp-sm);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.btn-back:hover {
  background: rgba(0, 0, 0, 0.04);
  text-decoration: none;
}

/* --- Sidebar Close Button ---------------------------------- */
.sidebar-close {
  position: absolute;
  top: var(--sp-sm);
  right: var(--sp-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.sidebar-close:hover {
  opacity: 1;
}

@media (min-width: 768px) {
  .sidebar-close {
    display: none;
  }
}

/* --- Sidebar Overlay Fix ----------------------------------- */
.sidebar-overlay.visible {
  display: block;
}

/* --- Main Wrapper ------------------------------------------ */
/* Use full viewport height so the calendar can flex to fill it. */
.main-wrapper {
  padding: var(--sp-sm) var(--sp-md);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.main-wrapper > .content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 768px) {
  .main-wrapper {
    margin-left: var(--sidebar-width);
    padding: var(--sp-sm) var(--sp-md);
  }
}

@media (min-width: 1024px) {
  .main-wrapper {
    padding: var(--sp-sm) var(--sp-md);
  }
}

/* --- Filter Row -------------------------------------------- */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
  align-items: flex-end;
}

.filter-item {
  flex: 1;
  min-width: 120px;
}

.filter-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.filter-select {
  width: 100%;
  height: var(--tap-min);
  padding: var(--sp-sm) var(--sp-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 0.875rem;
  color: var(--text-primary);
}

.filter-select:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

.filter-clear-btn {
  height: var(--tap-min);
  padding: var(--sp-sm) var(--sp-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.filter-clear-btn:hover {
  background: var(--bg-body);
}

/* --- Search Bar -------------------------------------------- */
.search-bar {
  margin-bottom: var(--sp-md);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-secondary);
  pointer-events: none;
}

.search-field {
  width: 100%;
  height: var(--tap-min);
  padding: var(--sp-sm) var(--sp-md) var(--sp-sm) 40px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 0.95rem;
  color: var(--text-primary);
}

.search-field:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

/* --- Loading / Empty / Error States ----------------------- */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-xl);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.empty-state {
  text-align: center;
  padding: var(--sp-xl);
  color: var(--text-secondary);
}

.empty-state-text {
  font-size: 1.1rem;
  margin-top: var(--sp-md);
}

.empty-state-hint {
  font-size: 0.85rem;
  margin-top: var(--sp-xs);
}

.error-state {
  text-align: center;
  padding: var(--sp-xl);
}

.error-state-text {
  color: var(--color-red);
  font-size: 1rem;
  margin-bottom: var(--sp-md);
}

/* --- Sidebar Brand ----------------------------------------- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  justify-content: center;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
}

.sidebar-brand-text {
  font-weight: 600;
  font-size: 0.95rem;
}

.sidebar-footer {
  padding: var(--sp-md);
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-footer-text {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
  display: block;
}

.sidebar-build-label {
  display: block;
  margin-top: 2px;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.35);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* Sidebar nav list reset */
.sidebar-nav {
  list-style: none;
}

.sidebar-nav li {
  list-style: none;
}

.sidebar-icon {
  flex-shrink: 0;
}
