/* --- Archive Pro Design System --- */
:root {
  --font-serif: "Georgia", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", monospace;

  --color-base: #fdfdfc;
  --color-surface: #ffffff;
  --color-ink: #121211;
  --color-muted: #8e8e8a;
  --color-border: #ecece8;
  --color-accent: #3e5c54;
  --color-danger: #a54a4a;
  --color-warning: #d4a373;

  --shadow-float: 0 16px 40px rgba(0,0,0,0.12);
  --shadow-soft: 0 2px 10px rgba(0,0,0,0.03);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background-color: var(--color-base);
  color: var(--color-ink);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  /* 噪点背景效果 */
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.6' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
}

.app-shell { max-width: 720px; margin: 0 auto; padding: 2rem 1.5rem 6rem; }

/* Navigation */
.app-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4rem; padding-bottom: 2rem; border-bottom: 1px solid var(--color-border); }
.brand { display: flex; align-items: center; gap: 0.75rem; }
.logo-symbol { width: 14px; height: 14px; background: var(--color-ink); border-radius: 2px; }
.brand h1 { font-family: var(--font-serif); font-size: 1.4rem; font-weight: 400; margin: 0; letter-spacing: -0.01em; }

.stats-row { display: flex; gap: 1.5rem; }
.stat-group { display: flex; flex-direction: column; align-items: flex-end; }
.stat-label { font-size: 0.65rem; text-transform: uppercase; color: var(--color-muted); letter-spacing: 0.05em; font-weight: 700; }
.stat-num { font-family: var(--font-mono); font-size: 1.2rem; font-weight: 500; }
.stat-group.danger .stat-num { color: var(--color-danger); }

/* Toolbar & Custom Select */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }

.sort-wrapper { position: relative; }
.select-trigger { 
  background: var(--color-surface); 
  border: 1px solid var(--color-border); 
  padding: 0.6rem 0.8rem; 
  font-size: 0.8rem; 
  font-weight: 600;
  display: flex; 
  align-items: center; 
  gap: 1.5rem; 
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}
.select-trigger:hover { border-color: var(--color-muted); }
.icon-chevron { width: 14px; height: 14px; transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sort-wrapper.is-open .icon-chevron { transform: rotate(180deg); }

.select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 200px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-float);
  list-style: none;
  padding: 0.4rem;
  margin: 0;
  z-index: 500;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px) scale(0.98);
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sort-wrapper.is-open .select-menu { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

.select-menu li { padding: 0.6rem 0.8rem; font-size: 0.8rem; cursor: pointer; transition: background 0.2s; border-radius: 2px; }
.select-menu li:hover { background: rgba(0,0,0,0.03); }
.select-menu li.selected { color: var(--color-accent); font-weight: 700; background: rgba(62, 92, 84, 0.05); }

.expired-count { font-family: var(--font-mono); font-size: 0.75rem; color: var(--color-danger); font-weight: 600; }

/* Items List */
.items-archive { display: grid; gap: 1rem; }
.item-card { 
  display: flex; 
  background: var(--color-surface); 
  border: 1px solid var(--color-border); 
  padding: 0.8rem; 
  gap: 1.2rem; 
  transition: all 0.2s; 
  cursor: pointer; 
}
.item-card:hover { border-color: var(--color-muted); transform: translateY(-1px); }

.item-visual { width: 72px; height: 72px; background: #f5f5f0; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.item-visual img { width: 100%; height: 100%; object-fit: cover; }

.item-details { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.2rem; }
.item-name { font-family: var(--font-serif); font-size: 1.1rem; margin: 0; font-weight: 400; }
.item-meta { font-family: var(--font-mono); font-size: 0.7rem; color: var(--color-muted); margin: 0; }
.item-status { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; padding: 0.2rem 0.4rem; border-radius: 2px; }

.item-actions { display: flex; gap: 1.2rem; margin-top: 0.4rem; }
.btn-text { background: none; border: none; font-size: 0.7rem; text-decoration: underline; color: var(--color-muted); cursor: pointer; padding: 0; }
.btn-text.danger { color: var(--color-danger); }

/* FAB Action */
.fab-action {
  position: fixed;
  right: 2rem;
  bottom: 2rem;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--color-ink);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  cursor: pointer;
  z-index: 100;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.fab-action:hover { transform: scale(1.1); }
.fab-action svg { width: 28px; height: 28px; }

/* Modal System (The Robust Way) */
.modal-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  transition: visibility 0.4s;
}
.modal-screen.is-visible { visibility: visible; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 18, 17, 0.3);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.4s ease;
}
.modal-screen.is-visible .modal-backdrop { opacity: 1; }

.modal-container {
  background: var(--color-base);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  position: relative;
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}
.modal-screen.is-visible .modal-container { transform: translateY(0); opacity: 1; }

.modal-header { padding: 2rem 2rem 1.5rem; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-header h2 { font-family: var(--font-serif); font-weight: 400; font-size: 1.4rem; margin: 0; }
.close-trigger { background: none; border: none; font-size: 2.2rem; cursor: pointer; color: var(--color-muted); line-height: 1; }

.modal-body { padding: 0 2rem 2.5rem; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; min-height: 0; scrollbar-gutter: stable; }

/* Inventory Form */
.inventory-form { display: grid; gap: 1.5rem; }

.photo-upload { display: flex; flex-direction: column; gap: 0.8rem; }
.photo-zone { width: 100%; aspect-ratio: 16/9; background: #f5f5f0; border: 1px dashed var(--color-border); display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden; }
.photo-zone img { width: 100%; height: 100%; object-fit: cover; }
.photo-ui { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; color: var(--color-muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group label { font-size: 0.65rem; text-transform: uppercase; color: var(--color-muted); letter-spacing: 0.08em; font-weight: 800; }
.form-group input, .form-group textarea {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 0.8rem;
  font-size: 1rem;
  font-family: var(--font-sans);
  outline: none;
}
.form-group input:focus { border-color: var(--color-ink); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.status-bar { display: flex; justify-content: space-between; align-items: center; }

.stepper-tool { display: flex; align-items: center; border: 1px solid var(--color-border); background: var(--color-surface); }
.stepper-tool button { width: 44px; height: 44px; background: none; border: none; font-size: 1.4rem; cursor: pointer; }
.stepper-tool span { padding: 0 1rem; font-family: var(--font-mono); font-weight: 600; min-width: 3ch; text-align: center; }
.expiry-info { font-family: var(--font-mono); font-size: 0.8rem; color: var(--color-accent); font-weight: 600; }

.form-footer { display: grid; grid-template-columns: 100px 1fr; gap: 1rem; margin-top: 1rem; }
.btn-primary { background: var(--color-ink); color: white; border: none; padding: 1rem; font-weight: 700; cursor: pointer; }
.btn-secondary { background: none; border: 1px solid var(--color-border); cursor: pointer; }

/* Empty View */
.empty-state { padding: 6rem 1rem; text-align: center; border: 1px dashed var(--color-border); color: var(--color-muted); }
.empty-state p { margin: 0; font-size: 1.1rem; }
.empty-state small { font-size: 0.75rem; letter-spacing: 0.02em; }

.is-hidden { display: none !important; }

/* Mobile Adaptive */
@media (max-width: 600px) {
  .app-nav { margin-bottom: 2.5rem; flex-direction: column; align-items: flex-start; gap: 1.5rem; }
  .stats-row { width: 100%; justify-content: space-between; }

  .modal-screen { align-items: flex-end; padding: 0; }
  .modal-container {
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    max-height: 75svh;
    max-height: 75vh; /* fallback */
    width: 100%;
    max-width: 100%;
    margin: 0;
  }
  .modal-screen.is-visible .modal-container { transform: translateY(0); }

  .modal-header { padding: 1rem 1rem 0.6rem; }
  .modal-header h2 { font-size: 1rem; }
  .close-trigger { font-size: 1.8rem; }
  .modal-body { padding: 0 1rem 1.2rem; }

  .photo-zone { aspect-ratio: auto; height: 80px; }
  .inventory-form { gap: 0.8rem; }
  .form-grid { gap: 0.6rem; }
  .form-group input, .form-group textarea { padding: 0.6rem 0.8rem; font-size: 0.95rem; }

  .form-footer { grid-template-columns: 1fr; gap: 0.6rem; margin-top: 0.5rem; }
  .btn-primary { padding: 0.8rem; }
  .btn-secondary { order: 2; padding: 0.7rem; }
}
