/* ==========================================
   MaPaMe Design System — Elderly-Friendly
   "Well-lit living room" aesthetic
   ========================================== */

:root {
  /* Page backgrounds */
  --bg-page: #FFF8F0;
  --bg-card: #FFFFFF;
  --bg-card-hover: #FFF3E6;
  --bg-sidebar: #5D4037;
  --bg-sidebar-hover: #6D4C41;
  --bg-sidebar-active: #4E342E;
  --bg-input: #FFFFFF;
  --bg-input-focus: #FFFAF5;

  /* Accent / interactive */
  --accent: #D84315;
  --accent-hover: #BF360C;
  --accent-light: rgba(216, 67, 21, 0.08);
  --accent-dim: rgba(216, 67, 21, 0.12);

  /* Secondary */
  --secondary: #558B2F;
  --secondary-light: rgba(85, 139, 47, 0.1);

  /* Text — WCAG AAA on cream */
  --text-primary: #1A1A1A;
  --text-secondary: #4A3728;
  --text-muted: #6D5D4E;
  --text-on-sidebar: #EFEBE9;
  --text-on-sidebar-muted: #A1887F;
  --text-on-accent: #FFFFFF;

  /* Borders */
  --border: #D7CCC8;
  --border-hover: #BCAAA4;
  --border-focus: var(--accent);

  /* Relationship category colors */
  --cat-family: #E65100;
  --cat-family-bg: #FFF3E0;
  --cat-friend: #1565C0;
  --cat-friend-bg: #E3F2FD;
  --cat-professional: #2E7D32;
  --cat-professional-bg: #E8F5E9;
  --cat-community: #7B1FA2;
  --cat-community-bg: #F3E5F5;
  --cat-medical: #C62828;
  --cat-medical-bg: #FFEBEE;
  --cat-other: #546E7A;
  --cat-other-bg: #ECEFF1;

  /* Layout */
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.10);
  --sidebar-width: 260px;
}

/* ==========================================
   Base
   ========================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1 { font-size: 1.78rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.44rem; font-weight: 700; line-height: 1.3; }
h3 { font-size: 1.22rem; font-weight: 600; line-height: 1.3; }
h4 { font-size: 1.1rem; font-weight: 600; }

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ==========================================
   Layout — Sidebar + Main
   ========================================== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-layout.no-shell {
  display: block;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px 40px;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ==========================================
   Sidebar
   ========================================== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo-icon {
  font-size: 2rem;
  line-height: 1;
}

.sidebar-logo-text h1 {
  font-size: 1.33rem;
  color: #FFFFFF;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sidebar-logo-text span {
  font-size: 0.72rem;
  color: var(--text-on-sidebar-muted);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  color: var(--text-on-sidebar);
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  min-height: 56px;
  transition: background 0.15s;
}

.sidebar-nav a:hover {
  background: var(--bg-sidebar-hover);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--bg-sidebar-active);
  font-weight: 600;
  border-left: 4px solid var(--accent);
  padding-left: 20px;
}

.sidebar-nav a svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.83rem;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  color: var(--text-on-sidebar);
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  color: var(--text-on-sidebar-muted);
  font-size: 0.72rem;
  text-transform: capitalize;
}

.sidebar-logout {
  background: none;
  border: none;
  color: var(--text-on-sidebar-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.sidebar-logout:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}

/* ==========================================
   Buttons — 56px min touch target
   ========================================== */
.btn {
  min-height: 56px;
  min-width: 56px;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
  transition: all 0.15s ease;
  line-height: 1.2;
}

.btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}

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

.btn-danger {
  background: #C62828;
  color: #fff;
  border-color: #C62828;
}

.btn-danger:hover {
  background: #B71C1C;
  border-color: #B71C1C;
}

.btn-success {
  background: var(--secondary);
  color: #fff;
  border-color: var(--secondary);
}

.btn-success:hover {
  background: #33691E;
  border-color: #33691E;
}

.btn-sm {
  min-height: 44px;
  padding: 10px 20px;
  font-size: 0.88rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-icon {
  padding: 12px;
  min-width: 48px;
  min-height: 48px;
}

/* ==========================================
   Form inputs — Large, accessible
   ========================================== */
label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  min-height: 52px;
  padding: 14px 18px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--accent-light);
  background: var(--bg-input-focus);
  outline: none;
}

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

textarea {
  min-height: 120px;
  resize: vertical;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236D5D4E' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 44px;
}

.field-group {
  margin-bottom: 20px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ==========================================
   Cards
   ========================================== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-hover {
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
  cursor: pointer;
}

.card-hover:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

/* ==========================================
   Badges
   ========================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-family { background: var(--cat-family-bg); color: var(--cat-family); }
.badge-friend { background: var(--cat-friend-bg); color: var(--cat-friend); }
.badge-professional { background: var(--cat-professional-bg); color: var(--cat-professional); }
.badge-community { background: var(--cat-community-bg); color: var(--cat-community); }
.badge-medical { background: var(--cat-medical-bg); color: var(--cat-medical); }
.badge-other { background: var(--cat-other-bg); color: var(--cat-other); }

/* ==========================================
   Loading / Spinner
   ========================================== */
.loading-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 16px;
  color: var(--text-muted);
  font-size: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-sm {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  padding: 24px;
}

.loading-sm .spinner {
  width: 24px;
  height: 24px;
  border-width: 3px;
}

/* ==========================================
   Toast notifications
   ========================================== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 16px 24px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  animation: toastIn 0.3s ease;
}

.toast.success {
  background: #2E7D32;
  color: #fff;
}

.toast.error {
  background: #C62828;
  color: #fff;
}

.toast.info {
  background: var(--bg-sidebar);
  color: #fff;
}

@keyframes toastIn {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==========================================
   Modal
   ========================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.2s ease;
}

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

.modal-header h3 {
  font-size: 1.22rem;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  line-height: 1;
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ==========================================
   Confirm dialog (extra-large buttons)
   ========================================== */
.confirm-body {
  text-align: center;
  padding: 16px 0;
}

.confirm-body p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.confirm-body .confirm-detail {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.confirm-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  padding-top: 24px;
}

.confirm-actions .btn {
  min-width: 160px;
  min-height: 60px;
  font-size: 1.1rem;
}

/* ==========================================
   Login page
   ========================================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #FFF8F0 0%, #FFE0B2 50%, #FFCC80 100%);
  position: relative;
  overflow: hidden;
}

.login-accent {
  position: absolute;
  top: -30%;
  right: -10%;
  width: 60%;
  height: 130%;
  background: var(--bg-sidebar);
  border-radius: 50% 0 0 50%;
  opacity: 0.06;
  transform: rotate(-15deg);
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 440px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.login-logo {
  margin-bottom: 16px;
}

.login-logo-icon {
  font-size: 3.5rem;
  line-height: 1;
}

.login-card h1 {
  font-size: 2rem;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-weight: 800;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 32px;
}

.login-card .field-group {
  text-align: left;
}

.login-card .btn {
  width: 100%;
  min-height: 60px;
  font-size: 1.1rem;
  margin-top: 8px;
}

.login-error {
  background: #FFEBEE;
  color: #C62828;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 0.94rem;
  font-weight: 500;
  margin-bottom: 20px;
  display: none;
  text-align: left;
}

.login-error.visible {
  display: block;
}

.login-footer {
  margin-top: 28px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ==========================================
   Home dashboard
   ========================================== */
.home-header {
  margin-bottom: 32px;
}

.home-header h1 {
  margin-bottom: 4px;
}

.home-header p {
  color: var(--text-muted);
  font-size: 1.05rem;
}

.home-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 40px;
}

.home-entry-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.home-entry-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
  background: var(--bg-card-hover);
}

.home-entry-card .entry-icon {
  font-size: 3rem;
  line-height: 1;
}

.home-entry-card h2 {
  color: var(--text-primary);
  margin: 0;
}

.home-entry-card p {
  color: var(--text-muted);
  font-size: 0.94rem;
  max-width: 200px;
}

.home-stats {
  display: flex;
  gap: 24px;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

.home-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 28px;
  min-width: 140px;
}

.home-stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}

.home-stat-label {
  font-size: 0.83rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 4px;
}

.home-activity {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}

.home-activity h3 {
  margin-bottom: 16px;
}

.activity-list {
  list-style: none;
}

.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.94rem;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.activity-time {
  color: var(--text-muted);
  font-size: 0.83rem;
  margin-left: auto;
  white-space: nowrap;
}

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

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1.05rem;
  margin-bottom: 20px;
}

/* ==========================================
   People grid
   ========================================== */
.people-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.people-search {
  flex: 1;
  max-width: 400px;
}

.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

/* Person card component */
.person-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.person-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.person-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
}

.person-avatar-placeholder {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.5rem;
  color: #fff;
  flex-shrink: 0;
}

.person-card-name {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.person-card-nickname {
  color: var(--text-muted);
  font-size: 0.83rem;
  font-style: italic;
}

.person-card-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ==========================================
   Map view
   ========================================== */
.map-container {
  position: relative;
  height: calc(100vh - 96px);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.map-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  pointer-events: none;
}

.map-toolbar > * {
  pointer-events: auto;
}

.map-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.map-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  background: rgba(255,248,240,0.95);
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.2s;
}

.legend-item.dimmed {
  opacity: 0.3;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

#graphCanvas {
  width: 100%;
  height: 100%;
}

/* ==========================================
   Page header with back button
   ========================================== */
.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.back-btn {
  min-width: 48px;
  min-height: 48px;
  padding: 12px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.back-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.back-btn svg {
  width: 24px;
  height: 24px;
  stroke: var(--text-primary);
}

/* ==========================================
   Responsive — Tablet
   ========================================== */
@media (max-width: 900px) {
  .home-cards {
    grid-template-columns: 1fr;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 72px;
  }

  .sidebar-logo-text,
  .sidebar-nav a span,
  .sidebar-user-info {
    display: none;
  }

  .sidebar-logo {
    justify-content: center;
    padding: 20px 12px;
  }

  .sidebar-nav a {
    justify-content: center;
    padding: 16px;
  }

  .sidebar-nav a.active {
    padding-left: 12px;
    border-left-width: 3px;
  }

  .sidebar-user {
    justify-content: center;
    padding: 12px;
  }

  .sidebar-logout {
    display: none;
  }

  .main-content {
    padding: 20px 16px;
  }

  .people-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .login-card {
    padding: 32px 24px;
    margin: 16px;
  }
}

@media (max-width: 480px) {
  :root {
    --sidebar-width: 0px;
  }

  .sidebar {
    display: none;
  }

  .main-content {
    margin-left: 0;
    padding: 16px 12px;
  }
}
