/* ============================================
   安徽格锐·外贸单证系统 - 主样式
   Grea Trade Document System - Main Styles
   ============================================ */

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --success: #0f9d58;
  --success-light: #e6f4ea;
  --warning: #f9ab00;
  --warning-light: #fef7e0;
  --danger: #d93025;
  --danger-light: #fce8e6;
  --gray-50: #f8f9fa;
  --gray-100: #f1f3f4;
  --gray-200: #e8eaed;
  --gray-300: #dadce0;
  --gray-400: #bdc1c6;
  --gray-500: #9aa0a6;
  --gray-600: #80868b;
  --gray-700: #5f6368;
  --gray-800: #3c4043;
  --gray-900: #202124;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.1);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
  --radius: 6px;
  --radius-lg: 10px;
  --sidebar-width: 240px;
  --header-height: 56px;
  --green-bg: #e8f5e9;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Arial', 'Noto Sans SC', sans-serif;
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-50);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Toast ===== */
.grea-toast {
  position: fixed; top: 20px; right: 20px; z-index: 99999;
  padding: 12px 24px; border-radius: var(--radius);
  font-size: 14px; box-shadow: var(--shadow-lg);
  transition: opacity 0.3s ease;
  max-width: 520px;
  white-space: pre-wrap;
}
.grea-toast-info { background: var(--gray-800); color: white; }
.grea-toast-success { background: var(--success); color: white; }
.grea-toast-error { background: var(--danger); color: white; }
.grea-toast-warning { background: var(--warning); color: var(--gray-900); }
.grea-toast-fade { opacity: 0; }

/* ===== Modal ===== */
.grea-modal-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
}
.grea-modal {
  background: white; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); min-width: 360px; max-width: 800px;
  max-height: 80vh; overflow-y: auto;
}
.grea-modal-lg { min-width: 600px; max-width: 90vw; }
.grea-modal-header {
  padding: 16px 24px; font-size: 16px; font-weight: 600;
  border-bottom: 1px solid var(--gray-200);
}
.grea-modal-body { padding: 24px; }
.grea-modal-footer {
  padding: 12px 24px; display: flex; gap: 8px;
  justify-content: flex-end; border-top: 1px solid var(--gray-200);
}

/* ===== Buttons ===== */
.grea-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 20px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; border: 1px solid transparent;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
  line-height: 1.4;
}
.grea-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.grea-btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.grea-btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.grea-btn-secondary { background: white; color: var(--gray-800); border-color: var(--gray-300); }
.grea-btn-secondary:hover:not(:disabled) { background: var(--gray-100); }
.grea-btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.grea-btn-danger:hover:not(:disabled) { background: #c62828; }
.grea-btn-success { background: var(--success); color: white; border-color: var(--success); }
.grea-btn-success:hover:not(:disabled) { background: #0b8043; }
.grea-btn-sm { padding: 4px 12px; font-size: 12px; }
.grea-btn-lg { padding: 10px 28px; font-size: 16px; }

/* ===== Forms ===== */
.grea-form-group { margin-bottom: 16px; }
.grea-form-group label {
  display: block; font-weight: 500; margin-bottom: 6px;
  color: var(--gray-800); font-size: 13px;
}
.grea-input, .grea-select, .grea-textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300);
  border-radius: var(--radius); font-size: 14px; color: var(--gray-900);
  background: white; transition: border-color 0.2s;
  line-height: 1.5;
}
.grea-input:focus, .grea-select:focus, .grea-textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.grea-textarea { min-height: 80px; resize: vertical; }
.grea-select { appearance: auto; }
.grea-input-error { border-color: var(--danger) !important; }
.grea-error-msg { color: var(--danger); font-size: 12px; margin-top: 4px; }
.grea-form-hint { color: var(--gray-500); font-size: 12px; margin-top: 4px; }

.grea-select-panel {
  background: var(--green-bg) !important;
}

/* ===== Tables ===== */
.grea-table-wrap {
  overflow-x: auto; background: white; border-radius: var(--radius);
  box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
}
.grea-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.grea-table th {
  background: var(--gray-100); color: var(--gray-700); font-weight: 600;
  padding: 12px 16px; text-align: left; border-bottom: 2px solid var(--gray-200);
  white-space: nowrap; line-height: 2.0;
}
.grea-table td {
  padding: 10px 16px; border-bottom: 1px solid var(--gray-200);
  line-height: 2.0; vertical-align: middle;
}
.grea-table tr:hover { background: var(--gray-50); }
.grea-table .grea-actions { display: flex; gap: 4px; flex-wrap: nowrap; }

/* ===== Page Layout ===== */
.grea-page { padding: 24px; max-width: 1400px; margin: 0 auto; }
.grea-page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.grea-page-title { font-size: 22px; font-weight: 600; color: var(--gray-900); }
.grea-page-actions { display: flex; gap: 8px; align-items: center; }

/* ===== Toolbar / Filters ===== */
.grea-toolbar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 16px;
  background: white; border-radius: var(--radius);
  box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
}
.grea-toolbar .grea-input { width: auto; min-width: 200px; }

/* ===== Sidebar Layout ===== */
.grea-layout { display: flex; min-height: 100vh; }
.grea-sidebar {
  width: var(--sidebar-width); background: var(--gray-900);
  color: white; display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform 0.3s;
}
.grea-sidebar-header {
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.grea-sidebar-logo { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.grea-sidebar-logo-img { width: 32px; height: 32px; border-radius: 50%; background: var(--danger); display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 16px; flex-shrink: 0; }
.grea-sidebar-user {
  padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 12px; color: rgba(255,255,255,0.7);
}
.grea-sidebar-user strong { color: white; font-size: 13px; display: block; }
.grea-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.grea-nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; color: rgba(255,255,255,0.7); cursor: pointer;
  transition: all 0.2s; font-size: 14px; border: none; background: none;
  width: 100%; text-align: left;
}
.grea-nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.grea-nav-item.active { background: rgba(255,255,255,0.12); color: white; font-weight: 500; border-right: 3px solid var(--primary); }
.grea-nav-item .nav-icon { width: 20px; text-align: center; font-size: 16px; }

.grea-main {
  margin-left: var(--sidebar-width); flex: 1;
  display: flex; flex-direction: column; min-height: 100vh;
}
.grea-header {
  height: var(--header-height); background: white; border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 50;
}
.grea-header-left { display: flex; align-items: center; gap: 12px; }
.grea-header-right { display: flex; align-items: center; gap: 12px; }
.grea-content { flex: 1; padding: 0; }

/* ===== Language Switcher ===== */
.grea-lang-btn {
  padding: 4px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius);
  background: white; cursor: pointer; font-size: 12px; color: var(--gray-700);
}
.grea-lang-btn:hover { background: var(--gray-100); }

/* ===== Login Page ===== */
.grea-login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a73e8 0%, #0f9d58 100%);
}
.grea-login-card {
  background: white; border-radius: var(--radius-lg); padding: 40px;
  width: 400px; max-width: 90vw; box-shadow: var(--shadow-lg);
}
.grea-login-logo {
  text-align: center; margin-bottom: 32px;
}
.grea-login-logo .logo-icon {
  width: 64px; height: 64px; border-radius: 50%; background: var(--danger);
  display: inline-flex; align-items: center; justify-content: center;
  color: white; font-size: 28px; font-weight: bold; margin-bottom: 12px;
}
.grea-login-logo h1 { font-size: 20px; color: var(--gray-900); }
.grea-login-logo p { font-size: 13px; color: var(--gray-500); margin-top: 4px; }
.grea-login-error {
  background: var(--danger-light); color: var(--danger); padding: 10px 16px;
  border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; display: none;
}

/* ===== Dashboard ===== */
.grea-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.grea-stat-card {
  background: white; border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
}
.grea-stat-card h3 { font-size: 13px; color: var(--gray-500); margin-bottom: 8px; }
.grea-stat-card .number { font-size: 28px; font-weight: 700; color: var(--gray-900); }
.grea-stat-card .sub { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ===== Document Editor ===== */
.grea-editor { background: white; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200); }
.grea-editor-section { margin-bottom: 24px; }
.grea-editor-section h3 { font-size: 15px; font-weight: 600; color: var(--gray-800); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--gray-200); }
.grea-editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grea-editor-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grea-editor-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.grea-editor-full { grid-column: 1 / -1; }

/* ===== Product Lines Table (in editor) ===== */
.grea-product-lines {
  width: 100%; border-collapse: collapse; table-layout: fixed;
  min-width: 820px;
}
.grea-product-lines th {
  background: var(--gray-100); padding: 8px 10px; font-size: 12px;
  font-weight: 600; text-align: left; border: 1px solid var(--gray-200);
  white-space: nowrap;
}
.grea-product-lines td {
  padding: 6px 8px; border: 1px solid var(--gray-200); vertical-align: middle;
}
.grea-product-lines input, .grea-product-lines select {
  width: 100%; box-sizing: border-box;
  padding: 6px 8px; border: 1px solid var(--gray-300);
  border-radius: 3px; font-size: 13px; background: #fff;
  line-height: 1.4;
}
.grea-product-lines input:focus, .grea-product-lines select:focus {
  border-color: var(--primary); outline: none;
}
.grea-product-lines .line-total { text-align: right; font-weight: 500; white-space: nowrap; }
/* Qty/数字列：隐藏 spinner，保证数字可见 */
.grea-product-lines input.line-qty,
.grea-product-lines input.line-price,
.grea-product-lines input.line-priceRMB {
  min-width: 80px;
  text-align: right;
  appearance: textfield;
  -moz-appearance: textfield;
}
.grea-product-lines input.line-qty::-webkit-outer-spin-button,
.grea-product-lines input.line-qty::-webkit-inner-spin-button,
.grea-product-lines input.line-price::-webkit-outer-spin-button,
.grea-product-lines input.line-price::-webkit-inner-spin-button,
.grea-product-lines input.line-priceRMB::-webkit-outer-spin-button,
.grea-product-lines input.line-priceRMB::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
.grea-product-lines input.line-unit {
  min-width: 56px;
}
.grea-editor-section:has(.grea-product-lines) {
  overflow-x: auto;
}

/* ===== Status Badges ===== */
.grea-badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 500;
}
.grea-badge-draft { background: var(--gray-200); color: var(--gray-700); }
.grea-badge-final { background: var(--success-light); color: var(--success); }
.grea-badge-pending { background: var(--warning-light); color: var(--warning); }

/* ===== Empty State ===== */
.grea-empty {
  text-align: center; padding: 60px 20px; color: var(--gray-400);
}
.grea-empty .icon { font-size: 48px; margin-bottom: 12px; }
.grea-empty p { font-size: 15px; }

/* ===== Print Styles ===== */
@media print {
  .grea-sidebar, .grea-header, .grea-no-print { display: none !important; }
  .grea-main { margin-left: 0 !important; }
  .grea-content { padding: 0 !important; }
  body { background: white; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .grea-sidebar { transform: translateX(-100%); }
  .grea-sidebar.open { transform: translateX(0); }
  .grea-main { margin-left: 0; }
  .grea-page { padding: 16px; }
  .grea-editor-grid { grid-template-columns: 1fr; }
  .grea-editor-grid-3, .grea-editor-grid-4 { grid-template-columns: 1fr 1fr; }
  .grea-toolbar { flex-direction: column; align-items: stretch; }
  .grea-toolbar .grea-input { min-width: auto; width: 100%; }
}

/* ===== Tabs ===== */
.grea-tabs {
  display: flex; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px;
}
.grea-tab {
  padding: 10px 20px; cursor: pointer; border: none; background: none;
  font-size: 14px; color: var(--gray-600); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all 0.2s;
}
.grea-tab:hover { color: var(--gray-900); }
.grea-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== PDF Preview ===== */
.grea-pdf-preview {
  background: white; padding: 16mm 12mm; min-height: 297mm;
  width: 210mm; margin: 0 auto; box-shadow: var(--shadow-md);
  font-family: Arial, 'Microsoft YaHei', 'SimSun', sans-serif; font-size: 10.5pt; line-height: 1.5;
  color: #222;
}
.grea-pdf-preview h1 { font-size: 18pt; font-weight: bold; text-align: center; margin: 10px 0 8px; letter-spacing: 1px; }
.grea-pdf-preview h2 { font-size: 11pt; font-weight: normal; text-align: center; margin-bottom: 12px; }
.grea-pdf-preview .company-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 12px;
}
.doc-letterhead { position: relative; margin-bottom: 8px; min-height: 88px; padding-left: 110px; padding-right: 24px; }
.doc-float-logo {
  position: absolute; left: 0; top: 0; width: 96px; height: auto;
  z-index: 2; pointer-events: none;
}
.doc-float-seal-top {
  position: absolute; right: 0; top: 0; width: 72px; height: auto; opacity: 0.92; z-index: 2;
}
.doc-letterhead-center { text-align: center; }
.doc-name-cn { font-size: 15pt; font-weight: 700; color: #1a1a1a; line-height: 1.35; text-align: center; }
.doc-name-en { font-size: 11pt; font-weight: 600; color: #333; margin-top: 2px; text-align: center; }
.doc-addr { font-size: 8.5pt; color: #555; margin-top: 6px; line-height: 1.55; text-align: center; }
.doc-letterhead-rule { border: none; border-top: 1.5px solid #333; margin: 10px 0 12px; }
.doc-seal-block {
  margin-top: 28px; display: flex; justify-content: flex-end; align-items: flex-end; gap: 8px;
  min-height: 110px; position: relative;
}
.doc-seal-text { text-align: right; font-size: 10pt; line-height: 1.5; padding-bottom: 8px; }
.doc-seal-label { font-size: 9pt; color: #666; margin-top: 18px; }
.doc-contract-seal {
  width: 124px; height: auto; position: relative; margin-left: -20px; margin-bottom: -6px;
}
.doc-seal-missing { font-size: 9pt; color: #999; border: 1px dashed #ccc; padding: 28px 16px; }
.grea-pdf-preview .company-left { display: flex; align-items: center; gap: 12px; }
.grea-pdf-preview .company-right { text-align: right; font-size: 9pt; color: var(--gray-700); }
.grea-pdf-preview .company-logo { width: 48px; height: 48px; border-radius: 50%; background: #c41e1e; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 20px; }
.grea-pdf-preview .company-name { font-size: 12pt; font-weight: bold; }
.grea-pdf-preview .info-section { margin-bottom: 16px; }
.grea-pdf-preview .info-row { display: flex; margin-bottom: 4px; }
.grea-pdf-preview .info-label { width: 120px; font-weight: bold; flex-shrink: 0; }
.grea-pdf-preview .info-value { flex: 1; }
.grea-pdf-preview .section-bar {
  background: #e8e8e8; font-weight: 700; padding: 6px 10px; border: 1px solid #999;
  margin: 12px 0 0; font-size: 10pt;
}
.grea-pdf-preview .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.grea-pdf-preview .box-block { border: 1px solid #999; padding: 8px 10px; font-size: 9.5pt; line-height: 1.55; min-height: 70px; }
.grea-pdf-preview .box-block strong { display: block; margin-bottom: 4px; }
.grea-pdf-preview table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.grea-pdf-preview table th { background: #f0f0f0; padding: 6px 10px; border: 1px solid #999; font-size: 10pt; text-align: center; }
.grea-pdf-preview table td { padding: 6px 10px; border: 1px solid #999; font-size: 10pt; }
.grea-pdf-preview .customs-grid td, .grea-pdf-preview .customs-grid th {
  border: 1px solid #333; padding: 4px 6px; font-size: 9pt; vertical-align: top;
}
.grea-pdf-preview .signature-area { margin-top: 32px; text-align: right; }
.grea-pdf-preview .page-footer { text-align: center; font-size: 9pt; color: var(--gray-500); margin-top: 20px; }

/* ===== Select2-like autocomplete ===== */
.grea-autocomplete { position: relative; }
.grea-autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 1000;
  background: var(--green-bg); border: 1px solid var(--gray-300);
  border-radius: var(--radius); max-height: 200px; overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.grea-autocomplete-item {
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--gray-200);
}
.grea-autocomplete-item:hover { background: rgba(26,115,232,0.1); }
.grea-autocomplete-item:last-child { border-bottom: none; }
.grea-autocomplete-item .sub { font-size: 11px; color: var(--gray-500); }
