/* ===== 诊间账 - 诊所利润工作台 v1 ===== */
:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --transition: .2s ease;
}

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

html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Layout ===== */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}
.app-header h1 { font-size: 1.25rem; font-weight: 600; letter-spacing: .5px; }
.app-header .header-actions { display: flex; gap: 8px; align-items: center; }

.nav-tabs {
  background: #fff;
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: sticky;
  top: 56px;
  z-index: 99;
}
.nav-tab {
  padding: 12px 20px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.nav-tab:hover { color: var(--primary); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-content { display: none; padding: 20px; max-width: 1200px; margin: 0 auto; }
.tab-content.active { display: block; }

/* ===== Cards ===== */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== KPI Row ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}
.kpi-card .kpi-label { font-size: .85rem; color: var(--gray-500); margin-bottom: 4px; }
.kpi-card .kpi-value { font-size: 1.5rem; font-weight: 700; }
.kpi-card .kpi-compare { font-size: .8rem; margin-top: 4px; }
.kpi-compare.up { color: var(--success); }
.kpi-compare.down { color: var(--danger); }
.kpi-compare.neutral { color: var(--gray-400); }
.kpi-value.profit-positive { color: var(--success); }
.kpi-value.profit-negative { color: var(--danger); }

/* ===== Charts ===== */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.chart-container { position: relative; min-height: 260px; }

/* ===== Alert box ===== */
.alert-box {
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
  font-size: .9rem;
  line-height: 1.6;
  display: none;
}
.alert-box.danger {
  background: var(--danger-light);
  border-left: 4px solid var(--danger);
  color: #991b1b;
  display: block;
}
.alert-box.safe {
  background: var(--success-light);
  border-left: 4px solid var(--success);
  color: #166534;
  display: block;
}

/* ===== Forms ===== */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.form-group label { font-size: .8rem; color: var(--gray-500); font-weight: 500; }
input, select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9rem;
  outline: none;
  transition: var(--transition);
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline {
  background: #fff;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-header {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
  padding: 6px 12px;
  font-size: .8rem;
}
.btn-header:hover { background: rgba(255,255,255,.25); }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
  background: var(--gray-50);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  white-space: nowrap;
}
tbody tr:hover { background: var(--gray-50); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--gray-400);
  font-size: .85rem;
}
.action-btn:hover { color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--gray-400);
  padding: 40px 20px;
  font-size: .9rem;
}

/* ===== Sample data badge ===== */
.sample-badge {
  display: none;
  background: var(--warning);
  color: #fff;
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  margin-left: 8px;
}
.sample-badge.visible { display: inline-block; }

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  justify-content: center;
  align-items: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ===== Category tags ===== */
.cat-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.cat-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--gray-100);
  border-radius: 16px;
  font-size: .8rem;
  cursor: pointer;
}
.cat-tag .cat-del {
  cursor: pointer;
  color: var(--gray-400);
  font-weight: 700;
  margin-left: 2px;
}
.cat-tag .cat-del:hover { color: var(--danger); }

/* ===== Import mapping ===== */
.mapping-row { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.mapping-row .label { min-width: 120px; font-weight: 500; font-size: .85rem; }
.mapping-row select { flex: 1; }

/* ===== Report Page ===== */
.report-header { text-align: center; margin-bottom: 24px; }
.report-header h2 { font-size: 1.3rem; margin-bottom: 4px; }
.report-header p { color: var(--gray-500); font-size: .85rem; }
.report-section { margin-bottom: 20px; }
.report-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 8px; border-bottom: 1px solid var(--gray-200); padding-bottom: 4px; }
.report-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.report-summary-item {
  text-align: center;
  padding: 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
}
.report-summary-item .label { font-size: .8rem; color: var(--gray-500); }
.report-summary-item .value { font-size: 1.2rem; font-weight: 700; margin-top: 2px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  html { font-size: 13px; }
  .app-header { padding: 0 12px; }
  .tab-content { padding: 12px; }
  .chart-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-group { min-width: 100%; }
  .report-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .nav-tab { padding: 10px 14px; font-size: .8rem; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .header-actions { flex-wrap: wrap; }
}

/* ===== Print ===== */
@media print {
  body { background: #fff; }
  .app-header, .nav-tabs, .no-print { display: none !important; }
  .tab-content { display: none !important; }
  .tab-content#tab-report { display: block !important; padding: 0; max-width: 100%; }
  .card { box-shadow: none; border: 1px solid var(--gray-200); break-inside: avoid; }
  .kpi-card { box-shadow: none; border: 1px solid var(--gray-200); }
  .report-summary-item { border: 1px solid var(--gray-200); }
  .chart-container canvas { max-height: 200px; }
  @page { margin: 15mm; }
}
