* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #f7faff 0%, #f2f5fb 40%, #eef2f7 100%);
  color: #111827;
}

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 20px 26px;
}

.topbar {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-settings-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d8e0ea;
  background: #fff;
}

.top-settings-btn svg {
  width: 21px;
  height: 21px;
  fill: #64748b;
}

.top-settings-btn:hover {
  border-color: #bfd7ff;
  background: #f8fbff;
}

.brand-logo {
  width: 88px;
  height: 88px;
  object-fit: contain;
}

.brand-text h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0.2px;
}

.brand-text p {
  margin: 2px 0 0;
  color: #6b7280;
  font-size: 14px;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #e6ebf2;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(26, 46, 80, 0.06);
}

.toolbar {
  display: block;
  padding: 14px;
  margin-bottom: 12px;
}

.folder-drop-zone {
  border: 2px dashed #8ec5ff;
  border-radius: 12px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #fbfdff;
  cursor: pointer;
  user-select: none;
  transition: all 0.18s ease;
}

.folder-drop-zone:hover {
  background: #f4f8ff;
  border-color: #5ca2f6;
}

.folder-drop-zone.dragover {
  border-color: #2563eb;
  background: #eef5ff;
}

.drop-icon {
  width: 30px;
  height: 30px;
  color: #94a3b8;
}

.drop-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.drop-main {
  font-size: 18px;
  font-weight: 500;
  color: #475569;
  letter-spacing: 0.2px;
}

.drop-sub {
  font-size: 14px;
  color: #64748b;
}

input,
textarea,
button {
  border: 1px solid #d8e0ea;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 14px;
  transition: all 0.18s ease;
}

#rootPath,
#pathHistoryDropdown {
  display: none !important;
}

.history-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid #dbe4f0;
  border-radius: 10px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
  z-index: 30;
  max-height: 220px;
  overflow-y: auto;
}

.history-dropdown.hidden {
  display: none;
}

.history-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 8px 10px 6px;
  border-bottom: 1px solid #eef2f7;
}

.history-clear-btn {
  border: none;
  background: transparent;
  color: #2563eb;
  font-size: 12px;
  padding: 0;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border-bottom: 1px solid #eef2f7;
  padding: 2px 6px 2px 0;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item-text {
  border: none;
  background: transparent;
  text-align: left;
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: #1f2937;
}

.history-item-text:hover {
  background: #f5f9ff;
}

.history-delete-btn {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #94a3b8;
  padding: 0;
  margin-right: 4px;
}

.history-delete-btn:hover {
  background: #fee2e2;
  color: #b91c1c;
}

input,
textarea {
  background: #fff;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #7aa9ff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

button {
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  color: #1f2937;
}

.ghost:hover {
  background: #f8fbff;
  border-color: #bfd7ff;
}

.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: white;
}

.primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.summary {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  position: sticky;
  top: 10px;
  z-index: 20;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.46) 0%,
    rgba(255, 255, 255, 0.3) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow:
    0 8px 20px rgba(15, 23, 42, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(8px) saturate(118%);
  -webkit-backdrop-filter: blur(8px) saturate(118%);
  transition:
    background 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease,
    backdrop-filter 0.22s ease,
    -webkit-backdrop-filter 0.22s ease;
}

.summary.summary-scrolled {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.54) 0%,
    rgba(255, 255, 255, 0.36) 100%
  );
  border-color: rgba(255, 255, 255, 0.36);
  box-shadow:
    0 10px 26px rgba(15, 23, 42, 0.11),
    inset 0 1px 0 rgba(255, 255, 255, 0.52);
  backdrop-filter: blur(11px) saturate(124%);
  -webkit-backdrop-filter: blur(11px) saturate(124%);
}

.summary.summary-scrolling {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.42) 100%
  );
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow:
    0 12px 30px rgba(15, 23, 42, 0.13),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
  backdrop-filter: blur(13px) saturate(128%);
  -webkit-backdrop-filter: blur(13px) saturate(128%);
}

.summary-left {
  display: flex;
  gap: 24px;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.summary-label {
  font-size: 12px;
  color: #64748b;
}

.summary-item b {
  font-size: 24px;
  color: #0f172a;
  line-height: 1.1;
}

.summary-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.action-btn {
  min-width: 96px;
}

.groups {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.group {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #e6ebf2;
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 6px 18px rgba(26, 46, 80, 0.04);
}

.group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-weight: 700;
  color: #0f172a;
}

.group-selected-amount {
  font-size: 14px;
  font-weight: 400;
  color: #111827;
}

.group-title .line {
  flex: 1;
  height: 1px;
  background: #d4deea;
}

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

.invoice-header {
  display: grid;
  grid-template-columns: 44px 140px 120px minmax(180px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr);
  gap: 10px;
  padding: 2px 10px 6px;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
}

.header-sort-btn {
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  padding: 0;
  border-radius: 0;
}

.header-sort-btn:hover {
  color: #1d4ed8;
}

.header-check-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  cursor: pointer;
}

.header-check-wrap input {
  margin: 0;
}

.invoice-item {
  background: #f9fbff;
  border: 1px solid #e7edf7;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  cursor: pointer;
}

.item-check-wrap {
  width: 44px;
  min-height: 44px;
  margin: -10px 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.item-check-wrap input {
  margin: 0;
}

.invoice-item:hover {
  border-color: #cddcf5;
  box-shadow: 0 6px 14px rgba(59, 130, 246, 0.08);
}

.invoice-item.dragging {
  opacity: 0.6;
}

.item-main {
  display: grid;
  grid-template-columns: 140px 120px minmax(180px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr);
  gap: 10px;
}

.item-main > div {
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.warn {
  font-size: 12px;
  color: #b45309;
}

.warn-row {
  margin: -4px 0 2px 34px;
  font-size: 12px;
  color: #b45309;
}

#previewDialog {
  width: min(1180px, 95vw);
  border: none;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 24px 52px rgba(2, 8, 23, 0.32);
}

#previewDialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

#settingsDialog {
  width: min(520px, 92vw);
  border: none;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 24px 52px rgba(2, 8, 23, 0.32);
}

#settingsDialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.settings-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #1f2937;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.dialog-head {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid #e8edf4;
  background: #f9fbff;
}

#previewTitle {
  margin: 0;
}

.dialog-right {
  position: relative;
  height: 38px;
}

.preview-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.nav-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 8px;
}

.nav-btn svg {
  width: 18px;
  height: 18px;
  fill: #334155;
}

.nav-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#previewCount {
  min-width: 58px;
  text-align: center;
  font-size: 13px;
  color: #475569;
}

#closePreview {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.close-icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.close-icon-btn svg {
  width: 16px;
  height: 16px;
  fill: #334155;
}

.dialog-body {
  min-height: 74vh;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
}

.preview-image-wrap {
  width: 100%;
  height: 100%;
  border-right: 1px solid #e8edf4;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#previewImage {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.edit-panel {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.edit-panel label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: #475569;
  font-size: 13px;
}

.edit-panel textarea {
  min-height: 90px;
  resize: vertical;
}

.empty-state {
  padding: 46px 20px;
  text-align: center;
  color: #64748b;
  background: rgba(255, 255, 255, 0.85);
  border: 1px dashed #ced9e8;
  border-radius: 14px;
}

.app-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 24px rgba(2, 8, 23, 0.32);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.app-toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 960px) {
  .drop-main {
    font-size: 16px;
  }

  .summary {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .summary-left {
    gap: 16px;
  }

  .summary-actions {
    width: 100%;
  }

  .summary-actions .action-btn {
    width: 100%;
  }

  .item-main {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .invoice-header {
    display: none;
  }

  .invoice-item {
    grid-template-columns: 24px 1fr;
  }

  .dialog-body {
    grid-template-columns: 1fr;
  }

  .dialog-head {
    grid-template-columns: 1fr;
  }

  .preview-image-wrap {
    min-height: 42vh;
    border-right: none;
    border-bottom: 1px solid #e8edf4;
  }
}
