/* ============================================================
   外贸CRM - 样式表
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #ea580c;
  --warning-light: #fff7ed;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --sidebar-width: 200px;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ============================================================
   Layout
   ============================================================ */
#app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.logo {
  padding: 20px 16px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}

.nav-links {
  list-style: none;
  padding: 8px;
  flex: 1;
}

.nav-links li { margin: 2px 0; }

.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s;
}

.nav-links a:hover { background: var(--primary-light); color: var(--primary); }
.nav-links a.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-links .icon { font-size: 18px; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  text-align: center;
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px;
  max-width: calc(100vw - var(--sidebar-width));
}

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

.stat-card {
  background: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.stat-value.blue { color: var(--primary); }
.stat-value.green { color: var(--success); }
.stat-value.orange { color: var(--warning); }
.stat-value.red { color: var(--danger); }

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

.dashboard-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.dashboard-card.full { grid-column: 1 / -1; }

.dashboard-card h3 {
  font-size: 15px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ============================================================
   Toolbar
   ============================================================ */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
}

.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: #fff;
  outline: none;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.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; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Chart containers */
canvas { max-width: 100%; }

/* Pagination */
.pagination {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 0; justify-content: center; flex-wrap: wrap;
}
.pagination .page-info {
  font-size: 12px; color: var(--text-secondary); margin-left: 8px; white-space: nowrap;
}
.pagination .btn-sm:disabled { opacity: 0.4; cursor: default; }

/* Followup timeline (grouped by customer) */
.fu-grouped-list { display: flex; flex-direction: column; gap: 12px; }
.fu-customer-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.fu-customer-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: #f8fafc; cursor: pointer;
  border-bottom: 1px solid var(--border); user-select: none;
}
.fu-customer-header:hover { background: #f1f5f9; }
.fu-cust-info { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fu-meta { font-size: 12px; color: var(--text-secondary); }
.fu-toggle { font-size: 12px; color: var(--text-secondary); transition: transform 0.2s; }
.fu-customer-card.collapsed .fu-timeline { display: none; }
.fu-customer-card.collapsed .fu-toggle { transform: rotate(-90deg); }

.fu-timeline { padding: 8px 16px; }
.fu-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid #f1f5f9;
  position: relative;
}
.fu-item:last-child { border-bottom: none; }
.fu-date {
  min-width: 85px; font-size: 12px; color: var(--text-secondary);
  padding-top: 2px; white-space: nowrap;
}
.fu-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  margin-top: 7px; flex-shrink: 0;
}
.fu-body { flex: 1; min-width: 0; }
.fu-content { font-size: 14px; line-height: 1.5; word-break: break-word; }
.fu-details { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.fu-tag {
  font-size: 11px; padding: 1px 7px;
  background: var(--primary-light); color: var(--primary);
  border-radius: 10px; white-space: nowrap;
}
.fu-tag.remind { background: var(--warning-light); color: var(--warning); }
.fu-note { font-size: 12px; color: var(--text-secondary); }
.fu-actions {
  display: flex; gap: 4px; flex-shrink: 0; padding-top: 1px;
}
.fu-card-pagination {
  border-top: 1px solid var(--border); background: #fafafa;
}

/* Tax rebate file rows */
.tax-upload-area { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tax-file-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid #f1f5f9;
}
.tax-file-row:last-child { border-bottom: none; }
.tax-file-row:hover { background: #fafbfc; }
.tax-file-type { min-width: 120px; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.tax-file-names { flex: 1; font-size: 13px; min-width: 150px; }
.tax-file-names a { margin-right: 8px; white-space: nowrap; }
.tax-no-file { color: var(--text-secondary); }
.tax-upload-form { flex-shrink: 0; }

/* Contact cards in customer detail */
.contacts-list { display: flex; flex-direction: column; gap: 8px; }
.contact-card {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; background: #f8fafc; border: 1px solid var(--border);
  border-radius: var(--radius);
}
.contact-main { display: flex; align-items: center; gap: 6px; min-width: 120px; }
.contact-pos { font-size: 12px; color: var(--text-secondary); }
.contact-details { display: flex; gap: 12px; flex-wrap: wrap; flex: 1;
  font-size: 13px; color: var(--text-secondary); }
.contact-details span { white-space: nowrap; }
.contact-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Year filter in header */
.page-header select.filter-select { min-width: 130px; }

/* ============================================================
   Table
   ============================================================ */
.table-container {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

tr:hover td { background: #f8fafc; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--primary-light); }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-a { background: #fef3c7; color: #92400e; }
.badge-b { background: #dbeafe; color: #1e40af; }
.badge-c { background: #dcfce7; color: #166534; }
.badge-d { background: #f3e8ff; color: #6b21a8; }
.badge-e { background: #fee2e2; color: #991b1b; }

.badge-status { background: #dbeafe; color: #1e40af; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-pending { background: #fef3c7; color: #92400e; }

/* ============================================================
   Customer detail
   ============================================================ */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.detail-back {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
  margin-bottom: 20px;
  background: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.detail-grid .field { margin-bottom: 4px; }
.detail-grid .field-label { font-size: 12px; color: var(--text-secondary); }
.detail-grid .field-value { font-size: 14px; }

.detail-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
}

.detail-tab {
  padding: 8px 20px;
  border: 1px solid var(--border);
  background: #f8fafc;
  cursor: pointer;
  font-size: 13px;
  border-radius: 0;
}

.detail-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.detail-tab:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.detail-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============================================================
   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;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
}

.modal-header h3 { font-size: 16px; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0 4px;
  line-height: 1;
}

.modal-body { padding: 20px; }

.form-group { margin-bottom: 14px; }

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

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Mini list (within detail view)
   ============================================================ */
.mini-list {
  list-style: none;
}

.mini-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.mini-list li:last-child { border-bottom: none; }

.mini-list .mini-date {
  color: var(--text-secondary);
  font-size: 12px;
  margin-right: 8px;
  white-space: nowrap;
}

/* ============================================================
   Empty state
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* ============================================================
   Reminder banner
   ============================================================ */
.reminder-item {
  padding: 8px 12px;
  border-left: 3px solid var(--warning);
  margin-bottom: 8px;
  background: var(--warning-light);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 13px;
}

/* ============================================================
   Page header
   ============================================================ */
.page-header {
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: 22px;
  margin-bottom: 4px;
}

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

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    overflow: hidden;
  }
  .sidebar .logo { font-size: 0; padding: 16px 8px; text-align: center; }
  .sidebar .logo::before { content: '🌍'; font-size: 20px; }
  .nav-links a { padding: 12px 8px; justify-content: center; }
  .nav-links a span:not(.icon) { display: none; }
  .nav-links .icon { font-size: 20px; margin: 0; }
  .sidebar-footer { display: none; }
  :root { --sidebar-width: 60px; }
  .main-content { padding: 16px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
