:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e2e6ea;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: #111827;
  color: #fff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar .brand { font-weight: 700; font-size: 16px; }
.topbar .brand span { color: #93c5fd; }
.topbar nav a { color: #d1d5db; margin-right: 16px; font-size: 13px; }
.topbar nav a.active, .topbar nav a:hover { color: #fff; }
.topbar .userinfo { font-size: 13px; color: #9ca3af; }
.topbar .userinfo a { color: #f87171; margin-left: 10px; }

.container { max-width: 1180px; margin: 24px auto; padding: 0 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }

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

/* A currency_rate_field dropdown defaults to a narrow fixed width (right for
   cramped per-line-item rows) — stretch it to fill its own grid column when
   it's a header-level field on its own, so it doesn't leave a gap next to
   wider neighbors like a customer picker or date input. */
.field-currency-full .currency-rate-group,
.field-currency-full .currency-rate-group > div:first-child {
  width: 100%;
}
.field-currency-full .currency-select {
  width: 100% !important;
}

.stat { text-align: center; }
.stat .num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: #fafbfc; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.new { background: #e5e7eb; color: #374151; }
.badge.sent-to-vendor { background: #dbeafe; color: #1e40af; }
.badge.partially-received { background: #fef3c7; color: #92400e; }
.badge.fully-received { background: #d1fae5; color: #065f46; }
.badge.sent-to-customer { background: #e0e7ff; color: #3730a3; }
.badge.delivered { background: #16a34a; color: #fff; }
.badge.open { background: #fef3c7; color: #92400e; }
.badge.completed { background: #16a34a; color: #fff; }
.badge.late { background: var(--danger); color: #fff; }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.clear { background: #d1fae5; color: #065f46; }
.badge.approved { background: #d1fae5; color: #065f46; }
.badge.declined { background: #fee2e2; color: #991b1b; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.secondary { background: #6b7280; }
.btn.secondary:hover { background: #4b5563; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.warning { background: var(--warn); }
.btn.warning:hover { background: #b45309; }
.btn.success { background: var(--success); }
.btn.success:hover { background: #15803d; }
/* Icon-only buttons (Save/Terminate/Delete, etc.) — no solid color block,
   just the glyph on a faint hover highlight so the emoji's own color shows
   through (the floppy disk's natural grey-with-blue, the red trash can, the
   orange no-entry sign) instead of being boxed in a bright background. */
.btn.icon {
  background: transparent;
  color: inherit;
  padding: 6px 8px;
  font-size: 16px;
  line-height: 1;
  border-radius: 6px;
  margin: 0 2px;
  min-width: 32px;
  text-align: center;
  vertical-align: middle;
  transition: background-color 0.15s ease;
}
.btn.icon:hover { background: #f1f5f9; }
.btn.icon.danger,
.btn.icon.warning,
.btn.icon.success {
  background: transparent;
}
.btn.icon.danger:hover { background: #fee2e2; }
.btn.icon.warning:hover { background: #fef3c7; }
.btn.icon.success:hover { background: #d1fae5; }

form.inline { display: inline; }

input, select, textarea {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  width: 100%;
  font-family: inherit;
}
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field { margin-bottom: 12px; }

.line-item-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fafbfc;
}
.line-item-row .grid { grid-template-columns: repeat(4, 1fr); gap: 10px; }

.muted { color: var(--muted); }
.mt-0 { margin-top: 0; }

pre.wechat-msg {
  background: #f0f9ff;
  border: 1px dashed #7dd3fc;
  padding: 12px;
  border-radius: 6px;
  white-space: pre-wrap;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: #fff;
  padding: 32px;
  border-radius: 10px;
  border: 1px solid var(--border);
  width: 320px;
}
.login-box h1 { text-align: center; }
.error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 16px; text-align: center; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 14px; color: var(--muted); font-size: 13px; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.module-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.module-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(37,99,235,.12); text-decoration: none; transform: translateY(-1px); }
.module-card .module-icon {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 8px;
  background: #eef2ff;
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
}
.module-card .module-body { flex: 1; min-width: 0; }
.module-card .module-title { font-weight: 600; color: var(--text); font-size: 14px; }
.module-card .module-desc { color: var(--muted); font-size: 12px; margin-top: 1px; }
.module-card .module-arrow { flex: none; color: var(--muted); font-size: 16px; }

.item-picker-chosen {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  background: #fafbfc;
}
.item-picker-chosen-text { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-picker-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.item-picker-modal-inner {
  background: #fff;
  width: 100%;
  max-width: 920px;
  max-height: 85vh;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.item-picker-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.item-picker-modal-header h3 { flex: none; }
.item-picker-modal-header .item-picker-search { flex: 1; }
.item-picker-close {
  flex: none;
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}
.item-picker-close:hover { color: var(--text); }
.item-picker-modal-body { padding: 16px 18px; overflow-y: auto; }
.item-picker-card { cursor: default; }
.item-picker-card .item-picker-select-btn { width: 100%; margin-top: auto; }

.item-card-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap:12px; margin-top:12px; align-items:stretch; }
.item-card {
  display: flex;
  flex-direction: column;
  border:1px solid #e5e7eb;
  border-radius:8px;
  overflow:hidden;
  cursor:pointer;
  background:#fff;
  transition:box-shadow 0.15s;
}
.item-card:hover { box-shadow:0 4px 14px rgba(0,0,0,0.1); }
.item-card-image { width:100%; height:110px; flex:none; background:#f8fafc; display:flex; align-items:center; justify-content:center; }
.item-card-image img { width:100%; height:100%; object-fit:cover; }
.item-card-noimage { color:#94a3b8; font-size:12px; }
.item-card-body { padding:8px 10px; display:flex; flex-direction:column; flex:1; }
.item-card-title {
  font-weight:600;
  margin-bottom:3px;
  font-size:13.5px;
  line-height:1.3;
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  overflow:hidden;
}
.item-card-meta {
  color:#64748b;
  font-size:11.5px;
  line-height:1.45;
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  overflow:hidden;
  margin-bottom: 8px;
}
.item-card-actions { margin-top:auto; padding-top:6px; display:flex; gap:6px; }
