:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --ink: #243036;
  --muted: #68757d;
  --line: #dfe5e8;
  --accent: #0d7c66;
  --accent-dark: #0a6957;
  --accent-soft: #e2f2ec;
  --warn: #b2590f;
  --warn-soft: #fceddc;
  --shoot: #2f6ea8;
  --shoot-soft: #e4eef7;
  --danger: #a83a3a;
  --shadow: 0 1px 2px rgba(20, 32, 38, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(238, 242, 244, 0.92);
}

.login-box {
  width: 100%;
  max-width: 340px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(20, 32, 38, 0.12);
}

.login-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.login-head h2 {
  margin: 0;
  font-size: 18px;
}

.login-head p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.login-box input {
  margin-bottom: 10px;
}

.login-box .btn {
  width: 100%;
}

.login-error {
  margin: 0 0 10px;
  color: var(--danger);
  font-size: 13px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(36, 48, 54, 0.45);
}

.modal-box {
  width: 100%;
  max-width: 390px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(20, 32, 38, 0.22);
}

.record-editor-box {
  max-width: 520px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.type-modal-segmented {
  width: 100%;
  display: flex;
}

.type-modal-segmented button {
  flex: 1;
}

#syncModal,
#typeModal {
  z-index: 96;
}

#recordEditorModal {
  z-index: 92;
}

.modal-box h2 {
  margin: 0;
  font-size: 18px;
}

.modal-summary {
  margin: 0;
  padding: 9px 10px;
  border-radius: 6px;
  background: #f1f5f6;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.sync-folder-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  font-weight: 600;
  cursor: pointer;
}

.sync-folder-option input {
  width: auto;
  min-height: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.lan-sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lan-sync-actions .btn {
  flex: 1 1 auto;
}

.lan-sync-note,
.lan-sync-status {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.lan-sync-note {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--warn-soft);
  color: var(--warn);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

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

.month-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.month-control .month-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.month-control select {
  width: auto;
  min-width: 128px;
  min-height: 36px;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 20px 48px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.stat-value {
  display: block;
  margin-top: 5px;
  font-size: 21px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value.warn {
  color: var(--warn);
}

.stat-button {
  width: 100%;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.stat-button:hover {
  border-color: var(--accent);
}

.stat-button .stat-value {
  color: var(--accent-dark);
}

.stat-value.shoot {
  color: var(--shoot);
}

.workspace {
  display: block;
  gap: 18px;
  align-items: start;
}

.form-panel,
.list-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-panel {
  padding: 18px;
}

.form-panel h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.field label,
.field .label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}

textarea {
  min-height: 130px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(13, 124, 102, 0.25);
  outline-offset: 0;
  border-color: var(--accent);
}

.parse-status {
  grid-column: 1 / -1;
  padding: 8px 10px;
  border: 1px solid #b7dccd;
  border-radius: 6px;
  background: #eef7f2;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 600;
}

.segmented {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: #edf1f2;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: fit-content;
}

.segmented button {
  min-height: 32px;
  padding: 5px 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(20, 32, 38, 0.14);
}

.paid-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  cursor: pointer;
  width: fit-content;
}

.paid-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.paid-switch .slider {
  position: relative;
  width: 38px;
  height: 22px;
  flex: 0 0 38px;
  background: #c6cfd4;
  border-radius: 999px;
  transition: background 0.15s ease;
}

.paid-switch .slider::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}

.paid-switch input:checked + .slider {
  background: var(--accent);
}

.paid-switch input:checked + .slider::before {
  transform: translateX(16px);
}

.paid-switch .switch-text {
  font-weight: 600;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}

.btn:hover {
  background: #f7f9fa;
  border-color: #cbd4d8;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

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

.btn.danger:hover {
  background: #fdf3f3;
  border-color: #e3baba;
}

.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  flex: 0 0 34px;
}

.icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
}

.icon-wrap svg {
  width: 16px;
  height: 16px;
  display: block;
}

.icon-btn > svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  display: block;
  pointer-events: none;
}

.list-panel {
  padding: 16px;
}

.list-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(3, auto);
  gap: 10px;
  margin-bottom: 12px;
  align-items: center;
}

.list-toolbar select {
  width: auto;
  min-width: 118px;
}

#dateFilter {
  min-width: 150px;
}

.list-summary {
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}

.day-group {
  margin-bottom: 14px;
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 6px 2px 8px;
  border-bottom: 1px solid var(--line);
}

.day-title {
  font-size: 14px;
  font-weight: 700;
}

.day-sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.record {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 14px;
  align-items: center;
  padding: 12px 14px;
  margin-top: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.record.completed {
  background: #edf7f2;
  border-color: #9cc9b6;
}

.record.completed .record-title {
  color: var(--accent-dark);
}

.record-main {
  display: flex;
  gap: 10px;
  min-width: 0;
  align-items: flex-start;
}

.record-body {
  min-width: 0;
}

.record-title {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

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

.record-pay {
  text-align: right;
}

.amount {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pay-line {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 3px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.type-edit {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.badge.type-shoot {
  background: var(--shoot-soft);
  color: var(--shoot);
}

.badge.paid {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.badge.unpaid {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.done {
  background: #d5ede2;
  color: #17614d;
}

.badge.clip-done {
  background: #d5ede2;
  color: #17614d;
}

.record-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.char-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.icon-btn.done {
  color: var(--accent-dark);
  border-color: #8ebca9;
  background: #e4f3ec;
}

.icon-btn.state-pending {
  color: var(--shoot);
  border-color: #a8c8e2;
  background: #e8f2fa;
}

.icon-btn.state-green {
  color: var(--accent-dark);
  border-color: #8ebca9;
  background: #e4f3ec;
}

.icon-btn.paid-state {
  color: var(--accent-dark);
  border-color: #8ebca9;
  background: #e4f3ec;
}

.icon-btn.unpaid-state {
  color: var(--warn);
  border-color: #e4c08e;
  background: #fdf1e2;
}

.icon-btn.payment-online {
  color: var(--shoot);
  border-color: #a8c8e2;
  background: #e8f2fa;
}

.icon-btn.payment-offline {
  color: #7a5a1d;
  border-color: #d7c49e;
  background: #f7f1e2;
}

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed #cdd6da;
  border-radius: 8px;
}

.empty strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
  color: var(--ink);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 10px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: #26333a;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 6px 18px rgba(20, 32, 38, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 50;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@supports (padding: max(0px)) {
  .topbar-inner {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  main {
    padding-bottom: max(48px, env(safe-area-inset-bottom));
  }
}

@media (min-width: 981px) {
  body {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .topbar {
    flex: 0 0 auto;
  }

  main {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .stats {
    flex: 0 0 auto;
  }

  .workspace {
    display: block;
    height: 100%;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
  }

  .list-panel {
    height: 100%;
  }

  .form-panel,
  .list-panel {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
}

@media (max-width: 980px) {
  .workspace {
    display: block;
  }

  .list-toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .list-toolbar input {
    grid-column: 1 / -1;
  }

  .list-toolbar select {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 720px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  input,
  select {
    font-size: 16px;
  }

  .btn,
  .segmented button,
  .month-control select {
    min-height: 44px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
    flex-basis: 40px;
  }

  .topbar-inner,
  main {
    padding-left: 14px;
    padding-right: 14px;
  }

  .stat {
    padding: 12px 13px;
  }

  .stat-value {
    font-size: 19px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-actions .btn {
    flex: 1 1 auto;
  }

  .modal-actions .btn {
    flex: 1;
  }

  .list-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .list-toolbar input {
    flex: 1 1 100%;
  }

  .list-toolbar select {
    flex: 1 1 calc(33.333% - 7px);
    width: auto;
    min-width: 0;
  }

  .record {
    grid-template-columns: 1fr;
  }

  .record-right {
    justify-content: space-between;
    width: 100%;
    flex-wrap: wrap;
  }

  .record-pay {
    text-align: left;
  }

  .record-actions {
    width: 100%;
  }

  .pay-line {
    justify-content: flex-start;
  }

  .day-sub {
    white-space: normal;
    text-align: right;
  }

  .top-actions {
    width: 100%;
  }

  .month-control {
    width: 100%;
  }

  .month-control select {
    flex: 1;
  }

  .top-actions .btn {
    flex: 1 1 auto;
  }
}

/* 手机端窄屏：避免顶部按钮把页面撑出横向滚动 */
@media (max-width: 560px) {
  body {
    overflow-x: hidden;
  }

  .top-actions {
    gap: 6px;
  }

  #exportCsvBtn,
  #exportJsonBtn,
  #importBtn {
    flex: 1 1 0;
    min-width: 0;
    padding-left: 8px;
    padding-right: 8px;
    font-size: 13px;
    white-space: nowrap;
  }

  #exportCsvBtn .icon-wrap,
  #exportJsonBtn .icon-wrap,
  #importBtn .icon-wrap {
    width: 15px;
    height: 15px;
  }

  .list-summary {
    line-height: 1.7;
    word-break: break-word;
  }
}
