/* ============= 基础重置 ============= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: #1f2937;
  background: #f5f7fb;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

/* ============= 顶栏 ============= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 24px;
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.stat-pill {
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.stat-pill.warn {
  background: rgba(245, 158, 11, 0.95);
}

.stat-pill.danger {
  background: rgba(220, 38, 38, 0.95);
}

.stat-pill.mandatory {
  background: #dc2626;
  color: #fff;
  font-weight: 700;
  animation: badgePulse 1.5s ease-in-out infinite;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============= 按钮 ============= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn.primary {
  background: #fff;
  color: #2563eb;
}

.btn.primary:hover {
  background: #f3f4f6;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn.dark {
  background: #1f2937;
  color: #fff;
}

.btn.dark:hover {
  background: #111827;
}

.btn.light {
  background: #fff;
  color: #1f2937;
  border: 1px solid #d1d5db;
}

.btn.light:hover {
  background: #f9fafb;
}

.btn.danger {
  background: #fff;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.btn.danger:hover {
  background: #fef2f2;
}

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

/* ============= 布局 ============= */
.layout {
  display: flex;
  height: calc(100vh - 60px);
}

.sidebar {
  width: 360px;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.search-bar {
  padding: 12px;
  border-bottom: 1px solid #e5e7eb;
}

.search-bar input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.search-bar input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-bar {
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  border-bottom: 1px solid #e5e7eb;
}

.chip {
  padding: 4px 12px;
  background: #f3f4f6;
  border-radius: 14px;
  font-size: 12px;
  color: #4b5563;
  transition: all 0.15s;
}

.chip:hover {
  background: #e5e7eb;
}

.chip.active {
  background: #2563eb;
  color: #fff;
}

.device-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

/* ============= 设备卡片 ============= */
.device-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  border-left: 4px solid transparent;
  transition: background 0.15s;
}

.device-card:hover {
  background: #f9fafb;
}

.device-card.selected {
  background: #eff6ff;
  border-left-color: #2563eb;
}

.device-card.status-soon {
  background: #fffbeb;
}

.device-card.status-soon.selected {
  background: #fef3c7;
}

.device-card.status-expired {
  background: #fef2f2;
}

.device-card.status-expired.selected {
  background: #fee2e2;
}

/* 强检特殊高亮 */
.device-card.status-mandatory-expired {
  background: #fef2f2;
  border-left: 4px solid #dc2626 !important;
  animation: mandatoryPulse 2s ease-in-out infinite;
}

.device-card.status-mandatory-expired.selected {
  background: #fee2e2;
}

.device-card.status-mandatory-soon {
  background: #fff7ed;
  border-left: 4px solid #ea580c !important;
}

.device-card.status-mandatory-soon.selected {
  background: #ffedd5;
}

@keyframes mandatoryPulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(220, 38, 38, 0); }
  50% { box-shadow: inset 4px 0 0 0 rgba(220, 38, 38, 0.4); }
}

.mandatory-tag {
  display: inline-block;
  padding: 1px 6px;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 2px;
}

.mandatory-inline {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 10px;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}

.badge.mandatory-expired {
  background: #dc2626;
  color: #fff;
  animation: badgePulse 1.5s ease-in-out infinite;
}

.badge.mandatory-soon {
  background: #ea580c;
  color: #fff;
}

@keyframes badgePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.device-card-main {
  flex: 1;
  min-width: 0;
}

.device-name {
  font-weight: 600;
  color: #1f2937;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}

.device-meta {
  font-size: 12px;
  color: #6b7280;
  display: flex;
  gap: 8px;
}

.device-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-card-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  margin-left: 8px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge.ok {
  background: #d1fae5;
  color: #065f46;
}

.badge.soon {
  background: #fef3c7;
  color: #92400e;
}

.badge.expired {
  background: #fee2e2;
  color: #991b1b;
}

.days {
  font-size: 11px;
  color: #6b7280;
}

/* ============= 内容区 ============= */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: #9ca3af;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.empty-state h2 {
  color: #4b5563;
  margin-bottom: 8px;
  font-weight: 500;
}

/* ============= 详情页 ============= */
.detail {
  max-width: 1100px;
  margin: 0 auto;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.detail-title h1 {
  font-size: 22px;
  margin-bottom: 6px;
  color: #111827;
}

.detail-title .sub {
  color: #6b7280;
  font-size: 13px;
}

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

.section {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.section h3 {
  font-size: 15px;
  color: #111827;
  margin-bottom: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section h3 .count {
  color: #6b7280;
  font-weight: normal;
  font-size: 12px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-item .label {
  font-size: 12px;
  color: #6b7280;
}

.info-item .value {
  color: #111827;
  font-weight: 500;
  word-break: break-all;
}

.info-item .value.empty {
  color: #9ca3af;
  font-weight: normal;
  font-style: italic;
}

.info-item .value.expired {
  color: #991b1b;
}

.info-item .value.soon {
  color: #92400e;
}

/* 设备状态徽章 (详情页头部) */
.status-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
  border: 1px solid;
}
.status-badge.ok      { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }
.status-badge.soon    { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.status-badge.expired { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

/* ============= 文档 tab ============= */
.doc-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 16px;
  overflow-x: auto;
}

.doc-tab {
  padding: 8px 14px;
  border-radius: 6px 6px 0 0;
  font-size: 13px;
  color: #6b7280;
  font-weight: 500;
  position: relative;
  white-space: nowrap;
}

.doc-tab:hover {
  color: #2563eb;
  background: #eff6ff;
}

.doc-tab.active {
  color: #2563eb;
  border-bottom: 2px solid #2563eb;
}

.doc-tab .badge-mini {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  background: #2563eb;
  color: #fff;
  font-size: 10px;
  border-radius: 8px;
  font-weight: 600;
}

.doc-tab .badge-mini.warn {
  background: #f59e0b;
}

.doc-tab .badge-mini.danger {
  background: #dc2626;
}

.doc-tab-content {
  min-height: 120px;
}

.doc-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #f9fafb;
  border-radius: 8px;
  border-left: 4px solid #d1d5db;
}

.doc-item.status-soon {
  border-left-color: #f59e0b;
  background: #fffbeb;
}

.doc-item.status-expired {
  border-left-color: #dc2626;
  background: #fef2f2;
}

.doc-item-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.doc-item-main {
  flex: 1;
  min-width: 0;
}

.doc-item-name {
  font-weight: 500;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-item-meta {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.doc-item-meta .expiry {
  font-weight: 500;
}

.doc-item-meta .expiry.expired {
  color: #991b1b;
}

.doc-item-meta .expiry.soon {
  color: #92400e;
}

.doc-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.doc-empty {
  text-align: center;
  padding: 30px 20px;
  color: #9ca3af;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px dashed #d1d5db;
}

.doc-empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

/* ============= 表单 ============= */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
}

.form-field label .req {
  color: #dc2626;
  margin-left: 2px;
}

.form-field input,
.form-field textarea,
.form-field select {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.form-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid #e5e7eb;
}

/* 上传对话框 */
.upload-hint {
  background: #eff6ff;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: #1e40af;
  margin-bottom: 12px;
}

/* ============= 工具类 ============= */
.hidden {
  display: none !important;
}

/* 客户只读徽章 */
.readonly-badge {
  display: inline-block;
  padding: 5px 12px;
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

/* 发布按钮 */
#btn-publish {
  background: #16a34a;
  color: #fff;
  border: none;
}
#btn-publish:hover {
  background: #15803d;
}
#btn-publish:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

.muted {
  color: #9ca3af;
}

.flex-1 {
  flex: 1;
}

.gap-8 {
  gap: 8px;
}

/* 滚动条 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* 响应式 */
@media (max-width: 900px) {
  .info-grid {
    grid-template-columns: 1fr 1fr;
  }
  .sidebar {
    width: 280px;
  }
}

@media (max-width: 600px) {
  .info-grid {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .sidebar {
    width: 100%;
    height: 200px;
  }
  .layout {
    flex-direction: column;
  }
  .topbar {
    flex-direction: column;
    height: auto;
    padding: 12px;
    gap: 8px;
  }
  .topbar-left, .topbar-right {
    width: 100%;
    justify-content: center;
  }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 999;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: toastIn 0.2s ease;
}

.toast.success { background: #16a34a; }
.toast.error { background: #dc2626; }
.toast.warn { background: #f59e0b; }

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
