/* ==========================================
   styles.css — 普山资本 支出台账
   Mobile-first dark theme
   ========================================== */

/* --- Design Tokens --- */
:root {
  --bg-primary: #080c14;
  --bg-secondary: #0f1520;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.06);
  --text-primary: #e8e0d0;
  --text-secondary: rgba(200, 195, 180, 0.7);
  --text-muted: rgba(148, 163, 184, 0.5);
  --accent-gold: #c9a84c;
  --accent-gold-dim: rgba(201, 168, 76, 0.15);
  --accent-blue: #00d4ff;
  --danger: #e0556a;
  --danger-dim: rgba(224, 85, 106, 0.15);
  --success: #4caf50;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --font-sans: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --nav-height: 60px;
  --topbar-height: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.5;
}

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

/* --- Utility --- */
.hidden { display: none !important; }

/* --- App Layout --- */
#app {
  min-height: 100dvh;
  padding-bottom: var(--nav-height);
}

.view {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-content {
  padding: 12px 16px 24px;
  max-width: 960px;
  margin: 0 auto;
}

/* --- Top Bar --- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-bar h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
}

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

.current-user {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease;
  min-height: 44px;
  min-width: 44px;
  user-select: none;
  -webkit-user-select: none;
}

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

.btn-gold {
  background: var(--accent-gold);
  color: #080c14;
  border-color: var(--accent-gold);
  font-weight: 600;
}

.btn-gold:hover { background: #d4b35a; }
.btn-gold:active { background: #b8943a; }

.btn-outline {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-outline:hover { background: var(--bg-card); }

.btn-ghost {
  color: var(--text-secondary);
  border: none;
  background: transparent;
}

.btn-ghost:hover { color: var(--text-primary); }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  min-height: 32px;
}

.btn-icon {
  padding: 8px;
  font-size: 1.2rem;
  min-width: 44px;
  min-height: 44px;
}

.btn-block {
  width: 100%;
}

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

.btn-danger:hover { background: var(--danger-dim); }

/* --- Login --- */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 32px 24px;
}

.login-logo {
  text-align: center;
  margin-bottom: 40px;
}

.logo-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent-gold), #e0c060);
  color: #080c14;
  font-size: 1.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  letter-spacing: 2px;
}

.login-logo h1 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-logo p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.login-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 12px;
  text-align: center;
}

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

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

.form-group input,
.form-group select,
.form-group textarea {
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
  min-height: 44px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent-gold);
}

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

.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-group select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

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

/* --- Month Picker --- */
.month-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 0 16px;
}

.month-label {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 120px;
  text-align: center;
}

/* --- Year Picker --- */
.year-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0 16px;
}

/* --- Stats --- */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  text-align: center;
}

.stat-card-annual {
  border-left: 3px solid var(--accent-blue);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent-gold);
  margin-bottom: 4px;
}

.stat-card-annual .stat-value {
  color: var(--accent-blue);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* --- Section Title --- */
.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 16px 0 10px;
  padding-left: 4px;
}

/* --- Handler List --- */
.handler-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.handler-card {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 12px;
}

.handler-card .handler-name {
  flex: 1;
  font-weight: 500;
  font-size: 0.9rem;
}

.handler-card .handler-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-right: 8px;
}

.handler-card .handler-amount {
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent-gold);
  font-size: 0.95rem;
}

.handler-card .handler-pct {
  width: 50px;
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- Records View --- */
.expense-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* --- Expense Card (mobile) --- */
.expense-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid var(--accent-gold);
}

.expense-card:active { background: var(--bg-card-hover); }

.expense-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.expense-card-date {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.expense-card-amount {
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent-gold);
  font-size: 1.05rem;
}

.expense-card-desc {
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.expense-card-meta {
  display: flex;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  align-items: center;
}

.expense-card-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--accent-gold-dim);
  color: var(--accent-gold);
}

.expense-card-img {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg-input);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.empty-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- FAB --- */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 20px + var(--safe-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--accent-gold);
  color: #080c14;
  border: none;
  font-size: 1.8rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(201, 168, 76, 0.3);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
}

.fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 8px rgba(201, 168, 76, 0.2);
}

/* --- Bottom Navigation --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 30;
  padding-bottom: var(--safe-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
  transition: color 0.15s;
  min-height: 44px;
}

.nav-item.active {
  color: var(--accent-gold);
}

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

.nav-label {
  font-size: 0.7rem;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 10px auto 0;
}

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

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-body .form-group {
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* --- Screenshot Upload Area --- */
.screenshot-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 14px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
}

.screenshot-area:hover, .screenshot-area.drag-over {
  border-color: var(--accent-gold);
  background: var(--accent-gold-dim);
}

.screenshot-area.has-image {
  border-style: solid;
  border-color: var(--border-strong);
  padding: 10px;
}

.screenshot-area p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.screenshot-preview {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.screenshot-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 12px;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 0.8rem;
  cursor: pointer;
}

.screenshot-preview-wrap {
  position: relative;
  display: inline-block;
}

/* --- Detail View --- */
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.detail-label {
  color: var(--text-secondary);
  min-width: 80px;
}

.detail-value {
  font-weight: 500;
  text-align: right;
}

.detail-screenshot {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius);
  margin-top: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
}

/* --- Lightbox --- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox img {
  max-width: 100%;
  max-height: 90dvh;
  object-fit: contain;
  border-radius: var(--radius);
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: rgba(255,255,255,0.1);
  color: white;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  z-index: 100;
}

/* --- Summary Tables --- */
.summary-table-wrap {
  overflow-x: auto;
  margin-bottom: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.summary-table th,
.summary-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.summary-table th {
  background: var(--bg-card);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.8rem;
  white-space: nowrap;
}

.summary-table tbody tr:last-child td {
  border-bottom: none;
}

.summary-table td {
  color: var(--text-primary);
}

.summary-table .col-num {
  text-align: right;
  font-family: var(--font-mono);
}

.summary-table .col-amount {
  text-align: right;
  font-family: var(--font-mono);
  color: var(--accent-gold);
  font-weight: 600;
}

.summary-table tfoot td {
  font-weight: 600;
  color: var(--accent-blue);
  border-top: 2px solid var(--border-strong);
}

/* --- Toast --- */
#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  animation: toastIn 0.25s ease;
  pointer-events: auto;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--accent-blue); color: #080c14; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Last Updated --- */
.last-updated {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 16px;
}

/* --- Desktop Overrides --- */
@media (min-width: 768px) {
  .view-content {
    padding: 20px 24px 32px;
  }

  .stats-row {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }

  .handler-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
  }

  .handler-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 18px;
  }

  .handler-card .handler-pct {
    width: auto;
    text-align: left;
  }

  /* Desktop: table-style expense list */
  .expense-list {
    gap: 0;
  }

  .expense-card {
    display: grid;
    grid-template-columns: 100px 1fr 120px 90px 90px 60px;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-left: none;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
  }

  .expense-card:first-child {
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .expense-card:last-child {
    border-radius: 0 0 var(--radius) var(--radius);
    border-bottom: none;
  }

  .expense-card-top {
    margin-bottom: 0;
    display: contents;
  }

  .expense-card-date { order: 0; font-size: 0.85rem; }
  .expense-card-desc { order: 1; font-size: 0.9rem; }
  .expense-card-amount { order: 2; text-align: right; }
  .expense-card-meta { order: 3; }
  .expense-card-badge { order: 4; text-align: center; }
  .expense-card-img { order: 5; }

  /* Desktop modal */
  .modal-overlay {
    align-items: center;
  }

  .modal-sheet {
    border-radius: var(--radius-lg);
    max-height: 85dvh;
    width: 520px;
  }

  .modal-handle { display: none; }

  /* Desktop nav */
  .bottom-nav {
    position: sticky;
    top: var(--topbar-height);
    bottom: auto;
    height: 44px;
    justify-content: center;
    gap: 0;
  }

  #app {
    padding-bottom: 0;
  }

  .fab {
    bottom: 28px;
    right: calc(50% - 480px + 20px);
  }
}
