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

body {
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: #f5f5f0;
  color: #2c2c2a;
  font-size: 14px;
  line-height: 1.6;
}

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: #fff;
  border-right: 1px solid #e5e5e0;
  padding: 24px 16px;
  flex-shrink: 0;
}

.brand {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 28px;
  padding: 0 8px;
  color: #2c2c2a;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #5f5e5a;
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 2px;
  cursor: pointer;
}
.nav-item:hover { background: #f5f5f0; color: #2c2c2a; }
.nav-item.active { background: #e6f1fb; color: #185fa5; }
.nav-icon { width: 18px; text-align: center; }

.main { flex: 1; padding: 28px 36px; min-width: 0; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-title { font-size: 22px; font-weight: 500; }

.btn {
  padding: 8px 16px;
  font-size: 14px;
  border: 1px solid #d3d1c7;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  color: #2c2c2a;
  font-family: inherit;
  transition: all 0.15s;
}
.btn:hover { background: #f5f5f0; border-color: #b4b2a9; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: #185fa5; color: #fff; border-color: #185fa5; }
.btn-primary:hover { background: #0c447c; border-color: #0c447c; }
.btn-danger { color: #791f1f; border-color: #f7c1c1; }
.btn-danger:hover { background: #fcebeb; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.card {
  background: #fff;
  border: 1px solid #e5e5e0;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid #e5e5e0;
  border-radius: 12px;
  padding: 18px;
}
.stat-label { font-size: 13px; color: #5f5e5a; margin-bottom: 8px; }
.stat-value { font-size: 24px; font-weight: 500; }
.stat-sub { font-size: 12px; color: #888780; margin-top: 4px; }

.text-success { color: #27500a; }
.text-warning { color: #854f0b; }
.text-danger  { color: #791f1f; }
.text-info    { color: #0c447c; }
.text-muted   { color: #888780; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid #f0efe9; }
th { background: #faf9f5; font-weight: 500; color: #5f5e5a; font-size: 12px; }
tr:hover td { background: #fafaf6; }
td.num, th.num { text-align: right; }
.table-wrap { background: #fff; border: 1px solid #e5e5e0; border-radius: 12px; overflow: hidden; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
}
.pill-draft       { background: #f1efe8; color: #5f5e5a; }
.pill-sent        { background: #e6f1fb; color: #0c447c; }
.pill-accepted    { background: #eaf3de; color: #27500a; }
.pill-in_progress { background: #faeeda; color: #633806; }
.pill-completed   { background: #e1f5ee; color: #085041; }
.pill-paid        { background: #c0dd97; color: #173404; }
.pill-rejected    { background: #fcebeb; color: #791f1f; }
.pill-cancelled   { background: #f1efe8; color: #888780; }
.pill-income      { background: #eaf3de; color: #27500a; }
.pill-expense     { background: #fcebeb; color: #791f1f; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.form-group { display: flex; flex-direction: column; }
.form-label { font-size: 12px; color: #5f5e5a; margin-bottom: 4px; }

input[type="text"], input[type="number"], input[type="email"], input[type="tel"],
input[type="date"], select, textarea {
  padding: 8px 12px;
  border: 1px solid #d3d1c7;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  font-family: inherit;
  color: #2c2c2a;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #185fa5;
  box-shadow: 0 0 0 3px rgba(24, 95, 165, 0.1);
}
textarea { resize: vertical; min-height: 60px; }

.items-table { width: 100%; margin-bottom: 14px; }
.items-table th { background: #faf9f5; font-size: 12px; padding: 8px 10px; }
.items-table td { padding: 6px 6px; border-bottom: 1px solid #f0efe9; }
.items-table input { padding: 6px 10px; font-size: 13px; }

.totals-box {
  background: #faf9f5;
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 16px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}
.totals-row.grand {
  font-size: 18px;
  font-weight: 500;
  border-top: 1px solid #e5e5e0;
  margin-top: 6px;
  padding-top: 10px;
}

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: 14px;
  width: 90%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0efe9;
}
.modal-title { font-size: 18px; font-weight: 500; }
.modal-close {
  background: transparent; border: none; cursor: pointer;
  font-size: 22px; color: #888780;
}
.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 18px; padding-top: 14px;
  border-top: 1px solid #f0efe9;
}

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

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

.action-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  color: #5f5e5a;
  margin: 0 2px;
}
.action-icon:hover { background: #f5f5f0; color: #2c2c2a; }

.flash {
  position: fixed; top: 20px; right: 20px;
  background: #fff;
  border: 1px solid #e5e5e0;
  border-left: 3px solid #185fa5;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  z-index: 200;
}
.flash.success { border-left-color: #27500a; }
.flash.error   { border-left-color: #791f1f; }

@media (max-width: 768px) {
  .sidebar { width: 60px; padding: 16px 8px; }
  .brand, .nav-item span:not(.nav-icon) { display: none; }
  .main { padding: 16px; }
}


.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
  align-items: start;
}
.legend-dot {
  display:inline-block;
  width:10px;
  height:10px;
  border-radius:2px;
  vertical-align:middle;
  margin-right:4px;
}
code {
  background:#f5f5f0;
  padding:2px 6px;
  border-radius:4px;
  font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size:12px;
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; position: static; }
  .main { padding: 20px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
}
