:root {
  --bg: #f4faf7;
  --bg-card: #ffffff;
  --text: #1e332a;
  --text-light: #4a6d5a;
  --text-muted: #7f9e8e;
  --border: #cde0d4;
  --border-light: #e5f0ea;
  --primary: #36B37E;
  --primary-dark: #2D9A6C;
  --primary-light: #57C896;
  --primary-bg: #d8f0e5;
  --primary-bg-light: #eaf7f0;
  --accent: #248B5E;
  --danger: #EF4444;
  --danger-bg: #FEF2F2;
  --warning: #F59E0B;
  --warning-bg: #FFFBEB;
  --success: #10B981;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(72,199,142,0.08);
  --shadow-md: 0 4px 12px rgba(72,199,142,0.1);
  --shadow-lg: 0 8px 24px rgba(72,199,142,0.12);
  --fs-hero: 1.8rem;
  --fs-h1: 1.5rem;
  --fs-h2: 1.25rem;
  --fs-h3: 1.1rem;
  --fs-body: 0.95rem;
  --fs-secondary: 0.88rem;
  --fs-caption: 0.82rem;
  --fs-micro: 0.72rem;
  --nav-height: 56px;
  --bottom-nav-height: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: var(--fs-body);
  min-height: 100vh;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navbar (Desktop top) ===== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  height: var(--nav-height);
  display: flex;
  align-items: center;
  padding: 0 24px;
  max-width: 100%;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary-dark);
  text-decoration: none;
  flex-shrink: 0;
}

.navbar-brand img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 32px;
  list-style: none;
}

.navbar-nav a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-light);
  font-size: var(--fs-secondary);
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
}

.navbar-nav a:hover { background: var(--primary-bg-light); color: var(--primary-dark); }
.navbar-nav a.active { background: var(--primary-bg); color: var(--primary-dark); font-weight: 600; }

.navbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-secondary);
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.navbar-user:hover { background: var(--primary-bg-light); }

/* ===== Bottom Nav (Mobile) ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-light);
  height: var(--bottom-nav-height);
  display: none; /* hidden by default, shown on mobile */
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  padding: 6px 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--fs-micro);
  font-weight: 500;
  transition: color 0.2s;
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.bottom-nav-icon svg {
  width: 22px;
  height: 22px;
}

.bottom-nav-label {
  font-size: 0.68rem;
}

/* body padding for bottom nav */
body.has-bottom-nav .main-content {
  padding-bottom: calc(60px + var(--bottom-nav-height));
}

/* ===== Layout ===== */
.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: var(--fs-h1);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-muted);
  font-size: var(--fs-secondary);
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h2 {
  font-size: var(--fs-h3);
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header h2 svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card .stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.stat-card .stat-icon svg { width: 20px; height: 20px; color: white; }

.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.stat-card .stat-label {
  font-size: var(--fs-caption);
  color: var(--text-muted);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-secondary);
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  line-height: 1.4;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }

.btn-secondary { background: var(--primary-bg); color: var(--primary-dark); }
.btn-secondary:hover { background: var(--border); text-decoration: none; }

.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #FEE2E2; text-decoration: none; }

.btn-sm { padding: 5px 12px; font-size: var(--fs-caption); }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Forms ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: var(--fs-secondary);
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-body);
  color: var(--text);
  background: var(--bg-card);
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.form-group textarea { min-height: 80px; resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 16px;
}

/* ===== Table ===== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 12px 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  font-size: var(--fs-secondary);
}

.data-table th {
  background: var(--primary-bg-light);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-light);
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}

.data-table tr:hover td { background: var(--primary-bg-light); }
.data-table tr:last-child td { border-bottom: none; }

/* ===== Tags/Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: var(--fs-micro);
  font-weight: 500;
}

.badge-green { background: var(--primary-bg); color: var(--primary-dark); }
.badge-yellow { background: var(--warning-bg); color: #92400E; }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-gray { background: #f3f4f6; color: #6b7280; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
  font-size: var(--fs-h3);
  font-weight: 600;
}

.modal-body { padding: 24px; overflow-x: hidden; }

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

/* ===== Auth Pages ===== */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 50%, #bbf7d0 100%);
}

.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo img {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin-bottom: 12px;
}

.auth-logo h1 {
  font-size: var(--fs-h1);
  color: var(--primary-dark);
}

.auth-logo p {
  color: var(--text-muted);
  font-size: var(--fs-secondary);
  margin-top: 4px;
}

.auth-card .form-group input {
  padding: 12px 16px;
  font-size: var(--fs-body);
}

.auth-card .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: var(--fs-body);
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: var(--fs-secondary);
  color: var(--text-muted);
}

.auth-footer a { color: var(--primary-dark); font-weight: 500; }

/* ===== Login/Register Tabs ===== */
.auth-tabs {
  display: flex;
  border-bottom: 2px solid var(--border-light);
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  text-align: center;
  padding: 12px;
  font-weight: 600;
  font-size: var(--fs-secondary);
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.auth-tab.active {
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
}

/* ===== Visit Cards ===== */
.visit-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.visit-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary-bg);
}

.visit-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.visit-card-date {
  font-size: var(--fs-caption);
  color: var(--text-muted);
}

.visit-card-member {
  font-size: var(--fs-micro);
  background: var(--primary-bg);
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 10px;
}

.visit-card-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  font-size: var(--fs-body);
}

.visit-card-meta {
  font-size: var(--fs-caption);
  color: var(--text-light);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.visit-card-cost {
  margin-top: 8px;
  font-size: var(--fs-secondary);
  font-weight: 600;
  color: var(--primary-dark);
}

.visit-detail {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.visit-detail-section {
  margin-bottom: 12px;
}

.visit-detail-section h4 {
  font-size: var(--fs-caption);
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.visit-detail-section p {
  font-size: var(--fs-secondary);
  color: var(--text-light);
}

/* ===== Member Pills ===== */
.member-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0;
  margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.member-filter::-webkit-scrollbar { display: none; }

.member-pill {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: var(--fs-secondary);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-light);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.member-pill:hover { border-color: var(--primary); color: var(--primary-dark); }
.member-pill.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== Med Card in Visit Modal ===== */
.med-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
}
.med-del {
  position: absolute;
  top: 6px;
  right: 6px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  z-index: 1;
}
.med-name {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: var(--fs-body);
  font-weight: 500;
  margin-bottom: 8px;
  display: block;
}
.med-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 0;
}
.med-fields + .med-fields { margin-top: 6px; }
.med-fields input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: var(--fs-caption);
  width: 100%;
  min-width: 0;
}

/* ===== Cost Breakdown ===== */
.cost-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.cost-item {
  text-align: center;
  padding: 8px;
  background: var(--primary-bg-light);
  border-radius: var(--radius-sm);
}

.cost-item .cost-label {
  font-size: var(--fs-micro);
  color: var(--text-muted);
  margin-bottom: 2px;
}

.cost-item .cost-value {
  font-size: var(--fs-secondary);
  font-weight: 600;
  color: var(--text);
}

/* ===== FAB (Floating Action Button) ===== */
.fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: all 0.2s;
}

.fab:hover { background: var(--primary-dark); transform: scale(1.05); }
.fab svg { width: 24px; height: 24px; }

/* ===== Image Grid ===== */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.image-grid img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: transform 0.2s;
}

.image-grid img:hover { transform: scale(1.03); }

/* ===== Upload Area ===== */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
  margin-top: 12px;
}

.upload-area:hover {
  border-color: var(--primary);
  background: var(--primary-bg-light);
}

.upload-area svg {
  width: 32px;
  height: 32px;
  margin-bottom: 8px;
  color: var(--primary-light);
}

.upload-area p {
  font-size: var(--fs-secondary);
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.pagination button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-light);
  font-size: var(--fs-caption);
  cursor: pointer;
  transition: all 0.2s;
}

.pagination button:hover { border-color: var(--primary); color: var(--primary-dark); }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 300;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-secondary);
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
}

.toast-success { background: var(--primary-bg); color: var(--primary-dark); border: 1px solid var(--primary); }
.toast-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.toast-info { background: #EFF6FF; color: #1D4ED8; border: 1px solid #3B82F6; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== Chart ===== */
.chart-container {
  width: 100%;
  min-height: 300px;
  position: relative;
}

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

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  color: var(--border);
}

.empty-state h3 {
  font-size: var(--fs-h3);
  color: var(--text-light);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: var(--fs-secondary);
  margin-bottom: 20px;
}

/* ===== Dropdown ===== */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 150;
  padding: 6px;
  display: none;
}

.dropdown-menu.show { display: block; }

.dropdown-menu a,
.dropdown-menu button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  text-align: left;
  font-size: var(--fs-secondary);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
}

.dropdown-menu a:hover,
.dropdown-menu button:hover {
  background: var(--primary-bg-light);
  color: var(--primary-dark);
}

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

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

/* ===== Search ===== */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.search-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-secondary);
  background: var(--bg-card);
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-light);
  overflow-x: auto;
}

.tab {
  padding: 10px 18px;
  font-size: var(--fs-secondary);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab:hover { color: var(--primary-dark); }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 600; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .navbar { padding: 0 16px; }
  .navbar .desktop-nav { display: none; }
  .navbar-brand-text { font-size: 1rem; }
  .navbar-brand img { width: 28px; height: 28px; }
  .mobile-nav-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: var(--fs-h3);
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
  }

  .bottom-nav { display: flex; }

  .main-content { padding: 16px 12px 40px; }
  body.has-bottom-nav .main-content { padding-bottom: calc(40px + var(--bottom-nav-height)); }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 16px 12px; }
  .stat-card .stat-value { font-size: 1.3rem; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-height: 92vh; max-width: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-body { padding: 16px; }
  .modal-header { padding: 16px; }
  .modal-footer { padding: 12px 16px; }
  .auth-card { padding: 24px; }
  .form-row { grid-template-columns: 1fr; }

  .fab {
    bottom: calc(var(--bottom-nav-height) + 20px);
  }
}

@media (min-width: 769px) {
  .bottom-nav { display: none !important; }
}
