@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;700&display=swap');

:root {
  --bg: #0b0e14;
  --surface: #151921;
  --surface-2: #1e2330;
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.15);
  --ink: #f8fafc;
  --muted: #94a3b8;
  --accent: #4f46e5;
  --accent-hover: #6366f1;
  --accent-dim: rgba(79,70,229,0.15);
  --success: #10b981;
  --danger: #f43f5e;
  --danger-dim: rgba(244,63,94,0.12);
  --warning: #f59e0b;
  --sidebar-w: 220px;
  --transition: all 0.18s cubic-bezier(0.4,0,0.2,1);
}

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

body {
  font-family: 'Inter','Noto Sans SC',system-ui,-apple-system,sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── LOGIN ── */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 0% 0%, rgba(79,70,229,0.12) 0%, transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(16,185,129,0.08) 0%, transparent 40%),
    var(--bg);
}

.login-card {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-card .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-card .logo-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 20px;
  box-shadow: 0 6px 14px var(--accent-dim);
}

.login-card h1 { font-size: 18px; font-weight: 700; }
.login-card .subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── APP SHELL ── */
.app { display: flex; min-height: 100vh; }

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  background: rgba(21,25,33,0.92);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding: 20px 0;
}

.sidebar-brand {
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand .brand-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 18px;
  margin-bottom: 10px;
}

.sidebar-brand h2 { font-size: 13px; font-weight: 700; line-height: 1.3; }
.sidebar-brand p { font-size: 11px; color: var(--muted); margin-top: 2px; }

.nav-section {
  padding: 0 8px;
  margin-bottom: 4px;
}

/* 修复：nav-label 左侧贴边问题 */
.nav-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 6px 10px 4px;
  display: block;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-dim); color: var(--accent-hover); font-weight: 600; }
.nav-item .icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 10px 8px;
  border-top: 1px solid var(--border);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--surface-2);
}

.user-avatar {
  width: 28px; height: 28px;
  background: var(--accent-dim);
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--accent-hover);
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-info .name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: 10px; color: var(--muted); }

.logout-btn {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  font-size: 15px; padding: 4px; border-radius: 6px;
  transition: color 0.15s;
}
.logout-btn:hover { color: var(--danger); }

/* ── MAIN ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
}

.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.page-header p { font-size: 13px; color: var(--muted); margin-top: 3px; }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--border-hover); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; }

/* ── GRID ── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start; /* 修复：防止两侧卡片等高拉伸 */
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}

/* ── DROPZONE（修复：压缩高度）── */
.dropzone {
  border: 2px dashed var(--border-hover);
  border-radius: 12px;
  padding: 24px 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: var(--transition);
  background: var(--surface-2);
  margin-bottom: 14px;
}
.dropzone:hover, .dropzone.dragging {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent-hover);
}
.dropzone .dz-icon { font-size: 26px; margin-bottom: 6px; }
.dropzone .dz-text { font-size: 13px; font-weight: 500; }
.dropzone .dz-hint { font-size: 11px; margin-top: 3px; opacity: 0.7; }

/* ── FORMS ── */
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 11px; font-weight: 500; color: var(--muted); }

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder { color: var(--muted); }
select option { background: var(--surface-2); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  border: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(79,70,229,0.4); }
.btn-secondary { background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-hover); }
.btn-danger { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(244,63,94,0.2); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-success { background: rgba(16,185,129,0.15); color: var(--success); border: 1px solid rgba(16,185,129,0.2); }
.btn-success:hover { background: var(--success); color: white; }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 7px; }
.btn-full { width: 100%; }
.btn:active { transform: scale(0.97); }

/* ── TABLE ── */
.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--surface-2);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.025); }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}
.badge-accent { background: var(--accent-dim); color: var(--accent-hover); }
.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }

/* ── ALERTS ── */
.alert { padding: 10px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; }
.alert-error { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(244,63,94,0.2); }
.alert-success { background: rgba(16,185,129,0.12); color: var(--success); border: 1px solid rgba(16,185,129,0.2); }

/* ── PREVIEW ── */
.preview-img {
  max-width: 260px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-top: 12px;
}

/* ── EDIT PANEL ── */
.edit-panel {
  display: none;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 14px;
  margin-top: 8px;
  border: 1px solid var(--border);
}
.edit-panel.open { display: block; }

/* ── MISC ── */
.hidden { display: none; }
.ml-auto { margin-left: auto; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
  .main { margin-left: 0; padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ---- tool panel layout refinements ---- */
.tool-grid {
  display: grid;
  gap: 18px;
  align-items: start;
}

.tool-grid-upload {
  grid-template-columns: minmax(360px, 540px) minmax(420px, 620px);
  justify-content: start;
}

.tool-grid-export {
  grid-template-columns: 360px 420px;
  justify-content: start;
  gap: 24px;
}

.tool-card {
  width: 100%;
  max-width: none !important;
}

.tool-card-export,
.tool-card-import {
  align-self: start;
}

/* 上传识别页：压缩模块高度，增加内部留白层次 */
.tool-grid-upload .card {
  padding: 18px;
}

.tool-grid-upload .dropzone {
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.tool-grid-upload .stack {
  gap: 8px;
}

.tool-grid-upload .form-group {
  gap: 4px;
}

.tool-grid-upload .grid-2 {
  gap: 10px;
  margin-bottom: 0;
}

.tool-grid-upload input,
.tool-grid-upload select {
  height: 38px;
}

.tool-grid-upload .btn,
.tool-grid-export .btn {
  height: 38px;
}

/* 导出页：别拉太开，卡片像工具模块一样靠近 */
.tool-grid-export {
  margin-top: 6px;
}

.tool-grid-export .card {
  padding: 18px;
}

.tool-grid-export .stack {
  gap: 10px;
}

.tool-grid-export .form-group {
  gap: 4px;
}

.tool-grid-export .card .form-label {
  margin-bottom: 2px;
}

/* 左侧标题再留一点边距 */
.nav-label {
  padding-left: 14px;
}

.nav-section {
  padding-left: 10px;
  padding-right: 10px;
}

/* 页面内容别无限摊宽 */
#page-upload,
#page-export,
#page-settings,
#page-shops,
#page-users,
#page-password {
  max-width: 1180px;
}

/* 记录列表筛选条也收紧一点 */
#page-records > .card:first-of-type {
  max-width: 760px;
}

@media (max-width: 1100px) {
  .tool-grid-upload {
    grid-template-columns: 1fr;
    max-width: 760px;
  }
  .tool-grid-export {
    grid-template-columns: 1fr;
    max-width: 760px;
  }
}

/* ---- modal confirm ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 6, 14, 0.65);
  backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(460px, calc(100vw - 32px));
  background: #f4f8f7;
  color: #0f172a;
  border-radius: 24px;
  padding: 30px 28px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.32);
}
.modal-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 14px;
}
.modal-message {
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 28px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}
.modal-actions .btn {
  min-width: 120px;
  height: 52px;
  border-radius: 999px;
  font-size: 16px;
}
.modal-actions .btn-secondary {
  background: #8ee7df;
  border: none;
  color: #0f172a;
}
.modal-actions .btn-danger {
  background: #0b7a73;
  border: none;
  color: white;
}
.modal-actions .btn-danger:hover {
  background: #08645f;
}

/* ---- logo + theme ---- */
.brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.logo-icon, .brand-icon {
  overflow: hidden;
}

.theme-toggle {
  margin-bottom: 10px;
}

html[data-theme='light'] {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --border: rgba(15, 23, 42, 0.08);
  --border-hover: rgba(15, 23, 42, 0.16);
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-dim: rgba(79, 70, 229, 0.10);
  --success: #059669;
  --danger: #e11d48;
  --danger-dim: rgba(225, 29, 72, 0.10);
  --warning: #d97706;
}

html[data-theme='light'] body {
  background:
    radial-gradient(circle at 0% 0%, rgba(79,70,229,0.06) 0%, transparent 30%),
    radial-gradient(circle at 100% 100%, rgba(16,185,129,0.05) 0%, transparent 30%),
    var(--bg);
}

html[data-theme='light'] .sidebar {
  background: rgba(255,255,255,0.82);
}

html[data-theme='light'] .btn-primary {
  color: #fff;
}

html[data-theme='light'] .modal-panel {
  background: #ffffff;
  color: #0f172a;
}

html[data-theme='light'] .modal-actions .btn-secondary {
  background: #d8fff6;
  color: #0f172a;
}

html[data-theme='light'] .modal-actions .btn-danger {
  background: #0b7a73;
  color: #fff;
}

/* ---- image preview modal ---- */
.image-modal-panel {
  position: relative;
  z-index: 1;
  width: min(960px, calc(100vw - 40px));
  max-height: calc(100vh - 48px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.4);
  overflow: hidden;
}
.image-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.image-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font-size: 16px;
}
.image-modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  max-height: calc(100vh - 140px);
  overflow: auto;
  background: rgba(0,0,0,0.08);
}
.image-modal-body img {
  max-width: 100%;
  max-height: calc(100vh - 180px);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  display: block;
}

/* ---- inline edit row ---- */
.edit-row.hidden { display: none; }
.edit-row-cell {
  padding: 0 !important;
  background: transparent !important;
}
.inline-edit-panel {
  margin: 0;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
}
.edit-panel-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}
.edit-actions {
  align-self: end;
  justify-content: flex-end;
}
.record-row td {
  border-bottom-color: rgba(255,255,255,0.05);
}
html[data-theme='light'] .record-row td {
  border-bottom-color: rgba(15,23,42,0.06);
}

/* ---- summary row ---- */
.summary-row td {
  background: color-mix(in srgb, var(--accent-dim) 75%, transparent);
  font-weight: 600;
}
html[data-theme='light'] .summary-row td {
  background: rgba(79, 70, 229, 0.08);
}

/* ---- hover polish ---- */
.btn,
.nav-item,
.image-modal-close,
.logout-btn,
input,
select,
.dropzone {
  transition:
    background-color .22s ease,
    border-color .22s ease,
    color .22s ease,
    box-shadow .22s ease,
    transform .18s ease,
    opacity .22s ease;
}

.btn-secondary:hover {
  background: color-mix(in srgb, var(--surface-2) 82%, var(--accent) 18%);
  color: var(--ink);
}

.btn-danger:hover {
  box-shadow: 0 10px 22px rgba(244, 63, 94, 0.18);
  transform: translateY(-1px);
}

.btn-success:hover {
  box-shadow: 0 10px 22px rgba(16, 185, 129, 0.16);
  transform: translateY(-1px);
}

.nav-item:hover {
  box-shadow: inset 0 0 0 1px var(--border-hover);
}

.image-modal-close:hover,
.logout-btn:hover {
  background: var(--surface-2);
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .nav-item,
  .image-modal-close,
  .logout-btn,
  input,
  select,
  .dropzone {
    transition: none !important;
  }
}
