/* ==================== SSD 车间扫码追溯系统 - 现代商务风 UI ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* 主色调 - 深蓝商务 */
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --primary-light: #EFF6FF;
  --primary-dark: #1E40AF;
  /* 语义色 */
  --success: #16A34A;
  --success-bg: #F0FDF4;
  --error: #DC2626;
  --error-bg: #FEF2F2;
  --warning: #F59E0B;
  --warning-bg: #FFFBEB;
  --info: #0891B2;
  /* 中性色 */
  --bg: #F8FAFC;
  --bg-secondary: #F1F5F9;
  --card: #FFFFFF;
  --border: #E2E8F0;
  --border-light: #F1F5F9;
  --text: #1E293B;
  --text2: #64748B;
  --text3: #94A3B8;
  /* 阴影 */
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px 0 rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  /* 圆角 */
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  /* 侧边栏 */
  --sidebar-width: 240px;
  --sidebar-bg: #1E293B;
  --sidebar-bg-hover: #334155;
  --sidebar-text: #CBD5E1;
  --sidebar-text-active: #FFFFFF;
  --sidebar-accent: #3B82F6;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* ==================== 扫码反馈条 ==================== */
#scan-feedback {
  position: fixed; top: 0; left: 0; right: 0; height: 40px; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: #fff; transition: opacity 0.3s;
  backdrop-filter: blur(4px);
}
#scan-feedback.success { background: var(--success); }
#scan-feedback.duplicate { background: var(--warning); color: #1E293B; }
#scan-feedback.error { background: var(--error); }

/* ==================== 登录页 ==================== */
#login-page {
  display: flex; align-items: center; justify-content: center; height: 100vh;
  background: linear-gradient(135deg, #1E293B 0%, #0F172A 50%, #1E3A5F 100%);
  position: relative;
}
#login-page::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at top right, rgba(59,130,246,0.15), transparent 50%),
              radial-gradient(ellipse at bottom left, rgba(22,163,74,0.1), transparent 50%);
  pointer-events: none;
}
.login-card {
  background: var(--card); border-radius: var(--radius-xl); padding: 40px 48px;
  width: 420px; box-shadow: var(--shadow-lg); position: relative; z-index: 1;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.logo-icon {
  width: 56px; height: 56px; border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; font-size: 28px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 12px; box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 4px; font-weight: 700; }
.login-card .subtitle { font-size: 13px; color: var(--text2); text-align: center; }

/* 串口区 */
.serial-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--bg-secondary); border-radius: var(--radius);
}
.serial-row label { font-size: 12px; color: var(--text2); white-space: nowrap; font-weight: 600; }
.serial-row .serial-status { font-size: 12px; color: var(--text2); }

.serial-tip {
  font-size: 12px; color: var(--text2); line-height: 1.6;
  padding: 10px 14px; background: var(--primary-light); border-radius: var(--radius);
  margin-bottom: 16px; border-left: 3px solid var(--primary);
}

.divider { height: 1px; background: var(--border); margin-bottom: 20px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; margin-bottom: 6px; font-weight: 600; color: var(--text); }
.form-group input {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 14px; outline: none; transition: all 0.2s; background: var(--card);
}
.form-group input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.remember-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 20px;
  font-size: 13px; color: var(--text2);
}
.remember-row input { accent-color: var(--primary); width: 16px; height: 16px; }

.btn-login {
  width: 100%; padding: 12px; background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff; border: none; border-radius: var(--radius); font-size: 15px; font-weight: 700;
  cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(37,99,235,0.4); }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.server-status { text-align: center; font-size: 12px; margin-top: 12px; padding: 6px 0; border-radius: var(--radius-sm); }
.server-status.connecting { color: var(--primary); }
.server-status.online { color: var(--success); }
.server-status.offline { color: var(--error); }

/* ==================== 主页面 ==================== */
#main-page { display: none; height: 100vh; flex-direction: row; }

/* 侧边栏 */
.sidebar {
  width: var(--sidebar-width); height: 100vh; background: var(--sidebar-bg);
  display: flex; flex-direction: column; flex-shrink: 0; color: var(--sidebar-text);
  transition: width 0.3s;
}
.sidebar-header {
  display: flex; align-items: center; gap: 10px; padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header .logo-icon { width: 36px; height: 36px; font-size: 18px; margin: 0; }
.sidebar-title { font-size: 16px; font-weight: 700; color: #fff; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px; padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.user-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--sidebar-accent), var(--primary));
  color: #fff; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-info { overflow: hidden; }
.user-name { font-size: 14px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 12px; color: var(--text3); }
.user-role.admin { color: var(--warning); }

.sidebar-menu { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-menu::-webkit-scrollbar { width: 4px; }
.sidebar-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.menu-group-title {
  font-size: 11px; color: var(--text3); text-transform: uppercase;
  padding: 12px 20px 6px; letter-spacing: 0.5px; font-weight: 600;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  font-size: 14px; color: var(--sidebar-text); cursor: pointer;
  transition: all 0.15s; border-left: 3px solid transparent;
}
.menu-item:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-text-active); }
.menu-item.active {
  background: var(--sidebar-bg-hover); color: var(--sidebar-text-active);
  border-left-color: var(--sidebar-accent);
}
.menu-item .menu-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.menu-item .menu-badge {
  margin-left: auto; font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: var(--error); color: #fff;
}

.sidebar-footer { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.btn-logout {
  width: 100%; padding: 8px; background: transparent; border: 1px solid rgba(255,255,255,0.2);
  color: var(--sidebar-text); border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
  transition: all 0.2s;
}
.btn-logout:hover { background: var(--error); border-color: var(--error); color: #fff; }

/* 主内容区 */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* 顶部状态栏 */
.topbar {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: var(--card); border-bottom: 1px solid var(--border);
  flex-shrink: 0; box-shadow: var(--shadow-sm);
}
.topbar-title { font-size: 18px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.status-chip {
  font-size: 12px; padding: 4px 12px; border-radius: 20px;
  background: var(--bg-secondary); color: var(--text2); white-space: nowrap;
}
.status-chip.serial-on { background: var(--success-bg); color: var(--success); }
.status-chip.serial-off { background: var(--error-bg); color: var(--error); }

/* 视图容器 */
.view-container { flex: 1; overflow-y: auto; padding: 20px 24px; }
.view { max-width: 1200px; margin: 0 auto; }

/* ==================== 扫码作业视图 ==================== */
.config-bar {
  display: flex; align-items: flex-end; gap: 20px; padding: 16px 20px;
  background: var(--card); border-radius: var(--radius); margin-bottom: 16px;
  box-shadow: var(--shadow-sm); flex-wrap: wrap;
}
.config-item { display: flex; flex-direction: column; gap: 4px; }
.config-item label { font-size: 12px; color: var(--text2); font-weight: 600; }
.config-item select {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; min-width: 140px; background: var(--card); color: var(--text);
  outline: none; cursor: pointer;
}
.config-item select:focus { border-color: var(--primary); }
.config-item .serial-inline { font-size: 12px; color: var(--text2); }
.config-item .serial-inline.connected { color: var(--success); font-weight: 600; }

/* 扫码结果大字显示区 */
#scan-result-display {
  height: 140px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-secondary); border-radius: var(--radius); margin-bottom: 16px;
  transition: all 0.2s; box-shadow: var(--shadow-sm);
}
#scan-result-display .result-text {
  font-size: 72px; font-weight: 900; letter-spacing: 4px; user-select: none;
}
#scan-result-display.pass { background: var(--success); }
#scan-result-display.pass .result-text { color: #fff; }
#scan-result-display.ng { background: var(--error); }
#scan-result-display.ng .result-text { color: #fff; }
#scan-result-display.duplicate { background: var(--warning); }
#scan-result-display.duplicate .result-text { color: #1E293B; font-size: 42px; }
#scan-result-display.idle .result-text { color: var(--text3); font-size: 24px; font-weight: 500; }

/* 质量模式选择面板 */
.quality-panel {
  display: none; padding: 14px 20px; background: var(--warning-bg);
  border-radius: var(--radius); margin-bottom: 16px;
  align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px solid rgba(245,158,11,0.2);
}
.quality-panel.show { display: flex; }
.quality-panel .qp-label { font-size: 14px; font-weight: 700; color: var(--text); }
.quality-panel .qp-btn {
  padding: 8px 24px; font-size: 14px; font-weight: 700; border: 2px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer; transition: all 0.2s; opacity: 0.55;
}
.quality-panel .qp-btn:hover { opacity: 0.85; }
.quality-panel .qp-btn.active { opacity: 1; }
.quality-panel .qp-btn-pass.active { box-shadow: 0 0 0 2px var(--success); }
.quality-panel .qp-btn-pass { background: var(--success); color: #fff; }
.quality-panel .qp-btn-fail { background: var(--error); color: #fff; }
.quality-panel .qp-btn-fail.active { animation: pulse-red 1.2s infinite; }
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(220,38,38,0); }
}
.quality-panel .qp-defect-select {
  padding: 6px 10px; border: 2px solid var(--error); border-radius: var(--radius-sm);
  font-size: 13px; min-width: 220px; background: var(--card);
}
.quality-panel .qp-info { font-size: 13px; color: var(--text2); }
.quality-panel .qp-current { font-size: 14px; font-weight: 600; }
.quality-panel .qp-current.pass { color: var(--success); }
.quality-panel .qp-current.fail { color: var(--error); }

/* 日志区 */
.log-section {
  background: var(--card); border-radius: var(--radius); padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}
.log-section .log-header { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.log-box {
  height: 240px; overflow-y: auto; background: var(--bg-secondary);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace; font-size: 12px; line-height: 1.7;
}
.log-box::-webkit-scrollbar { width: 6px; }
.log-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.log-box .log-success { color: var(--success); }
.log-box .log-error { color: var(--error); }
.log-box .log-warning { color: var(--warning); }
.log-box .log-info { color: var(--text); }

/* ==================== 卡片通用 ==================== */
.card {
  background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 16px 24px; border-bottom: 1px solid var(--border-light);
  display: flex; justify-content: space-between; align-items: center;
}
.card-header h2 { font-size: 16px; font-weight: 700; }
.card-body { padding: 24px; }

/* ==================== 表格 ==================== */
.tab-bar { display: flex; gap: 4px; margin-bottom: 16px; }
.tab-bar .tab {
  padding: 6px 16px; border: none; border-radius: var(--radius-sm); font-size: 13px;
  cursor: pointer; background: var(--bg-secondary); color: var(--text2);
  transition: all 0.15s;
}
.tab-bar .tab:hover { background: var(--border-light); }
.tab-bar .tab.active { background: var(--primary); color: #fff; }

.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th, .stats-table td {
  padding: 10px 14px; text-align: center; border-bottom: 1px solid var(--border-light);
}
.stats-table th { background: var(--bg-secondary); font-weight: 700; color: var(--text2); }
.stats-table tbody tr:hover { background: var(--bg-secondary); }
.stats-table .total-row { font-weight: 700; background: var(--primary-light); }

/* ==================== 按钮 ==================== */
.btn {
  padding: 8px 18px; border: none; border-radius: var(--radius-sm); font-size: 13px;
  font-weight: 600; cursor: pointer; transition: all 0.15s; display: inline-flex;
  align-items: center; gap: 4px;
}
.btn:hover { opacity: 0.88; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-default { background: var(--bg-secondary); color: var(--text); }
.btn-info { background: var(--info); color: #fff; }
.btn-text { background: transparent; color: var(--text2); }

.btn-sm { padding: 5px 12px; font-size: 12px; border: none; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; }
.btn-refresh { background: var(--bg-secondary); color: var(--text); }
.btn-connect { background: var(--primary); color: #fff; }
.btn-disconnect { background: var(--error); color: #fff; }

/* ==================== 设置区域 ==================== */
.settings-section-title {
  font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 2px solid var(--border-light);
}
.station-config {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.station-label { font-size: 13px; font-weight: 600; white-space: nowrap; }
.station-input {
  flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; outline: none;
}
.station-input:focus { border-color: var(--primary); }

/* 声音设置项 */
.sound-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--border-light); border-radius: var(--radius); margin-bottom: 8px;
  background: var(--card); transition: all 0.15s;
}
.sound-item:hover { border-color: var(--border); }
.sound-item.disabled { opacity: 0.5; background: var(--bg-secondary); }
.sound-item .sound-toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; cursor: pointer; }
.sound-item .sound-toggle input { opacity: 0; width: 0; height: 0; }
.sound-item .sound-toggle .slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 11px; transition: 0.2s;
}
.sound-item .sound-toggle .slider:before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: var(--shadow-sm);
}
.sound-item .sound-toggle input:checked + .slider { background: var(--primary); }
.sound-item .sound-toggle input:checked + .slider:before { transform: translateX(18px); }
.sound-item .sound-label { flex-shrink: 0; width: 130px; font-size: 13px; font-weight: 500; }
.sound-item .sound-volume-wrap { flex: 1; display: flex; align-items: center; gap: 8px; }
.sound-item .sound-volume {
  flex: 1; height: 4px; -webkit-appearance: none; appearance: none;
  background: var(--border); border-radius: 2px; outline: none;
}
.sound-item .sound-volume::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px;
  background: var(--primary); border-radius: 50%; cursor: pointer; box-shadow: var(--shadow-sm);
}
.sound-item .sound-volume::-moz-range-thumb {
  width: 16px; height: 16px; background: var(--primary); border-radius: 50%;
  cursor: pointer; border: none;
}
.sound-item .sound-volume-text { width: 42px; text-align: right; font-size: 12px; color: var(--text2); }
.sound-item .sound-preview {
  padding: 4px 12px; font-size: 12px; border: 1px solid var(--primary);
  color: var(--primary); background: transparent; border-radius: var(--radius-sm);
  cursor: pointer; flex-shrink: 0; font-weight: 600;
}
.sound-item .sound-preview:hover { background: var(--primary-light); }
.sound-item.disabled .sound-preview { color: var(--text3); border-color: var(--border); cursor: not-allowed; }

/* ==================== 弹窗 ==================== */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15,23,42,0.5); z-index: 900;
  align-items: center; justify-content: center; backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--card); border-radius: var(--radius-lg); width: 480px; max-height: 80vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 16px 24px; border-bottom: 1px solid var(--border-light);
  font-size: 16px; font-weight: 700;
}
.modal-body { padding: 20px 24px; flex: 1; overflow-y: auto; }
.modal-footer { padding: 12px 24px; border-top: 1px solid var(--border-light); display: flex; gap: 8px; }
.confirm-modal .modal { width: 400px; }
.confirm-msg { font-size: 14px; line-height: 1.7; padding: 8px 0; }
.confirm-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ==================== iframe 管理视图 ==================== */
.admin-iframe {
  width: 100%; height: calc(100vh - 56px - 40px - 2px);
  border: none; border-radius: var(--radius); background: #fff;
}

/* ==================== 响应式 ==================== */
@media (max-width: 1024px) {
  .topbar-right .status-chip { font-size: 11px; padding: 3px 8px; }
}
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-title, .user-info, .menu-item .menu-text, .menu-group-title, .btn-logout { display: none; }
  .sidebar-user { justify-content: center; }
  .menu-item { justify-content: center; padding: 12px; }
  .topbar { padding: 0 12px; }
  .topbar-right { gap: 4px; }
  .status-chip { font-size: 10px; padding: 2px 6px; }
  .view-container { padding: 12px; }
  .config-bar { gap: 10px; padding: 12px; }
  .config-item select { min-width: 100px; }
  #scan-result-display { height: 100px; }
  #scan-result-display .result-text { font-size: 48px; }
}
