/* ============================================================
   FamilyHub v2.0 — Component Styles (components.css)
   Base styles for buttons, inputs, cards, chips, tabs, etc.
   ============================================================ */

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
  text-decoration: none;
  user-select: none;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

/* Primary */
.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.btn-primary:hover {
  background: #0a6b5e;
  border-color: #0a6b5e;
  box-shadow: var(--shadow-sm);
}
.btn-primary:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* Secondary */
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-surface-2);
  border-color: var(--color-text-muted);
}
.btn-secondary:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

/* Danger */
.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border-color: var(--color-danger);
}
.btn-danger:hover {
  background: var(--color-danger);
  color: #fff;
}

/* Icon-only button */
.btn-icon {
  padding: var(--space-2);
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

/* Button sizes */
.btn-xs { padding: var(--space-1) var(--space-2-5); font-size: var(--text-xs); }
.btn-sm { padding: var(--space-1-5) var(--space-3); font-size: var(--text-sm); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-md); }

/* ── Form Controls ───────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1-5);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.form-label.required::after {
  content: ' *';
  color: var(--color-danger);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: var(--space-2-5) var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  appearance: none;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--color-text-muted);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.input.error,
.select.error,
.textarea.error {
  border-color: var(--color-danger);
  box-shadow: var(--shadow-focus-danger);
}

.textarea {
  resize: vertical;
  min-height: 80px;
  line-height: var(--leading-relaxed);
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748B' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
  cursor: pointer;
}

/* ── Checkbox & Radio ────────────────────────────────────── */
.checkbox-group,
.radio-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.checkbox-group input[type="checkbox"],
.radio-group input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-accent);
  cursor: pointer;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-sm);
}

.card.interactive {
  cursor: pointer;
}

.card.interactive:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.card-body {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

/* ── Entity Chip ─────────────────────────────────────────── */
.entity-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entity-chip:hover {
  background: var(--color-surface-2);
  border-color: var(--color-text-muted);
}

.entity-chip-icon {
  font-size: 0.7rem;
  flex-shrink: 0;
}

/* ── Type Badge ──────────────────────────────────────────── */
.type-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fff;
  white-space: nowrap;
}

/* ── Tag Chip ────────────────────────────────────────────── */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 1px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

/* ── Priority Dot ────────────────────────────────────────── */
.priority-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.priority-dot.urgent  { background: var(--color-danger); }
.priority-dot.high    { background: var(--color-warning); }
.priority-dot.medium  { background: var(--color-info); }
.priority-dot.low     { background: var(--color-text-muted); }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: var(--space-2-5) var(--space-4);
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.tab:hover { color: var(--color-text); }
.tab.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

/* ── Divider ─────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-4) 0;
}

.divider-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: var(--space-4) 0;
}

.divider-label::before,
.divider-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* ── Status Badges ───────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

.status-badge.success { background: var(--color-success-bg); color: var(--color-success-text); }
.status-badge.warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.status-badge.danger  { background: var(--color-danger-bg);  color: var(--color-danger-text); }
.status-badge.info    { background: var(--color-info-bg);    color: var(--color-info-text); }
.status-badge.neutral { background: var(--color-surface-2);  color: var(--color-text-muted); }

/* ── Avatar ──────────────────────────────────────────────── */
.avatar {
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
  overflow: hidden;
}

.avatar-xs { width: 20px; height: 20px; font-size: 9px; }
.avatar-sm { width: 26px; height: 26px; font-size: 11px; }
.avatar-md { width: 32px; height: 32px; font-size: 13px; }
.avatar-lg { width: 40px; height: 40px; font-size: 16px; }
.avatar-xl { width: 56px; height: 56px; font-size: 22px; }

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Avatar Stack ────────────────────────────────────────── */
.avatar-stack {
  display: flex;
}

.avatar-stack .avatar {
  border: 2px solid var(--color-bg);
  margin-left: -6px;
}

.avatar-stack .avatar:first-child { margin-left: 0; }

/* ── Dropdown Menu ───────────────────────────────────────── */
.dropdown {
  position: relative;
  display: inline-flex;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  min-width: 180px;
  z-index: var(--z-dropdown);
  display: none;
  flex-direction: column;
  overflow: hidden;
  padding: var(--space-1) 0;
}

.dropdown-menu.open { display: flex; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  transition: background var(--transition-fast);
}

.dropdown-item:hover { background: var(--color-surface); }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-item.danger:hover { background: var(--color-danger-bg); }

.dropdown-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-1) 0;
}

/* ── Loading States ──────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface) 25%,
    var(--color-surface-2) 37%,
    var(--color-surface) 63%
  );
  background-size: 400px 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  from { background-position: -400px 0; }
  to   { background-position: 400px 0; }
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: var(--radius-full);
  animation: spin 0.75s linear infinite;
}

/* spin keyframe defined in layout.css */

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
  gap: var(--space-3);
}

.empty-state-icon {
  font-size: 2.5rem;
  opacity: 0.4;
}

.empty-state-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.empty-state-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 300px;
  line-height: var(--leading-relaxed);
}

/* ── Section Header ──────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  gap: var(--space-3);
}

.section-title {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  color: var(--color-text);
}

.section-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-0-5);
}

/* ── Collapsible Section ─────────────────────────────────── */
.collapsible {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: var(--space-3);
}

.collapsible-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  user-select: none;
  transition: background var(--transition-fast);
}

.collapsible-header:hover { background: var(--color-surface-2); }

.collapsible-chevron {
  margin-left: auto;
  transition: transform var(--transition-base);
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.collapsible.open .collapsible-chevron { transform: rotate(90deg); }

.collapsible-body {
  display: none;
  padding: var(--space-4);
  background: var(--color-bg);
}

.collapsible.open .collapsible-body { display: block; }

/* ── Filter Bar ──────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2-5);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.filter-pill:hover { border-color: var(--color-accent); color: var(--color-text); }
.filter-pill.active { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }

/* ── Tooltip ─────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-brand);
  color: #fff;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: var(--z-tooltip);
}

[data-tooltip]:hover::after { opacity: 1; }

/* ── Inline Edit Fields ──────────────────────────────────── */
.inline-edit {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 2px var(--space-1);
  min-width: 40px;
  transition: background var(--transition-fast);
}

.inline-edit:hover {
  background: var(--color-surface);
}

.inline-edit[contenteditable="true"] {
  background: var(--color-bg);
  border: 1px solid var(--color-accent);
  box-shadow: var(--shadow-focus);
  cursor: text;
  outline: none;
  padding: 2px var(--space-2);
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2xl);
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn var(--transition-slow) both;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  gap: var(--space-3);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  flex: 1;
}

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ── Spending Bar ────────────────────────────────────────── */
.spending-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.spending-bar-track {
  height: 6px;
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.spending-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  transition: width var(--transition-slow);
}

.spending-bar-fill.over-budget { background: var(--color-danger); }
.spending-bar-fill.warning     { background: var(--color-warning); }

/* ── Keyboard Shortcut Keys ──────────────────────────────── */
kbd {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  box-shadow: 0 1px 0 var(--color-border);
  line-height: 1.5;
}

/* ── Utility Classes ─────────────────────────────────────── */
.hidden       { display: none !important; }
.sr-only      { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.text-muted   { color: var(--color-text-muted); }
.text-accent  { color: var(--color-accent); }
.text-danger  { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-sm      { font-size: var(--text-sm); }
.text-xs      { font-size: var(--text-xs); }
.font-mono    { font-family: var(--font-mono); }
.font-heading { font-family: var(--font-heading); }
.truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.gap-2        { gap: var(--space-2); }
.gap-3        { gap: var(--space-3); }
.gap-4        { gap: var(--space-4); }
.mt-auto      { margin-top: auto; }
.ml-auto      { margin-left: auto; }
.w-full       { width: 100%; }
