* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; margin: 0; }

.nav-tab { padding: 10px 20px; cursor: pointer; border-bottom: 3px solid transparent; transition: all 0.3s; }
.nav-tab:hover { background: rgba(16, 185, 129, 0.1); }
.nav-tab.active { border-bottom-color: #10b981; color: #10b981; font-weight: 600; }

.module { display: none; padding: 20px; }
.module.active { display: block; }

.card { background: white; border-radius: 8px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

.btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-size: 14px; transition: all 0.2s; }
.btn-primary { background: #10b981; color: white; }
.btn-primary:hover { background: #059669; }
.btn-secondary { background: #6b7280; color: white; }
.btn-secondary:hover { background: #4b5563; }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 4px 8px; font-size: 12px; }

.input { padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; width: 100%; }
.input:focus { outline: none; border-color: #10b981; }
input:read-only, input[readonly] { background: #f3f4f6; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 12px; text-align: left; border: 1px solid #e5e7eb; }
th { background: #f9fafb; font-weight: 600; }

tr:hover td { background: #f9fafb; }

.dropzone { border: 2px dashed #d1d5db; border-radius: 8px; padding: 40px; text-align: center; transition: all 0.3s; }
.dropzone.dragover { border-color: #10b981; background: rgba(16, 185, 129, 0.05); }

.search-box { position: relative; }
.search-results { position: fixed; background: white; border: 1px solid #e5e7eb; border-radius: 6px; max-height: 320px; overflow-y: auto; z-index: 9999; display: none; box-shadow: 0 10px 30px -5px rgba(0,0,0,0.12); }
.search-results.show { display: block; }
.search-item { padding: 8px 12px; cursor: pointer; }
.search-item:hover { background: #f3f4f6; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }

@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.sticky-header th { position: sticky; top: 0; z-index: 10; background: #f9fafb; }

.highlight-red { background: #fee2e2 !important; }
.highlight-yellow { background: #fef3c7 !important; }
.highlight-green { background: #d1fae5 !important; }

/* Modal */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal-content { background: white; border-radius: 8px; padding: 20px; width: 90%; max-width: 800px; max-height: 90vh; overflow-y: auto; }
.modal-content-sm { max-width: 400px; text-align: center; }

/* Print styles */
body.printing header,
body.printing nav,
body.printing main,
body.printing .modal-overlay { display: none !important; }
body.printing #printArea { display: block !important; }

@media print {
    @page {
        size: A4;
        margin: 12mm;
    }
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    body {
        background: white !important;
        font-size: 10pt;
        line-height: 1.4;
    }
    header, nav, main, .modal-overlay, .btn { display: none !important; }
    #printArea {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        background: white !important;
        box-shadow: none !important;
        border: none !important;
        overflow: visible !important;
    }
    #printArea h2 {
        font-size: 16pt;
        margin-bottom: 8px;
    }
    #printArea h3 {
        font-size: 12pt;
        margin: 14px 0 8px;
        page-break-after: avoid;
    }
    #printArea h4 {
        font-size: 11pt;
        margin: 10px 0 6px;
        page-break-after: avoid;
    }
    #printArea p {
        font-size: 9.5pt;
        margin: 4px 0;
    }
    #printArea table,
    #printArea table[style] {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 8pt !important;
        border-collapse: collapse !important;
        page-break-inside: avoid;
        margin-bottom: 8px !important;
    }
    #printArea table th,
    #printArea table td,
    #printArea table[style] th,
    #printArea table[style] td {
        padding: 2px 4px !important;
        border: 0.5pt solid #bbb !important;
        word-break: break-all;
        vertical-align: top;
        font-size: 8pt !important;
        line-height: 1.3 !important;
    }
    #printArea table th,
    #printArea table[style] th {
        background: #f0f0f0 !important;
        font-weight: 600 !important;
    }
    /* Force grid layouts to single column in print */
    #printArea [style*="display:grid"],
    #printArea [style*="display: grid"] {
        display: block !important;
    }
    #printArea [style*="grid-template-columns"] > div {
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 12px;
        page-break-inside: avoid;
    }
    /* Simplify tank cards for print */
    #printArea [style*="border-radius:28px"] {
        border-radius: 8px !important;
        box-shadow: none !important;
        border: 1pt solid #93c5fd !important;
        padding: 12px !important;
    }
    #printArea [style*="border-radius:16px"] {
        border-radius: 6px !important;
    }
    #printArea [style*="background:linear-gradient"] {
        background: #e0f2fe !important;
    }
    /* Hide decorative pseudo-elements in print */
    #printArea [style*="position:absolute;top:-12px"],
    #printArea [style*="position:absolute;top:-6px"] {
        display: none !important;
    }
    /* Page break control */
    #printArea tr { page-break-inside: avoid; }
    #printArea thead { display: table-header-group; }
    #printArea tbody { display: table-row-group; }
}

/* Admin specific */
.admin-nav { background: white; border-bottom: 1px solid #e5e7eb; padding: 0 20px; display: flex; gap: 10px; }
.admin-nav a { padding: 12px 16px; color: #4b5563; text-decoration: none; border-bottom: 3px solid transparent; }
.admin-nav a:hover, .admin-nav a.active { color: #10b981; border-bottom-color: #10b981; }

.status-active { color: #10b981; }
.status-expired { color: #ef4444; }

/* ===== Modern Interactive Enhancements ===== */

@keyframes cardEntry {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modalOverlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalContentIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* --- Card Hover & Entry --- */
.card {
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.04);
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #10b981, #34d399, #10b981);
  background-size: 200% 100%;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 24px -8px rgba(0,0,0,0.12), 0 4px 8px -4px rgba(0,0,0,0.06);
  border-color: rgba(16, 185, 129, 0.1);
}

.card:hover::before {
  opacity: 1;
  animation: gradientShift 3s ease infinite;
}

#admin-samples .card::before,
#admin-recipes .card::before,
#admin-users .card::before,
#admin-fertilizers .card::before,
#admin-shared .card::before,
#admin-invites .card::before {
  background: linear-gradient(90deg, #3b82f6, #60a5fa, #3b82f6);
  background-size: 200% 100%;
}

.module.active .card {
  animation: cardEntry 0.25s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.module.active .card:nth-child(1) { animation-delay: 0s; }
.module.active .card:nth-child(2) { animation-delay: 0.04s; }
.module.active .card:nth-child(3) { animation-delay: 0.08s; }
.module.active .card:nth-child(4) { animation-delay: 0.12s; }
.module.active .card:nth-child(5) { animation-delay: 0.16s; }

/* --- Button Interactions --- */
.btn {
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #059669, #047857);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}

.btn-secondary {
  background: linear-gradient(135deg, #6b7280, #4b5563);
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #4b5563, #374151);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.35);
}

/* --- Input Interactions --- */
.input {
  padding: 10px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fafafa;
  transition: all 0.25s ease;
}

.input:hover {
  border-color: #d1d5db;
  background: #fff;
}

.input:focus {
  outline: none;
  border-color: #10b981;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12), 0 1px 2px rgba(0,0,0,0.04);
}

/* --- Table Interactions --- */
th, td {
  padding: 10px 14px;
  border-bottom: 1px solid #f0f0f0;
  border-left: none;
  border-right: none;
  border-top: none;
}

th {
  background: linear-gradient(180deg, #f9fafb, #f3f4f6);
  font-weight: 600;
  color: #374151;
  font-size: 12px;
  letter-spacing: 0.3px;
}

tr {
  transition: all 0.15s ease;
  position: relative;
}

tr:hover td {
  background: #f0fdf4;
}

tr:hover td:first-child {
  box-shadow: inset 3px 0 0 #10b981;
}

.sticky-header th {
  background: linear-gradient(180deg, #f9fafb, #f3f4f6);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* --- Nav Tabs --- */
.nav-tab {
  padding: 12px 24px;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-tab:hover {
  background: rgba(16, 185, 129, 0.08);
}

.nav-tab.active {
  font-weight: 600;
}

.admin-nav a {
  padding: 14px 20px;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.admin-nav a:hover {
  background: rgba(59, 130, 246, 0.08);
}

.admin-nav a.active {
  font-weight: 600;
}

/* --- Modal Animations --- */
.modal-overlay {
  background: rgba(0,0,0,0.5);
}

.modal-overlay.show {
  animation: modalOverlayIn 0.2s ease;
}

.modal-content {
  opacity: 1;
  transform: none;
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}

.modal-overlay.show .modal-content {
  animation: modalContentIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-content-sm {
  max-width: 420px;
  padding: 32px;
}

/* --- Dropzone --- */
.dropzone {
  border-radius: 12px;
  padding: 48px;
  background: #fafafa;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.dropzone:hover {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.04);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px -4px rgba(16, 185, 129, 0.1);
}

.dropzone.dragover {
  background: rgba(16, 185, 129, 0.08);
  transform: scale(1.01);
  box-shadow: 0 12px 24px -8px rgba(16, 185, 129, 0.15);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.3;
  transition: transform 0.2s ease;
}

.badge:hover {
  transform: scale(1.05);
}

/* --- Search Results --- */
/* 已合并到基础 .search-results 定义中 */

.search-item {
  padding: 10px 14px;
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
}

.search-item:hover {
  background: #f0fdf4;
  border-left-color: #10b981;
  padding-left: 16px;
}

/* --- User Dropdown --- */
#userDropdown {
  border-radius: 12px;
  box-shadow: 0 10px 30px -5px rgba(0,0,0,0.15);
  border: 1px solid #f0f0f0;
  overflow: hidden;
}

#userDropdown a {
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
}

#userDropdown a:hover {
  background: #f0fdf4;
  border-left-color: #10b981;
  padding-left: 18px;
}

/* --- Grid spacing --- */
.grid-2, .grid-3, .grid-4 {
  gap: 24px;
}

/* --- Table Column Filters --- */
.filter-row th {
  padding: 4px 6px;
  background: #f3f4f6;
  border-top: none;
}
.filter-row .input-sm {
  padding: 4px 6px;
  font-size: 12px;
  min-width: 50px;
  width: 100%;
}
.filter-row select.input-sm {
  padding-right: 18px;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

/* ============================================
   Mobile Compatibility
   ============================================ */

/* Disable hover lift on touch devices */
@media (hover: none) and (pointer: coarse) {
  .card:hover {
    transform: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  }
  .card:hover::before {
    opacity: 0;
    animation: none;
  }
  .btn:hover {
    transform: none;
    box-shadow: none;
  }
  .btn-primary:hover,
  .btn-danger:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  }
  .dropzone:hover {
    transform: none;
    box-shadow: none;
  }
}

/* Small screen adaptations */
@media (max-width: 768px) {
  .card {
    padding: 16px;
    margin-bottom: 16px;
    border-radius: 10px;
  }
  .card::before {
    height: 2px;
  }
  .btn {
    padding: 6px 12px;
    font-size: 13px;
  }
  .input {
    padding: 8px 10px;
    font-size: 16px; /* prevent iOS zoom on focus */
  }
  .nav-tab {
    padding: 8px 12px;
    font-size: 13px;
  }
  .admin-nav {
    padding: 0 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-nav a {
    padding: 10px 12px;
    font-size: 13px;
    white-space: nowrap;
  }
  .modal-content {
    padding: 20px;
    border-radius: 12px;
    width: 95%;
  }
  .modal-content-sm {
    padding: 24px;
    max-width: 95%;
  }
  th, td {
    padding: 8px 10px;
    font-size: 12px;
  }
  .grid-2, .grid-3, .grid-4 {
    gap: 12px;
  }
  .dropzone {
    padding: 32px 20px;
  }
  .search-results {
    max-height: 260px;
  }
}

/* --- AB Tank Cards (modern fertilizer tank style) --- */
.tank-card {
  background: linear-gradient(165deg, #f8fafc 0%, #f0f9ff 20%, #e0f2fe 60%, #dbeafe 100%);
  border: 1.5px solid rgba(147, 197, 253, 0.5);
  border-radius: 28px;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 1px 2px rgba(59, 130, 246, 0.04),
    0 4px 12px rgba(59, 130, 246, 0.06),
    0 16px 40px rgba(59, 130, 246, 0.1);
  padding: 32px 28px 28px;
}
.tank-card::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 42%;
  height: 26px;
  background: linear-gradient(180deg, #bfdbfe 0%, #93c5fd 40%, #60a5fa 100%);
  border-radius: 13px 13px 0 0;
  border: 1.5px solid rgba(59, 130, 246, 0.35);
  border-bottom: none;
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.4),
    0 -2px 6px rgba(59, 130, 246, 0.1);
}
.tank-card .tank-lid-handle {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 14%;
  height: 5px;
  background: linear-gradient(180deg, #dbeafe 0%, #93c5fd 100%);
  border-radius: 3px;
  border: 1px solid rgba(59, 130, 246, 0.25);
  z-index: 2;
}
.tank-card .tank-title {
  color: #1e3a5f;
  font-weight: 700;
  font-size: 19px;
  margin-bottom: 20px;
  padding-top: 6px;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  letter-spacing: 0.3px;
}
.tank-card .tank-table-wrap {
  background: rgba(255, 255, 255, 0.4);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(147, 197, 253, 0.25);
  position: relative;
  z-index: 1;
}
.tank-card .tank-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}
.tank-card .tank-table th {
  background: rgba(147, 197, 253, 0.22);
  color: #1e3a5f;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  border-bottom: 1.5px solid rgba(96, 165, 250, 0.35);
}
.tank-card .tank-table td {
  padding: 12px 16px;
  color: #334155;
  border-bottom: 1px solid rgba(147, 197, 253, 0.18);
  transition: background 0.18s ease;
}
.tank-card .tank-table tr:last-child td {
  border-bottom: none;
}
.tank-card .tank-table tr:hover td {
  background: rgba(147, 197, 253, 0.1);
}
.tank-card .tank-ph {
  margin-top: 20px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  border: 1px solid rgba(147, 197, 253, 0.3);
  color: #1e40af;
  font-size: 13px;
  font-weight: 500;
  position: relative;
  z-index: 1;
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.04);
}
.tank-card .tank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.22);
  letter-spacing: 0.6px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}
