/* ============ TABLE ============ */
.table-wrapper {
  padding: 16px 24px 60px;
  position: relative;
  min-height: 300px;
}
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table thead {
  background: var(--surface-alt);
}
.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.data-table th.sortable:hover { background: var(--border); color: var(--text); }
.data-table th .sort-icon {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.35;
  vertical-align: middle;
  transition: opacity 0.15s;
}
.data-table th.sortable:hover .sort-icon { opacity: 0.7; }
.data-table th.sort-active .sort-icon { opacity: 1; color: var(--primary); }
.data-table th.sort-active { color: var(--primary); }

/* Days until badge — plain-language format */
.days-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.days-badge.overdue {
  background: var(--danger-bg);
  color: var(--danger);
}
.days-badge.today {
  background: var(--warning-bg);
  color: var(--warning);
}
.days-badge.upcoming {
  background: var(--warning-bg);
  color: var(--warning);
}
.days-badge.future {
  background: var(--surface-alt);
  color: var(--text-muted);
}

/* Settings modal — tabbed */
.modal-wide { max-width: 620px; }
.settings-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.settings-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  border-radius: 6px;
  transition: all 0.15s;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(15,23,42,0.10);
}
.settings-panel { min-height: 240px; }
.settings-panel > .settings-desc { margin-bottom: 14px; }
.settings-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}
#password-form { display: flex; flex-direction: column; gap: 14px; }

.color-labels-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding: 2px;
  margin-bottom: 14px;
}
.color-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  position: relative;
}
.color-label-row:hover { background: var(--surface-alt); }
.color-label-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}
.color-label-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}
.color-label-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.color-label-input::placeholder { color: var(--text-light); font-style: italic; }
.color-label-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  line-height: 1;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.color-label-row:hover .color-label-remove { opacity: 1; }
.color-label-remove:hover { color: var(--danger); background: var(--surface); }

.color-label-save {
  background: var(--primary);
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.color-label-save:hover { background: var(--primary-hover); }
.color-label-save.saving {
  background: var(--info);
  opacity: 0.7;
  pointer-events: none;
}
.color-label-save.saved {
  background: var(--success);
  pointer-events: none;
}
.color-label-badge {
  font-size: 9px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
  flex-shrink: 0;
}

.add-custom-color {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
}
.add-custom-color input[type="color"] {
  width: 40px;
  height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 2px;
  background: var(--surface);
}
.add-custom-color input[type="text"] {
  flex: 1;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 12px;
  font-family: inherit;
}
.add-custom-color input[type="text"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.add-custom-color .btn-primary {
  padding: 7px 14px;
  font-size: 12px;
}

/* Audit Log */
.audit-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.audit-filters input[type="text"],
.audit-filters select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.audit-filters input[type="text"] {
  flex: 1;
  min-width: 180px;
}
.audit-filters input[type="text"]:focus,
.audit-filters select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.audit-load-more {
  padding: 12px;
  text-align: center;
  border-top: 1px solid var(--border);
}
.audit-load-more .btn-secondary {
  padding: 8px 16px;
  font-size: 12px;
}
.audit-log-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.audit-log-list {
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.audit-entry {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  font-size: 12px;
}
.audit-entry:last-child { border-bottom: none; }
.audit-entry:hover { background: var(--surface-hover); }
.audit-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--primary-light);
  color: var(--primary);
}
.audit-icon.success { background: var(--success-bg); color: var(--success); }
.audit-icon.warn { background: var(--warning-bg); color: var(--warning); }
.audit-icon.danger { background: var(--danger-bg); color: var(--danger); }
.audit-body { flex: 1; min-width: 0; }
.audit-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.audit-title { color: var(--text); font-weight: 500; word-break: break-word; }
.audit-title strong { color: var(--primary); font-weight: 600; }
.audit-time {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}
.audit-detail {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
  line-height: 1.4;
}
.audit-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Weight History display */
.weight-history {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.weight-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.weight-entry:last-child { border-bottom: none; }
.weight-entry .w-date { color: var(--text-muted); }
.weight-entry .w-value { font-weight: 600; color: var(--text); }
.weight-entry .w-source {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text-muted);
}
.weight-entry .w-source.manual { background: var(--info-bg); color: var(--info); }
.log-weight-btn {
  margin-top: 8px;
  width: 100%;
  padding: 8px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.log-weight-btn:hover { background: var(--surface-alt); color: var(--text); border-color: var(--text-muted); }
.log-weight-form {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.log-weight-form input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
}
.log-weight-form input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.log-weight-form button {
  padding: 6px 14px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
}
.log-weight-form button:hover { background: var(--primary-hover); }
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Row coloring overrides default backgrounds */
.data-table tbody tr[data-color] td {
  background: var(--row-color) !important;
}

.cell-name { font-weight: 600; color: var(--text); cursor: pointer; }
.cell-name:hover { color: var(--primary); }
.cell-muted { color: var(--text-muted); font-size: 12px; }
.cell-mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }

.days-overdue { color: var(--danger); font-weight: 700; }
.days-upcoming { color: var(--warning); font-weight: 600; }
.days-future { color: var(--text-muted); }

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-paid { background: var(--success-bg); color: var(--success); }
.status-partial { background: var(--warning-bg); color: var(--warning); }
.status-overdue { background: var(--danger-bg); color: var(--danger); }
.status-sent { background: var(--info-bg); color: var(--info); }
.status-draft { background: var(--surface-alt); color: var(--text-muted); }
.status-neutral { background: var(--surface-alt); color: var(--text); }

.amount-due { color: var(--danger); font-weight: 700; }
.amount-paid { color: var(--success); }

.notes-cell { position: relative; min-width: 220px; }
.notes-input {
  width: 100%;
  padding: 6px 28px 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
  min-height: 32px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.notes-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}
.notes-input.dirty {
  border-color: #f59e0b;
  background: #fffbeb;
}
.notes-input.dirty:focus {
  box-shadow: 0 0 0 2px rgba(245,158,11,0.15);
}
.notes-input.saved {
  border-color: #10b981;
}

/* Save indicator inside notes cell */
.notes-status {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.notes-status.visible { opacity: 1; }
.notes-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
}
.notes-status .mini-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--info);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.notes-status .check {
  color: #10b981;
}
.notes-status .err {
  color: var(--danger);
}

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

.color-btn {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  position: relative;
  font-size: 0;
}
.color-btn::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 2px;
  background: var(--swatch-color, repeating-conic-gradient(#e5e7eb 0% 25%, white 0% 50%) 50% / 6px 6px);
}
.color-btn:hover { border-color: var(--text); }

.checkbox-wrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.checkbox-wrap input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}

