:root {
  --primary: #1976d2;
  --primary-dark: #115293;
  --secondary: #43a047;
  --danger: #d32f2f;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #212121;
  --text-secondary: #757575;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}

.app-header {
  flex: 0 0 auto;
  background: var(--primary);
  color: #fff;
  padding: 14px 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.app-main {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.entry-form {
  display: grid;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

input[type="date"],
input[type="month"],
input[type="text"],
input[type="number"],
input[type="password"],
select {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
  outline: none;
  transition: border-color 0.2s;
}

input:focus,
select:focus {
  border-color: var(--primary);
  background: #fff;
}

.spec-tip {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--secondary);
  color: #fff;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: #2e7d32;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 6px 10px;
  font-size: 0.85rem;
}

.btn-danger:hover {
  background: rgba(211, 47, 47, 0.06);
}

.btn-full {
  width: 100%;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-row label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.filter-row input[type="date"],
.filter-row input[type="month"] {
  flex: 1 1 auto;
  min-width: 140px;
}

.month-range {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

.month-range input[type="month"] {
  flex: 1 1 120px;
  min-width: 120px;
}

.quick-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

.quick-btns .btn {
  flex: 1 1 auto;
  min-width: 80px;
  padding: 10px 12px;
  font-size: 0.95rem;
}

.empty-tip {
  margin: 12px 0 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

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

.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

.entry-item-line {
  font-weight: 600;
}

.entry-item-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.entry-item-meters {
  font-weight: 600;
  color: var(--primary);
  margin-right: 10px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--text-secondary);
  font-weight: 600;
  background: #fafafa;
}

.data-table td {
  vertical-align: middle;
}

.data-table tfoot td {
  border-bottom: none;
}

.total-row {
  font-weight: 700;
  background: #f0f7ff;
}

.total-row td {
  color: var(--primary-dark);
}

.range-summary {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.app-nav {
  flex: 0 0 auto;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.nav-btn.active {
  color: var(--primary);
  background: #f0f7ff;
}

.nav-icon {
  font-size: 1.25rem;
}

.nav-label {
  font-size: 0.75rem;
  font-weight: 500;
}

@media (min-width: 600px) {
  .app-main {
    padding: 16px;
  }

  .card {
    padding: 20px;
    margin-bottom: 16px;
  }

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

  .form-group:first-child,
  .btn-full {
    grid-column: 1 / -1;
  }

  .month-range {
    width: auto;
    flex: 1 1 auto;
  }

  .quick-btns {
    width: auto;
    flex: 1 1 auto;
    justify-content: flex-end;
  }
}

/* 模态框 */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 12px;
  overflow-y: auto;
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  overflow: hidden;
  margin: auto 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0 4px;
  line-height: 1;
}

.modal-body {
  padding: 12px 16px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* 规格管理表格 */
.spec-mgr-wrap {
  overflow-x: auto;
}

.spec-mgr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.spec-mgr-table th,
.spec-mgr-table td {
  padding: 6px 4px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.spec-mgr-table th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.78rem;
  background: #fafafa;
  white-space: nowrap;
}

.spec-mgr-table input {
  width: 100%;
  padding: 5px 6px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fafafa;
  outline: none;
  box-sizing: border-box;
}

.spec-mgr-table input:focus {
  border-color: var(--primary);
  background: #fff;
}

.spec-mgr-table .col-order {
  width: 36px;
  text-align: center;
  font-weight: 600;
}

.spec-mgr-table .col-name {
  min-width: 60px;
}

.spec-mgr-table .col-label {
  min-width: 110px;
}

.spec-mgr-table .col-length {
  width: 50px;
}

.spec-mgr-table .col-move {
  width: 52px;
  text-align: center;
}

.spec-mgr-table .col-delete {
  width: 44px;
  text-align: center;
}

.spec-mgr-table .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 6px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}

.spec-mgr-table .btn-icon:hover {
  background: #f0f0f0;
}

.spec-mgr-table .btn-icon:active {
  transform: scale(0.95);
}

.spec-mgr-table .btn-del {
  padding: 3px 8px;
  font-size: 0.78rem;
}

.spec-mgr-add-area {
  margin-top: 10px;
}

.spec-mgr-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px 0;
  font-size: 0.9rem;
}

.spec-mgr-btn {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 10px;
  font-size: 0.8rem;
  color: var(--primary);
  background: none;
  border: 1px dashed var(--primary);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.spec-mgr-btn:hover {
  background: #f0f7ff;
}

@media (max-width: 480px) {
  .spec-mgr-table {
    font-size: 0.8rem;
  }
  .spec-mgr-table input {
    font-size: 0.8rem;
    padding: 4px 4px;
  }
  .spec-mgr-table .col-move {
    width: 46px;
  }
  .spec-mgr-table .col-delete {
    width: 40px;
  }
}

/* 登录弹窗 */
.login-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.login-overlay.open {
  display: flex;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-title {
  margin: 0 0 8px;
  font-size: 1.3rem;
  color: var(--primary);
}

.login-subtitle {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.login-input {
  margin-bottom: 16px;
}

.login-error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2em;
}

/* Toast 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(33, 33, 33, 0.9);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
