:root {
  --farmer: #16a34a;
  --agent: #2563eb;
  --aggregator: #7c3aed;
  --processor: #4338ca;
  --marketer: #059669;
  --admin: #1f2937;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --sync-bg: #dbeafe;
  --sync-text: #1e3a8a;
  --ok-bg: #dcfce7;
  --ok-text: #166534;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --radius: 12px;
  --shadow-soft: 0 10px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 18% -18%, #dcfce7 0%, #f8fafc 48%),
    radial-gradient(circle at 100% -32%, #dbeafe 0%, rgba(219, 234, 254, 0) 42%);
  color: var(--text);
  font-family: "Manrope", "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100%;
}

#app {
  min-height: 100vh;
}

.mobile-shell {
  --role-rgb: 22 163 74;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: max(84px, env(safe-area-inset-bottom));
}
.mobile-shell.role-farmer { --role-rgb: 22 163 74; }
.mobile-shell.role-agent { --role-rgb: 37 99 235; }
.mobile-shell.role-aggregator { --role-rgb: 124 58 237; }
.mobile-shell.role-processor { --role-rgb: 67 56 202; }
.mobile-shell.role-marketer { --role-rgb: 5 150 105; }
.mobile-shell.role-admin { --role-rgb: 31 41 55; }

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(8px);
  background:
    linear-gradient(180deg, rgba(var(--role-rgb), 0.16) 0%, rgba(255, 255, 255, 0.9) 55%),
    rgba(255, 255, 255, 0.86);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 21px;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
}

.role-farmer .logo,
.logo.role-farmer {
  background: linear-gradient(135deg, #16a34a, #059669);
}
.role-agent .logo,
.logo.role-agent {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}
.role-aggregator .logo,
.logo.role-aggregator {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
}
.role-processor .logo,
.logo.role-processor {
  background: linear-gradient(135deg, #4338ca, #3730a3);
}
.role-marketer .logo,
.logo.role-marketer {
  background: linear-gradient(135deg, #059669, #047857);
}
.role-admin .logo,
.logo.role-admin {
  background: linear-gradient(135deg, #1f2937, #0f172a);
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.main {
  padding: 16px 14px 0;
  display: grid;
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.98)),
    var(--surface);
  padding: 13px;
  box-shadow: var(--shadow-soft);
  min-width: 0;
}

.panel h2,
.panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.3;
}

.panel form {
  display: block;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

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

.row > * {
  flex: 1 1 120px;
  min-width: 0;
}

.grid2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background:
    linear-gradient(180deg, rgba(var(--role-rgb), 0.08) 0%, var(--surface-soft) 70%),
    var(--surface-soft);
}

.metric strong {
  font-size: 18px;
  display: block;
}

.metric span {
  font-size: 12px;
  color: var(--muted);
}

label {
  display: block;
  margin: 0 0 5px;
  font-size: 12px;
  color: #334155;
  font-weight: 600;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #fff;
  padding: 10px;
  margin: 0 0 8px;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(var(--role-rgb), 0.9);
  box-shadow: 0 0 0 3px rgba(var(--role-rgb), 0.18);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

button {
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid #334155;
  background: #cbd5e1;
  background-image: none;
  color: #0b1220;
  text-shadow: none;
  -webkit-text-fill-color: #0b1220 !important;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0.01em;
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.18);
  transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

button:active {
  transform: scale(0.98);
}
.mobile-shell button:not(.secondary):not(.warn):not(.danger):not(.tab):not(:disabled) {
  background: linear-gradient(135deg, rgba(var(--role-rgb), 0.30), rgba(var(--role-rgb), 0.52));
  box-shadow: 0 8px 16px rgba(var(--role-rgb), 0.22);
  color: #0b1220 !important;
  -webkit-text-fill-color: #0b1220 !important;
  border-color: rgba(var(--role-rgb), 0.88);
}

.panel form > button[type="submit"] {
  width: 100%;
  margin-top: 4px;
}

.mobile-shell .panel form > button[type="submit"]:not(:disabled) {
  background: linear-gradient(135deg, rgba(var(--role-rgb), 0.32), rgba(var(--role-rgb), 0.54));
  color: #0b1220 !important;
  -webkit-text-fill-color: #0b1220 !important;
  border-color: rgba(var(--role-rgb), 0.90);
  box-shadow: 0 8px 16px rgba(var(--role-rgb), 0.24);
  opacity: 1;
  text-shadow: none;
}

button.secondary {
  background: #dbe2ea;
  color: #0f172a;
  border-color: #475569;
  text-shadow: none;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.12);
}

button.warn {
  background: #fbbf24;
  border-color: #b45309;
  color: #431407;
  -webkit-text-fill-color: #431407 !important;
}

button.danger {
  background: #fca5a5;
  border-color: #b91c1c;
  color: #450a0a;
  -webkit-text-fill-color: #450a0a !important;
}

button:disabled {
  opacity: 0.88;
  cursor: not-allowed;
  color: #334155;
  -webkit-text-fill-color: #334155 !important;
  background: #cbd5e1;
  border-color: #475569;
  box-shadow: none;
}

button.secondary:disabled {
  color: #475569;
  -webkit-text-fill-color: #475569 !important;
  background: #e2e8f0;
  border-color: #94a3b8;
}

button:focus-visible {
  outline: 2px solid rgba(var(--role-rgb), 0.35);
  outline-offset: 2px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 9px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
}

.chip.sync-not { background: var(--warn-bg); color: var(--warn-text); border-color: #fcd34d; }
.chip.syncing { background: var(--sync-bg); color: var(--sync-text); border-color: #93c5fd; }
.chip.sync-ok { background: var(--ok-bg); color: var(--ok-text); border-color: #86efac; }
.chip.pending { background: #e0e7ff; color: #3730a3; }
.chip.received { background: var(--ok-bg); color: var(--ok-text); }
.chip.rejected { background: var(--danger-bg); color: var(--danger-text); }
.chip.offline { background: #ffedd5; color: #9a3412; border-color: #fdba74; }

.item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 8px;
  background: #fff;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.04);
}

.item h4 {
  margin: 0 0 4px;
  font-size: 14px;
}

.item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.item .row button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-width: 1px;
}

.item .row {
  margin-top: 8px;
}

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

.trace-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.trace-item {
  border: 1px solid #dbe2ea;
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.trace-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.trace-body p {
  margin: 6px 0 0;
  font-size: 12px;
  color: #334155;
}

.table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
}

.table th,
.table td {
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  font-size: 12px;
  padding: 7px 6px;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 12px;
}

.toast-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 60;
}

.toast {
  pointer-events: auto;
  width: min(92vw, 420px);
  background: #0f172a;
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  box-shadow: 0 12px 24px rgba(2, 6, 23, 0.35);
  animation: rise 0.2s ease-out;
}

.toast.good { background: #166534; }
.toast.bad { background: #991b1b; }
.toast.warn { background: #92400e; }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.tab {
  flex: 0 0 auto;
  border: 1px solid #64748b;
  background: #dbe2ea;
  color: #0f172a;
  -webkit-text-fill-color: #0f172a !important;
  text-shadow: none;
  box-shadow: none;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.tab.active {
  background: rgba(var(--role-rgb), 0.46);
  border-color: rgba(var(--role-rgb), 0.98);
  color: #0b1220;
  -webkit-text-fill-color: #0b1220 !important;
  box-shadow: 0 5px 12px rgba(var(--role-rgb), 0.26);
}

.landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.landing-card {
  width: 100%;
  max-width: 448px;
  border-radius: 20px;
  border: 1px solid #d1fae5;
  background: linear-gradient(160deg, #ecfdf5, #f0fdfa 55%, #eff6ff);
  padding: 20px;
  box-shadow: 0 18px 34px rgba(15, 23, 42, 0.12);
  position: relative;
  overflow: hidden;
}

.landing-glow {
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.28) 0%, rgba(16, 185, 129, 0) 68%);
  top: -40px;
  right: -40px;
}

.landing-logo {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  font-size: 34px;
  color: #fff;
  background: linear-gradient(135deg, #16a34a, #059669);
  box-shadow: 0 16px 24px rgba(5, 150, 105, 0.38);
  animation: float 2.4s ease-in-out infinite;
}

.landing h1 {
  margin: 12px 0 4px;
  font-size: 34px;
  line-height: 1.05;
}

.landing p {
  margin: 0;
  color: #334155;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.feature {
  border: 1px solid #bbf7d0;
  background: rgba(255, 255, 255, 0.86);
  border-radius: 12px;
  padding: 10px;
  font-size: 12px;
  font-weight: 600;
}

.feature span {
  display: block;
  font-size: 18px;
  margin-bottom: 4px;
}

.login-card {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.login-panel {
  margin-top: 2px;
  flex: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.login-card .main {
  flex: 1;
  display: flex;
  align-items: stretch;
}

.login-card .main > .login-panel {
  width: 100%;
}

.login-card .login-panel form {
  flex: 1;
}

.transfer-availability {
  margin: 4px 0 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(var(--role-rgb), 0.2);
  background: rgba(var(--role-rgb), 0.08);
}

.qr-box {
  background: #fff;
  border: 2px solid #bbf7d0;
  border-radius: 12px;
  padding: 8px;
  max-width: 220px;
}

.kv {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 8px;
}

.kv div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  margin: 3px 0;
}

.pwa-install {
  margin-top: 8px;
}

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

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
