/* ===== CSS VARIABLES ===== */
:root {
  --bg: #f4f1ec;
  --bg-2: #ede9e1;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --border: #e0dbd2;
  --border-2: #cdc8be;
  --text-primary: #1a1714;
  --text-secondary: #6b6560;
  --text-muted: #9b958d;
  --accent: #b85c38;
  --accent-light: #f5e8e2;
  --accent-dark: #8f3f22;
  --urgent: #c0392b;
  --urgent-light: #fdecea;
  --success: #27ae60;
  --success-light: #eafaf1;
  --warning: #e67e22;
  --info: #2980b9;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.12), 0 8px 24px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --font-display: 'Fraunces', serif;
  --font-body: 'DM Sans', sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-icon {
  width: 44px;
  height: 44px;
  background: var(--accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}
.brand-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  letter-spacing: -0.3px;
}
.brand-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  display: block;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}
.record-count {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ===== BUTTONS ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(184,92,56,0.35); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.btn-secondary:hover { background: var(--bg-2); color: var(--text-primary); }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--urgent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.btn-danger:hover { background: #a93226; transform: translateY(-1px); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  background: transparent;
}
.btn-icon.edit { color: var(--info); }
.btn-icon.edit:hover { background: #eaf4fb; }
.btn-icon.delete { color: var(--urgent); }
.btn-icon.delete:hover { background: var(--urgent-light); }

/* ===== MAIN ===== */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ===== STATS BAR ===== */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-sm); }
.stat-value {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
}
.stat-value.urgent { color: var(--urgent); }
.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* ===== FILTERS ===== */
.filters-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  height: 42px;
  padding: 0 12px 0 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(184,92,56,0.1); }
.filter-select {
  height: 42px;
  padding: 0 36px 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6560' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: var(--transition);
}
.filter-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(184,92,56,0.1); }

/* ===== RECORDS GRID ===== */
.records-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: var(--transition);
  animation: cardIn 0.35s ease both;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--border);
  transition: var(--transition);
}
.card.urgent-card::before { background: var(--urgent); }
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card:hover::before { background: var(--accent); }
.card.urgent-card:hover::before { background: var(--urgent); }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}
.card-avatar.boy { background: #e8f4fd; color: #2980b9; }
.card-avatar.girl { background: #fde8f5; color: #8e44ad; }
.card-info { flex: 1; min-width: 0; }
.card-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
}
.badge-age { background: var(--bg-2); color: var(--text-secondary); }
.badge-gender-m { background: #e8f4fd; color: #2471a3; }
.badge-gender-f { background: #fde8f5; color: #7d3c98; }
.badge-gender-o { background: var(--bg-2); color: var(--text-secondary); }
.badge-urgent { background: var(--urgent-light); color: var(--urgent); font-weight: 600; }

.card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.card-body { display: flex; flex-direction: column; gap: 10px; }
.card-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
}
.card-row-icon {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 2px;
}
.card-row-label {
  color: var(--text-muted);
  min-width: 80px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
  padding-top: 1px;
}
.card-row-value {
  color: var(--text-primary);
  flex: 1;
  word-break: break-word;
}
.card-description {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== LOADING STATE ===== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  gap: 20px;
  color: var(--text-muted);
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== EMPTY STATE ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  gap: 16px;
  text-align: center;
}
.empty-icon {
  width: 80px;
  height: 80px;
  background: var(--surface);
  border: 2px dashed var(--border-2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}
.empty-state p {
  color: var(--text-muted);
  max-width: 300px;
  font-size: 14px;
}

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20,16,13,0.6);
  backdrop-filter: blur(6px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 32px 0;
  margin-bottom: 24px;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}
.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg-2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
}
.modal-close:hover { background: var(--border); color: var(--text-primary); }

/* ===== FORM ===== */
.modal-form { padding: 0 32px 32px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 24px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}
.required { color: var(--urgent); }
.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
  appearance: none;
}
.form-input:focus { border-color: var(--accent); background: white; box-shadow: 0 0 0 3px rgba(184,92,56,0.1); }
.form-input.invalid { border-color: var(--urgent); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-error {
  font-size: 12px;
  color: var(--urgent);
  display: none;
}
.form-error.visible { display: block; }

/* ===== CHECKBOX ===== */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.checkbox-label:hover { border-color: var(--accent); background: var(--accent-light); }
.checkbox-input { position: absolute; opacity: 0; width: 0; height: 0; }
.checkbox-custom {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-2);
  border-radius: 5px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  background: white;
}
.checkbox-input:checked + .checkbox-custom {
  background: var(--urgent);
  border-color: var(--urgent);
}
.checkbox-input:checked + .checkbox-custom::after {
  content: '';
  width: 5px;
  height: 9px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
  display: block;
}
.checkbox-text { font-size: 14px; color: var(--text-primary); }

/* ===== MODAL FOOTER ===== */
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ===== CONFIRM DIALOG ===== */
.confirm-dialog {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.confirm-icon {
  width: 64px;
  height: 64px;
  background: var(--urgent-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--urgent);
  margin: 0 auto 20px;
}
.confirm-dialog h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-primary);
}
.confirm-dialog p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 28px;
}
.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--text-primary);
  color: white;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 400;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
}
.toast.success { background: #1e4d35; border-left: 3px solid var(--success); }
.toast.error { background: #4d1e1e; border-left: 3px solid var(--urgent); }
.toast.info { background: #1e2d4d; border-left: 3px solid var(--info); }
.toast-icon { flex-shrink: 0; }
.toast-out { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(40px) scale(0.95); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .header-inner { padding: 0 16px; }
  .main { padding: 20px 16px 48px; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full-width { grid-column: 1; }
  .modal-header { padding: 20px 20px 0; }
  .modal-form { padding: 0 20px 20px; }
  .records-grid { grid-template-columns: 1fr; }
  .record-count { display: none; }
  .brand-sub { display: none; }
  #toast-container { left: 16px; right: 16px; max-width: none; bottom: 16px; }
}
@media (max-width: 480px) {
  .stats-bar { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 26px; }
  .filters-row { gap: 8px; }
  .filter-select { flex: 1; }
  .confirm-actions { flex-direction: column; }
  .confirm-actions button { width: 100%; justify-content: center; }
}
