:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-hover: #faf9f7;
  --primary: #6b8e7f;
  --primary-light: #a8c4b8;
  --primary-bg: #eaf0ec;
  --accent: #c4a882;
  --accent-light: #ddd0c0;
  --text: #333333;
  --text-secondary: #888888;
  --text-tertiary: #aaaaaa;
  --border: #e8e6e1;
  --border-hover: #d0cec8;
  --shadow: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --status-draft: #b4b2a9;
  --status-draft-bg: #f1efe8;
  --status-pending: #ba7517;
  --status-pending-bg: #faeeda;
  --status-declared: #378add;
  --status-declared-bg: #e6f1fb;
  --status-completed: #1d9e75;
  --status-completed-bg: #e1f5ee;
  --status-exception: #e24b4a;
  --status-exception-bg: #fcebeb;

  --danger: #e24b4a;
  --danger-bg: #fcebeb;
  --success: #1d9e75;
  --success-bg: #e1f5ee;

  --sidebar-w: 220px;
  --sidebar-w-collapsed: 0px;
  --topbar-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 14px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--primary); text-decoration: none; }

#app {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
  z-index: 100;
}

.sidebar-header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 28px; height: 28px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  letter-spacing: -0.5px;
}
.logo-text { font-size: 15px; font-weight: 600; color: var(--text); }

.sidebar-toggle {
  padding: 4px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  display: none;
}

.nav-list { list-style: none; flex: 1; padding: 8px; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 500;
}

.nav-item svg { flex-shrink: 0; }
.nav-item span { font-size: 13px; }

.nav-badge {
  margin-left: auto;
  background: var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.nav-item.active .nav-badge {
  background: var(--primary);
  color: #fff;
}

.nav-status {
  margin-left: auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.nav-status.connected { background: var(--success); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.sync-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.sync-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.menu-btn { display: none; color: var(--text); padding: 4px; }

.page-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

.topbar-actions { display: flex; gap: 8px; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* ===== Views ===== */
.view { display: none; }
.view.active { display: block; }

/* ===== Dashboard ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
}

.stat-pending { color: var(--status-pending); }
.stat-declared { color: var(--status-declared); }
.stat-exception { color: var(--status-exception); }

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

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-title { font-size: 14px; font-weight: 600; }

.card-body { padding: 16px 20px; }

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quick-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 12px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
}

.quick-action-btn:hover {
  border-color: var(--primary-light);
  background: var(--primary-bg);
}

.qa-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600;
}

.qa-label { font-size: 12px; color: var(--text-secondary); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-tertiary);
}

.empty-state p { margin-bottom: 12px; font-size: 13px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: #5a7d6e; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--border-hover); background: var(--surface-hover); }

.btn-ghost {
  color: var(--text-secondary);
  background: transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--surface-hover); }

.btn-outline {
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-bg); }

.btn-danger {
  color: var(--danger);
  background: var(--danger-bg);
}
.btn-danger:hover { background: #f8d8d8; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-link {
  color: var(--primary);
  font-size: 13px;
  padding: 0;
}
.btn-link:hover { text-decoration: underline; }

/* ===== Table ===== */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px;
}

.search-box svg { color: var(--text-tertiary); flex-shrink: 0; }

.search-input {
  border: none;
  background: none;
  outline: none;
  padding: 9px 0;
  flex: 1;
  font-size: 13px;
}

.filter-group { display: flex; gap: 8px; }

.filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 36px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  cursor: pointer;
}

.table-wrapper {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

.table-empty { padding: 40px; }

/* ===== Product Detail Table ===== */
.product-table { min-width: 1100px; }

.product-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}

.product-form .form-group { margin-bottom: 0; }

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

.product-form .form-group input {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.product-form .form-group input:focus {
  border-color: var(--primary);
}

.muted { color: var(--text-tertiary); }

/* ===== Status Badges ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.status-draft { background: var(--status-draft-bg); color: var(--status-draft); }
.status-pending { background: var(--status-pending-bg); color: var(--status-pending); }
.status-declared { background: var(--status-declared-bg); color: var(--status-declared); }
.status-completed { background: var(--status-completed-bg); color: var(--status-completed); }
.status-exception { background: var(--status-exception-bg); color: var(--status-exception); }

/* ===== Form ===== */
.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.form-header h2 { font-size: 18px; font-weight: 600; }

.declaration-form {
  max-width: 900px;
}

.form-section {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
}

.form-section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

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

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group-full { grid-column: 1 / -1; }

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.required { color: var(--danger); }

.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
  font-size: 13px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

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

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 0;
}

/* ===== Templates ===== */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.template-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.template-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-md);
}

.template-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary-bg);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

.template-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.template-card p { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }
.template-card .template-meta {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.template-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-hover);
  color: var(--text-secondary);
}

/* ===== Obsidian ===== */
.obsidian-status {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--surface-hover);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.obsidian-status-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.obsidian-status-icon.connected { color: var(--success); border-color: var(--success); }

.obsidian-status-text h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.obsidian-status-text p { font-size: 13px; color: var(--text-secondary); }

.obsidian-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== Settings ===== */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.setting-row:last-child { border-bottom: none; }

.setting-info { flex: 1; }
.setting-label { font-size: 13px; font-weight: 500; display: block; }
.setting-desc { font-size: 12px; color: var(--text-tertiary); }

.setting-input {
  width: 200px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  outline: none;
}
.setting-input:focus { border-color: var(--primary); }

.setting-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  outline: none;
}

/* ===== Toggle ===== */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 11px;
  transition: 0.2s;
  cursor: pointer;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ===== Synced Files ===== */
.synced-files { display: flex; flex-direction: column; gap: 8px; }

.synced-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-hover);
  border-radius: var(--radius-md);
}

.synced-file-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--primary-bg);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.synced-file-info { flex: 1; min-width: 0; }
.synced-file-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.synced-file-meta { font-size: 11px; color: var(--text-tertiary); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-close {
  color: var(--text-tertiary);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--text); background: var(--surface-hover); }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.25s ease;
  max-width: 320px;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.info { border-color: var(--status-declared); }

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

/* ===== Sidebar Overlay (mobile) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .menu-btn { display: flex; }
  .topbar-actions .btn span { display: none; }
}

@media (max-width: 500px) {
  .stats-grid { grid-template-columns: 1fr; }
  .content { padding: 12px; }
  .toolbar { flex-direction: column; }
  .filter-group { width: 100%; }
  .filter-select { flex: 1; }

  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 10px; }

  .data-table .col-hide { display: none; }

  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; }

  .obsidian-status { flex-direction: column; text-align: center; }
  .obsidian-actions { flex-direction: column; }
  .obsidian-actions .btn { width: 100%; justify-content: center; }

  .setting-row { flex-direction: column; align-items: flex-start; }
  .setting-input, .setting-select { width: 100%; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }
/* Team sign-in */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top, #eef4ff, #f5f7fb 48%, #edf0f5);
}
.login-screen[hidden], #app[hidden] { display: none !important; }
.login-card {
  width: min(400px, 100%);
  display: grid;
  gap: 12px;
  padding: 36px;
  background: #fff;
  border: 1px solid #e2e7ef;
  border-radius: 18px;
  box-shadow: 0 18px 55px rgba(25, 42, 70, .12);
}
.login-brand {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #2457d6;
  color: #fff;
  font-weight: 700;
}
.login-card h1 { margin: 4px 0 0; font-size: 25px; }
.login-card p { margin: 0 0 12px; color: #697386; }
.login-card label { font-size: 13px; font-weight: 600; }
.login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #cfd7e3;
  border-radius: 8px;
  font: inherit;
}
.login-card input:focus { outline: 2px solid #b9cdfd; border-color: #2457d6; }
.login-error { min-height: 20px; color: #c73535; font-size: 13px; }
.sync-error .sync-dot { background: #d94848 !important; }
.current-user { color: var(--text-secondary); font-size: 12px; }
.form-hint { margin: 0 0 12px; color: var(--text-tertiary); font-size: 13px; }
.document-upload { display: grid; grid-template-columns: 180px minmax(220px, 1fr) auto; gap: 10px; align-items: center; }
.document-upload[hidden] { display: none; }
.document-upload select, .document-upload input { min-height: 38px; }
.document-list { display: grid; gap: 8px; margin-top: 14px; }
.document-item { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:10px 12px; border:1px solid var(--border); border-radius:8px; }
.document-item strong, .document-item span { display:block; }
.document-item strong { font-size:13px; }
.document-item span { margin-top:3px; color:var(--text-tertiary); font-size:11px; }
.empty-state.compact { padding:18px; }
@media (max-width: 760px) { .document-upload { grid-template-columns: 1fr; } }
