/* ===== Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: #333;
  background: #f5f7fa;
  line-height: 1.5;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }

.hidden { display: none !important; }

.page {
  display: block;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #999;
  font-size: 14px;
}

/* ===== Login ===== */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 360px;
}

.login-box h1 {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
  font-size: 22px;
}

.login-hint {
  text-align: center;
  margin-top: 15px;
  color: #999;
  font-size: 12px;
}

/* ===== Layout ===== */
#app-view {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: #1a1a2e;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 { font-size: 16px; margin-bottom: 8px; }

.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  background: #667eea;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  color: rgba(255,255,255,0.7);
  transition: all 0.2s;
  cursor: pointer;
  user-select: none;
  pointer-events: auto;
}

.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.nav-item .icon { margin-right: 10px; font-size: 16px; }

.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.main-content {
  flex: 1;
  margin-left: 220px;
  padding: 30px;
  min-width: 320px;
  position: relative;
  z-index: 1;
  overflow-x: auto;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: white;
  color: #333;
  font-size: 14px;
  transition: all 0.2s;
  cursor: pointer;
}

.btn:hover { border-color: #667eea; color: #667eea; }

.btn-primary {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.btn-primary:hover { background: #5a6fd6; color: white; }

.btn-secondary {
  background: #52c41a;
  color: white;
  border-color: #52c41a;
}

.btn-secondary:hover { background: #49ad18; }

.btn-danger {
  background: #ff4d4f;
  color: white;
  border-color: #ff4d4f;
}

.btn-danger:hover { background: #e04345; }

.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-block { width: 100%; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: #555;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #667eea;
}

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

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

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  justify-content: flex-end;
}

/* ===== Tables ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
}

.data-table th {
  background: #fafafa;
  font-weight: 600;
  color: #666;
  font-size: 13px;
}

.data-table tr:hover { background: #f5f7fa; }

.data-table td { font-size: 13px; }

/* ===== Status badges ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.badge-draft { background: #f0f0f0; color: #999; }
.badge-pending { background: #fff7e6; color: #fa8c16; }
.badge-approved { background: #f6ffed; color: #52c41a; }
.badge-rejected { background: #fff1f0; color: #ff4d4f; }
.badge-returned { background: #fff2e8; color: #fa541c; }
.badge-completed { background: #e6f7ff; color: #1890ff; }

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: white;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #667eea;
  margin-bottom: 4px;
}

.stat-label { color: #999; font-size: 13px; }

/* ===== Page ===== */
.page > h1 { margin-bottom: 24px; font-size: 22px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-header h1 { margin: 0; }

#page-applications .page-header {
  align-items: flex-start;
  gap: 20px;
}

#page-applications .filter-bar {
  justify-content: flex-end;
}

.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input {
  padding: 6px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: #fff;
}

#app-filter-demand { min-width: 230px; }
#app-filter-demand-query { min-width: 190px; }

.applications-summary {
  margin: -8px 0 20px;
  padding: 14px 18px;
  background: #fff;
  border: 1px solid #e8eaf0;
  border-left: 4px solid #667eea;
  border-radius: 8px;
  color: #555;
}

.applications-summary strong {
  color: #ff4d4f;
  font-size: 18px;
}

.demand-filter-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: #526ed3;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.demand-filter-link:hover {
  text-decoration: underline;
}

/* ===== Wizard ===== */
.wizard-steps {
  display: flex;
  margin-bottom: 30px;
  background: white;
  border-radius: 8px;
  overflow: hidden;
}

.wizard-steps .step {
  flex: 1;
  padding: 16px;
  text-align: center;
  background: #f5f7fa;
  color: #999;
  position: relative;
}

.wizard-steps .step.active {
  background: #667eea;
  color: white;
}

.type-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin: 20px 0;
}

.type-card {
  background: white;
  padding: 30px;
  border-radius: 8px;
  border: 2px solid #f0f0f0;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.type-card:hover { border-color: #667eea; }

.type-card.selected { border-color: #667eea; background: #f0f4ff; }

.type-icon { font-size: 36px; margin-bottom: 12px; }

.type-card h4 { margin-bottom: 8px; }

.type-card p { color: #999; font-size: 13px; }

/* ===== Items ===== */
.items-list { margin-bottom: 20px; }

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: white;
  border-radius: 6px;
  margin-bottom: 8px;
  border: 1px solid #f0f0f0;
}

.item-row span { flex: 1; }
.item-row .item-sequence { flex: 0 0 34px; font-weight: 700; color: #667eea; text-align: center; }

.item-row .item-desc { flex: 2; }
.item-row .item-amount { color: #ff4d4f; font-weight: 600; flex: 0.8; }
.item-row .item-supplier { color: #666; font-style: italic; flex: 1.2; }

.item-row img { width: 60px; height: 60px; object-fit: cover; border-radius: 4px; }

.add-item-form {
  background: #fafafa;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.total-bar {
  background: white;
  padding: 16px 20px;
  border-radius: 8px;
  text-align: right;
  font-size: 16px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.total-bar strong { color: #ff4d4f; font-size: 20px; }

/* ===== Detail ===== */
.detail-card {
  background: white;
  padding: 24px;
  border-radius: 8px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

.detail-item dt { color: #999; font-size: 12px; margin-bottom: 4px; }
.detail-item dd { font-weight: 500; }

/* ===== Payment Form (Print) ===== */
.payment-form {
  background: white;
  padding: 40px;
  max-width: 800px;
  margin: 0 auto;
}

.payment-form h2 {
  text-align: center;
  font-size: 22px;
  margin-bottom: 8px;
  letter-spacing: 8px;
}

.payment-form .form-date {
  text-align: right;
  margin-bottom: 20px;
  font-size: 14px;
}

.payment-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.payment-table td, .payment-table th {
  border: 1px solid #333;
  padding: 10px 14px;
  vertical-align: middle;
}

.payment-table .label-cell {
  background: #f5f5f5;
  width: 120px;
  text-align: center;
  font-weight: 500;
}

.payment-table .full-row td { text-align: left; }

.payment-table .checkbox-group {
  display: flex;
  gap: 30px;
}

.payment-table .checkbox-group label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.payment-table .checkbox-group input[type="checkbox"] {
  width: 16px; height: 16px;
}

.sign-row td { height: 60px; vertical-align: bottom; padding-bottom: 8px; }
.sign-row .sign-label { vertical-align: middle; text-align: center; background: #f5f5f5; }

.qr-section {
  display: flex;
  gap: 40px;
  margin-top: 20px;
  justify-content: center;
}

.qr-item { text-align: center; }
.qr-item img { width: 120px; height: 120px; }
.qr-item p { margin-top: 8px; font-size: 13px; color: #666; }

.note-text {
  margin-top: 12px;
  font-size: 13px;
  color: #666;
}

.print-actions {
  text-align: center;
  margin-bottom: 20px;
}

@media print {
  .no-print { display: none !important; }
  .sidebar, .main-content { margin: 0; max-width: 100%; }
  #app-view { display: block; }
  #page-payment-form { display: block !important; }
  .payment-form { padding: 20px; }
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 8px;
  width: 480px;
  max-width: 90%;
}

.modal-content h3 { margin-bottom: 20px; }

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

/* ===== Approval cards ===== */
.approval-card {
  background: white;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.approval-card h4 { margin-bottom: 12px; }

.approval-meta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  font-size: 13px;
}

.approval-meta dt { color: #999; }
.approval-meta dd { font-weight: 500; }

.approval-actions {
  display: flex;
  gap: 12px;
}

/* ===== Petty Cash ===== */
.petty-cash-card {
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 24px;
}

.petty-cash-amount {
  font-size: 36px;
  font-weight: 700;
  color: #52c41a;
}

.petty-cash-section {
  background: white;
  padding: 24px;
  border-radius: 8px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.petty-cash-section h2 {
  margin-bottom: 16px;
  font-size: 18px;
}

.transaction-recharge { color: #52c41a; font-weight: 600; }
.transaction-deduct { color: #ff4d4f; font-weight: 600; }

/* ===== Misc ===== */
.drafts-section {
  background: #fffbe6;
  border: 1px solid #ffe58f;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 24px;
}

.drafts-title {
  font-size: 16px;
  margin-bottom: 12px;
  color: #d48806;
}

.drafts-table { margin-bottom: 0; }

.receipt-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
}

.image-preview-trigger {
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  line-height: 0;
  cursor: zoom-in;
}

.image-preview-trigger:focus-visible {
  outline: 3px solid rgba(22, 119, 255, 0.35);
  outline-offset: 2px;
}

.image-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 64px 24px 24px;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
}

.image-preview-modal img {
  display: block;
  max-width: 96vw;
  max-height: calc(100vh - 96px);
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  cursor: default;
}

.image-preview-toolbar {
  position: absolute;
  top: 14px;
  left: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  font-size: 16px;
}

.image-preview-toolbar button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 30px;
  line-height: 36px;
  cursor: pointer;
}

body.image-preview-open { overflow: hidden; }

.qr-upload { margin: 20px 0; }
#qr-preview img { max-width: 200px; margin-top: 10px; }

.empty-state {
  text-align: center;
  padding: 60px;
  color: #999;
}

/* ===== Loading indicator ===== */
.page-loading {
  text-align: center;
  padding: 40px;
  color: #999;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-header h2, .nav-item span:not(.icon), .sidebar-footer span { display: none; }
  .main-content { margin-left: 60px; padding: 15px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .type-cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .approval-meta { grid-template-columns: repeat(2, 1fr); }
  #page-applications .page-header { flex-direction: column; }
  #page-applications .filter-bar { justify-content: flex-start; }
  #app-filter-demand, #app-filter-demand-query { width: 100%; min-width: 0; }
}
