/* ============================================================
   车险客户管理系统 — 移动端优先样式表
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text2: #64748b;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warn: #d97706;
  --warn-light: #fffbeb;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.08);
  --nav-h: 56px;
  --bottom-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
               "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--bottom-h) + var(--safe-bottom) + 8px);
}

a { color: var(--primary); text-decoration: none; }
a:active { opacity: .7; }
img { max-width: 100%; }
h2 { font-size: 18px; font-weight: 700; margin: 0; }

/* ============================================================
   TOP HEADER BAR
   ============================================================ */
.top {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #fff;
  padding: 0 16px;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.top > div:first-child {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}
/* Desktop nav links inside .top */
.top > div:last-child { display: none; }
.top > div:last-child a {
  color: rgba(255,255,255,.85);
  margin-left: 16px;
  font-size: 14px;
  white-space: nowrap;
  transition: color .15s;
}
.top > div:last-child a:hover { color: #fff; }

/* Hamburger button (mobile only) */
.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.hamburger span,
.hamburger span::before,
.hamburger span::after {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: .25s ease;
  position: relative;
}
.hamburger span::before,
.hamburger span::after { content: ''; position: absolute; left: 0; }
.hamburger span::before { top: -7px; }
.hamburger span::after  { top: 7px; }
/* Animated open state */
.hamburger.open span { background: transparent; }
.hamburger.open span::before { transform: rotate(45deg); top: 0; }
.hamburger.open span::after  { transform: rotate(-45deg); top: 0; }

/* ============================================================
   SIDE DRAWER (Mobile)
   ============================================================ */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  opacity: 0;
  transition: opacity .25s;
}
.drawer-overlay.show { display: block; opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100%;
  background: #fff;
  z-index: 201;
  transform: translateX(-100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 4px 0 20px rgba(0,0,0,.1);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  padding: 20px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #fff;
}
.drawer-header h3 { font-size: 18px; font-weight: 700; }
.drawer-header p { font-size: 13px; opacity: .7; margin-top: 4px; }

.drawer-nav { padding: 8px 0; }
.drawer-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  color: var(--text);
  font-size: 15px;
  border-bottom: 1px solid var(--border-light);
  transition: background .15s;
  min-height: 48px;
}
.drawer-nav a:active { background: var(--primary-light); }
.drawer-nav a .icon { font-size: 18px; width: 24px; text-align: center; opacity: .6; }

.drawer-divider { height: 1px; background: var(--border); margin: 8px 16px; }

.drawer-nav a.logout { color: var(--danger); }

/* ============================================================
   SUB-NAV BAR
   ============================================================ */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--text2);
  background: transparent;
  white-space: nowrap;
  transition: all .15s;
  min-height: 36px;
  display: flex;
  align-items: center;
}
.nav a:active, .nav a.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

/* ============================================================
   BOTTOM TAB BAR (Mobile)
   ============================================================ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,.04);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text2);
  font-size: 10px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
  position: relative;
}
.bottom-nav a .tab-icon { font-size: 22px; line-height: 1; }
.bottom-nav a:active, .bottom-nav a.active { color: var(--primary); }
.bottom-nav a.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 2px;
  background: var(--primary);
  border-radius: 0 0 2px 2px;
}

/* ============================================================
   FLOATING ACTION BUTTON
   ============================================================ */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--bottom-h) + var(--safe-bottom) + 16px);
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 300;
  box-shadow: 0 4px 14px rgba(37,99,235,.35);
  z-index: 90;
  border: none;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.fab:active {
  transform: scale(.92);
  box-shadow: 0 2px 8px rgba(37,99,235,.25);
}

/* ============================================================
   CONTAINER & CARDS
   ============================================================ */
.container {
  max-width: 100%;
  margin: 0 auto;
  padding: 12px 12px;
}
.container.narrow { max-width: 680px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
}

/* ============================================================
   GRID LAYOUT
   ============================================================ */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* ============================================================
   STATS CARDS
   ============================================================ */
.stat {
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.stat > div:first-child {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 4px;
}
.stat b { font-size: 28px; font-weight: 800; color: var(--text); display: block; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 5px;
  font-weight: 500;
}
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* prevents iOS zoom */
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
textarea { min-height: 80px; resize: vertical; line-height: 1.5; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  background: var(--primary);
  color: #fff !important;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1;
  min-height: 48px;
  transition: background .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:hover { background: var(--primary-hover); }

.btn2 { background: #475569; }
.btn2:hover { background: #334155; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

/* Full-width button on mobile */
.btn-block { width: 100%; }

/* ============================================================
   TABLES → MOBILE CARDS
   ============================================================ */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
}
.table-wrap table { min-width: 0; width: 100%; border-collapse: separate; border-spacing: 0; }

/* Mobile: card-style rows */
.table-wrap thead { display: none; }
.table-wrap tr {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.table-wrap td {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 5px 0;
  border: 0;
  font-size: 14px;
  gap: 12px;
}
.table-wrap td::before {
  content: attr(data-label);
  font-size: 12px;
  color: var(--text2);
  font-weight: 500;
  flex-shrink: 0;
  min-width: 70px;
}
.table-wrap td:empty { display: none; }

/* Hide inline forms inside table cards on mobile, show as block */
.table-wrap .inline-form { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.table-wrap .inline-form input,
.table-wrap .inline-form button { max-width: 100%; width: 100%; }

/* ============================================================
   FLASH / ALERTS
   ============================================================ */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--success-light);
  color: #166534;
  margin-bottom: 12px;
  font-size: 14px;
  border: 1px solid #bbf7d0;
}
.error {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--danger-light);
  color: #991b1b;
  margin-bottom: 12px;
  font-size: 14px;
  border: 1px solid #fecaca;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login.card {
  max-width: 420px;
  margin: 40px auto;
  padding: 28px 24px;
  box-shadow: var(--shadow-lg);
}
.login h2 { text-align: center; margin-bottom: 8px; font-size: 22px; }
.login .muted { text-align: center; margin-bottom: 20px; }
.login .btn { width: 100%; margin-top: 8px; }

/* ============================================================
   MISC COMPONENTS
   ============================================================ */
.muted { color: var(--text2); font-size: 13px; }
.danger { color: var(--danger); }
.warn { color: var(--warn); }
.ok { color: var(--success); }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef2ff;
  color: #4338ca;
}

.import-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}
.import-bar input[type="file"] { max-width: 100%; font-size: 14px; }

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.inline-form input { max-width: 360px; }

.danger-zone {
  border-color: #fecaca;
  background: #fffbfb;
}

.stack-form { display: flex; flex-direction: column; gap: 14px; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px 0;
  flex-wrap: wrap;
}
.pagination a {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  min-height: 40px;
  display: flex;
  align-items: center;
  transition: all .15s;
}
.pagination a:active { background: var(--primary); color: #fff; }

/* ============================================================
   SEARCH BAR (customer list)
   ============================================================ */
.search-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.search-grid > div { flex: 1; min-width: 120px; }
.search-grid .btn { flex-shrink: 0; }

/* ============================================================
   DESKTOP BREAKPOINT (>=769px)
   ============================================================ */
@media (min-width: 769px) {
  body { padding-bottom: 0; font-size: 15px; }

  .hamburger { display: none; }
  .top > div:last-child { display: flex; align-items: center; }
  .top { padding: 0 24px; }

  .bottom-nav { display: none; }
  .fab { bottom: 28px; right: 28px; width: 56px; height: 56px; font-size: 28px; border-radius: 18px; }
  .drawer, .drawer-overlay { display: none !important; }

  .nav { padding: 10px 24px; }
  .nav a { font-size: 14px; padding: 8px 16px; }

  .container { max-width: 1100px; padding: 20px 24px; }
  .card { padding: 24px; margin-bottom: 16px; }

  .grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

  .stat b { font-size: 32px; }

  /* Desktop tables: normal table layout */
  .table-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
  .table-wrap table { min-width: 760px; border-collapse: collapse; }
  .table-wrap thead { display: table-header-group; }
  .table-wrap tr {
    display: table-row;
    border-radius: 0;
    border: 0;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }
  .table-wrap th {
    display: table-cell;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text2);
    font-weight: 600;
    background: #f8fafc;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }
  .table-wrap td {
    display: table-cell;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    font-size: 14px;
    vertical-align: top;
  }
  .table-wrap td::before { display: none; }
  .table-wrap .inline-form { flex-direction: row; width: auto; }
  .table-wrap .inline-form input { width: auto; max-width: 200px; }

  .login.card { margin: 80px auto; }

  .import-bar input[type="file"] { max-width: 360px; }
  .inline-form input { max-width: 360px; }

  .search-grid { flex-wrap: nowrap; }
}

/* ============================================================
   TABLET BREAKPOINT (769px - 1024px)
   ============================================================ */
@media (min-width: 769px) and (max-width: 1024px) {
  .container { max-width: 900px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .table-wrap table { min-width: 700px; }
}

/* ============================================================
   LARGE DESKTOP (>=1025px)
   ============================================================ */
@media (min-width: 1025px) {
  .grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  .top, .nav, .bottom-nav, .fab, .drawer, .drawer-overlay { display: none !important; }
  body { padding: 0; background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}

/* ============================================================
   MESSAGE STYLES
   ============================================================ */
.error-message {
    color: #dc2626;
    margin-bottom: 8px;
    padding: 8px 12px;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 4px;
    font-size: 14px;
}

.success-message {
    color: #16a34a;
    margin-bottom: 8px;
    padding: 8px 12px;
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 4px;
    font-size: 14px;
}

.warning-message {
    color: #d97706;
    margin-bottom: 8px;
    padding: 8px 12px;
    background-color: #fffbeb;
    border: 1px solid #fed7aa;
    border-radius: 4px;
    font-size: 14px;
}

/* ============================================================
   LOGOUT BUTTON STYLES
   ============================================================ */
.link-btn {
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
    padding: 0;
    text-decoration: none;
}

.link-btn:hover {
    text-decoration: underline;
}

.drawer .link-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 0;
    color: var(--text);
    font-size: 15px;
}

.drawer .link-btn:hover {
    background: var(--bg-hover);
    text-decoration: none;
}
