:root {
  --navy: #002A5C;
  --navy-dark: #001B3D;
  --olive: #AFBD21;
  --olive-dark: #8E9A1B;
  --blue-gray: #7A8CB0;
  --pale-olive: #DBE0A2;
  --review-flag: #E08A2C;

  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --border: #DCE1EA;
  --text: #1A2433;
  --text-muted: #5B6B85;

  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

/* ---------- Header ---------- */

header {
  background: var(--navy);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  height: 32px;
  width: auto;
  display: block;
}

.brand h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}

/* Dial connection status pill, with a small orbiting ring when connected
   — a quiet nod to the atom motif in the logo, functional not decorative */

.dial-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 5px 12px 5px 8px;
}

.dial-dot-wrap {
  position: relative;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.dial-dot {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6b7280;
}

.dial-status.connected .dial-dot {
  background: var(--olive);
}

.dial-status.connected .dial-dot-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.5px solid var(--olive);
  border-radius: 50%;
  opacity: 0.5;
  animation: orbit-pulse 2.2s ease-out infinite;
}

@keyframes orbit-pulse {
  0%   { transform: scale(0.5); opacity: 0.6; }
  100% { transform: scale(1.6); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .dial-status.connected .dial-dot-wrap::before { animation: none; }
}

/* ---------- Layout ---------- */

main {
  max-width: 1600px;
  width: 94%;
  margin: 24px auto;
  padding: 0 0 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.scroll-card {
  padding: 0;
  overflow-x: auto;
}

/* ---------- Filters ---------- */

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

select, input[type="date"], input[type="text"] {
  font-family: var(--font);
  font-size: 13.5px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  min-width: 150px;
}

select:focus, input:focus {
  outline: 2px solid var(--olive);
  outline-offset: 1px;
}

.preset-group {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}

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

.preset-btn.active {
  background: var(--navy);
  color: white;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 7px;
}

.checkbox-group input {
  width: 15px;
  height: 15px;
  accent-color: var(--review-flag);
}

.checkbox-group label {
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.reset-link {
  font-size: 12.5px;
  color: var(--blue-gray);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font);
  padding-bottom: 8px;
}

.reset-link:hover { color: var(--navy); }

/* ---------- Summary strip ---------- */

.summary-row {
  display: flex;
  gap: 32px;
}

.summary-item .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.summary-item.non-billable .value { color: var(--blue-gray); }

.summary-item .label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Table ---------- */

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

thead th:hover { color: var(--navy); }

thead th.sort-active { color: var(--navy); }

thead th .arrow { font-size: 10px; margin-left: 3px; opacity: 0.6; }

tbody tr {
  border-bottom: 1px solid var(--border);
}

tbody tr:hover { background: #FAFBFC; }

tbody tr.needs-review {
  box-shadow: inset 3px 0 0 var(--review-flag);
}

td {
  padding: 9px 10px;
  vertical-align: top;
  white-space: nowrap;
}

td.numeric {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
}

.badge.billable {
  background: rgba(175, 189, 33, 0.18);
  color: var(--olive-dark);
}

.badge.non-billable {
  background: rgba(122, 140, 176, 0.18);
  color: var(--blue-gray);
}

.source-tag {
  font-size: 11.5px;
  color: var(--text-muted);
}

.review-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--review-flag);
}

.notes-cell {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state .big {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.toolbar h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.btn-primary, .btn-secondary {
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--navy);
  color: white;
}

.btn-primary:hover { background: var(--navy-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { background: var(--bg); }

/* ---------- Row action icons ---------- */

.row-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1;
}

.icon-btn:hover { background: var(--bg); color: var(--navy); }

.icon-btn.delete:hover { color: #C0392B; }

/* ---------- Inline note editing ---------- */

.notes-cell {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
}

.notes-cell:hover {
  background: var(--pale-olive);
  color: var(--text);
}

.notes-edit-textarea {
  width: 100%;
  min-width: 200px;
  font-family: var(--font);
  font-size: 13px;
  padding: 5px 7px;
  border: 1px solid var(--olive);
  border-radius: 4px;
  resize: vertical;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 27, 61, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 440px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0, 27, 61, 0.25);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--navy);
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

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

.modal-error {
  background: rgba(224, 138, 44, 0.12);
  color: var(--review-flag);
  border: 1px solid rgba(224, 138, 44, 0.3);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.form-group select, .form-group input, .form-group textarea {
  width: 100%;
  font-family: var(--font);
  font-size: 13.5px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.form-group textarea { resize: vertical; }

.form-row {
  display: flex;
  gap: 10px;
}

.form-row .form-group { flex: 1; }

.adhoc-box {
  background: rgba(224, 138, 44, 0.08);
  border: 1px solid rgba(224, 138, 44, 0.3);
  border-radius: 6px;
  padding: 12px 14px 2px;
  margin-bottom: 14px;
}

.adhoc-box-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--review-flag);
  margin-bottom: 10px;
}

.optional-tag {
  font-weight: 400;
  text-transform: none;
  color: var(--text-muted);
  letter-spacing: 0;
}

.adhoc-tag {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--review-flag);
  margin-left: 5px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ---------- Nav ---------- */

.main-nav {
  display: flex;
  gap: 4px;
}

.main-nav a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px;
}

.main-nav a:hover { color: white; background: rgba(255, 255, 255, 0.08); }

.main-nav a.active {
  color: white;
  background: rgba(255, 255, 255, 0.15);
  font-weight: 600;
}

/* ---------- Field hints ---------- */

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

.sync-note {
  font-size: 12.5px;
  color: var(--olive-dark);
  height: 16px;
  margin: -10px 0 14px 2px;
}

.entry-toast {
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  background: rgba(175, 189, 33, 0.14);
  color: var(--olive-dark);
  border: 1px solid rgba(175, 189, 33, 0.35);
}

.entry-toast.warning {
  background: rgba(224, 138, 44, 0.1);
  color: var(--review-flag);
  border-color: rgba(224, 138, 44, 0.3);
}

@keyframes highlight-flash {
  0% { background: var(--pale-olive); }
  100% { background: transparent; }
}

tbody tr.just-saved {
  animation: highlight-flash 2s ease-out;
}

/* ---------- Management tree ---------- */

.tree-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}

.tree-row.level-client { background: var(--surface); }
.tree-row.level-project { background: #FAFBFD; padding-left: 40px; }
.tree-row.level-task { background: #F6F8FB; padding-left: 64px; }

.tree-row.inactive { opacity: 0.5; }

.tree-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-muted);
  width: 16px;
  flex-shrink: 0;
}

.tree-toggle.spacer { visibility: hidden; }

.tree-name {
  font-size: 13.5px;
  font-weight: 500;
  flex: 1;
}

.tree-row.level-client .tree-name { font-weight: 600; color: var(--navy); }

.type-badge {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--pale-olive);
  color: var(--olive-dark);
}

.type-badge.internal {
  background: rgba(122, 140, 176, 0.18);
  color: var(--blue-gray);
}

.status-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
}

.status-badge.active { background: rgba(175, 189, 33, 0.18); color: var(--olive-dark); }
.status-badge.inactive { background: #EEE; color: var(--text-muted); }

.tree-meta {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.tree-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.add-child-row {
  padding: 8px 16px 8px 40px;
  border-bottom: 1px solid var(--border);
  background: #FAFBFD;
}

.add-child-row.for-task { padding-left: 64px; background: #F6F8FB; }

.add-child-btn {
  background: none;
  border: none;
  color: var(--blue-gray);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0;
}

.add-child-btn:hover { color: var(--navy); }

/* ---------- Tag chip input ---------- */

.tag-input-box {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--surface);
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 4px;
}

.tag-chips:empty { margin-bottom: 0; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(0, 42, 92, 0.08);
  color: var(--navy);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 6px 3px 9px;
  border-radius: 999px;
}

.tag-chip button {
  background: none;
  border: none;
  color: var(--navy);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.6;
}

.tag-chip button:hover { opacity: 1; }

#entryTagInput {
  border: none;
  outline: none;
  width: 100%;
  font-family: var(--font);
  font-size: 13.5px;
  padding: 3px 2px;
}

.tag-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 160px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 4px 10px rgba(0, 27, 61, 0.1);
}

.tag-suggestion-item {
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}

.tag-suggestion-item:hover,
.tag-suggestion-item.active {
  background: var(--pale-olive);
}

/* ---------- Tag badges in the entries table ---------- */

.tags-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 180px;
}

.tag-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--navy);
  background: rgba(0, 42, 92, 0.08);
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

.user-checklist {
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 160px;
  overflow-y: auto;
  padding: 8px 10px;
}

.user-checklist .checkbox-group {
  padding-bottom: 6px;
}

.user-checklist .checkbox-group:last-child {
  padding-bottom: 0;
}

.user-checklist .empty-note {
  font-size: 12.5px;
  color: var(--text-muted);
}

.user-checklist .checkbox-group label {
  text-transform: none;
  font-weight: 400;
  letter-spacing: normal;
  white-space: nowrap;
}
