/* ════════════════════════════════════════════════
   Arya Finternet — Professional Banking Design System
   ════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=DM+Sans:wght@400;500;600;700&display=swap');

/* ── Design Tokens ── */
:root {
  /* Primary palette — navy blue (banking) */
  --navy:          #1b2a6b;
  --navy-dark:     #111d52;
  --navy-mid:      #243480;
  --navy-light:    rgba(27, 42, 107, 0.06);
  --navy-border:   rgba(27, 42, 107, 0.15);

  /* Accent */
  --blue:          #1565d8;
  --blue-light:    #e8effe;
  --blue-border:   rgba(21, 101, 216, 0.2);

  /* Surface */
  --white:         #ffffff;
  --bg-page:       #f4f5f9;
  --bg-card:       #ffffff;
  --bg-input:      #f8f9fc;
  --bg-hover:      #f0f2f8;
  --border:        #e2e5ed;
  --border-strong: #c8cdd9;

  /* Status colors */
  --green:         #1a8a4a;
  --green-bg:      #e6f7ee;
  --green-border:  #b3e0c4;
  --amber:         #b45309;
  --amber-bg:      #fef3e2;
  --amber-border:  #f8d59e;
  --red:           #c0392b;
  --red-bg:        #fdecea;
  --red-border:    #f5b7b1;
  --sky:           #0288d1;
  --sky-bg:        #e1f3fb;
  --sky-border:    #b3ddf5;
  --violet:        #6d3fc0;
  --violet-bg:     #f0ebfa;
  --violet-border: #cdb6ee;

  /* Text */
  --text-primary:   #1a1f36;
  --text-secondary: #515771;
  --text-muted:     #8b92aa;
  --text-inverse:   #ffffff;

  /* Radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;

  /* Shadow */
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:   0 8px 24px rgba(0,0,0,0.1), 0 4px 8px rgba(0,0,0,0.05);
  --shadow-modal:0 20px 60px rgba(0,0,0,0.18);

  /* Fonts */
  --font-body:     'Inter', 'DM Sans', system-ui, sans-serif;
  --font-heading:  'DM Sans', 'Inter', sans-serif;
  --font-mono:     'JetBrains Mono', 'Fira Code', monospace;

  --transition:    all 0.18s ease;

  /* Topbar */
  --topbar-h:    60px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════════
   TOPBAR LAYOUT
══════════════════════════════════════════ */
#app { min-height: 100vh; }

.portal-wrap {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Navigation Bar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--navy);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 0;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 32px;
  flex-shrink: 0;
}

.brand-logo, .brand-logo-text {
  width: 36px;
  height: 36px;
  background: #fff;
  color: var(--navy);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
  font-weight: 700;
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
}

.brand-name {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.62rem;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
}

/* Tab nav in topbar */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  height: 100%;
}

.topbar-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 100%;
  padding: 0 16px;
  font-size: 0.83rem;
  font-weight: 500;
  color: rgba(255,255,255,0.70);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: var(--transition);
  border: none;
  background: none;
  font-family: var(--font-body);
  white-space: nowrap;
  position: relative;
}

.topbar-tab:hover {
  color: rgba(255,255,255,0.95);
  background: rgba(255,255,255,0.07);
}

.topbar-tab.active {
  color: #fff;
  border-bottom: 3px solid #fff;
  font-weight: 600;
}

.topbar-tab .tab-icon { font-size: 0.95rem; }

/* Topbar right slot */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  flex-shrink: 0;
}

.topbar-role-switcher {
  display: flex;
  gap: 4px;
  background: rgba(255,255,255,0.12);
  padding: 3px;
  border-radius: 20px;
  margin-right: 8px;
}

.btn-role-pill {
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.75);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-body);
}

.btn-role-pill.active, .btn-role-pill:hover {
  background: #ffffff;
  color: #0f2537;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.topbar-role-badge {
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.topbar-role-badge.bank   { background: rgba(56,189,248,0.2);  color: #7de8ff; }
.topbar-role-badge.farmer { background: rgba(74,222,128,0.2);  color: #86efac; }
.topbar-role-badge.arya   { background: rgba(196,181,253,0.2); color: #c4b5fd; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
}

.topbar-username {
  font-size: 0.82rem;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
}

.btn-topbar-logout {
  padding: 5px 12px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.8);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-body);
}
.btn-topbar-logout:hover { background: rgba(255,255,255,0.18); color: #fff; }

/* Main content area */
.main-content {
  flex: 1;
  padding: 28px 32px;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

/* ══════════════════════════════════════════
   PAGE HEADER
══════════════════════════════════════════ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-family: var(--font-heading);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ══════════════════════════════════════════
   CARDS
══════════════════════════════════════════ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-family: var(--font-heading);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 20px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* ── Stat Cards ── */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-color, var(--blue));
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  background: var(--accent-bg, var(--blue-light));
  margin-bottom: 4px;
}

.stat-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-family: var(--font-heading); font-size: 1.75rem; font-weight: 700; color: var(--text-primary); }
.stat-sub   { font-size: 0.75rem; color: var(--text-muted); }

/* ══════════════════════════════════════════
   TABLES
══════════════════════════════════════════ */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead tr th {
  padding: 11px 16px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: #f8f9fc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead tr th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead tr th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

tbody tr td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-secondary);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }

.td-mono { font-family: var(--font-mono); font-size: 0.76rem; color: var(--text-muted); }
.td-main { color: var(--text-primary); font-weight: 600; }

/* ══════════════════════════════════════════
   STATUS BADGES
══════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge::before { content: '●'; font-size: 0.5rem; }

.badge-registered  { background: #f0f1f5;      color: var(--text-secondary); border-color: var(--border); }
.badge-evaluated   { background: var(--sky-bg); color: var(--sky); border-color: var(--sky-border); }
.badge-tokenized   { background: var(--blue-light); color: var(--blue); border-color: var(--blue-border); }
.badge-pledged     { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.badge-retiring    { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }
.badge-retired     { background: #f0f1f5;      color: var(--text-muted); border-color: var(--border); }
.badge-active      { background: var(--green-bg); color: var(--green); border-color: var(--green-border); }
.badge-released    { background: var(--sky-bg); color: var(--sky); border-color: var(--sky-border); }
.badge-liquidated  { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }
.badge-approved    { background: var(--green-bg); color: var(--green); border-color: var(--green-border); }
.badge-pending_kyc { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.badge-suspended   { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }
.badge-pending     { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.badge-confirmed   { background: var(--green-bg); color: var(--green); border-color: var(--green-border); }
.badge-failed      { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }

/* Loan request lifecycle: asked -> certified -> pledged -> the farmer answers.
   Amber for PLEDGED is deliberate: the collateral is locked and nobody has
   agreed to it yet, which is the state that should look unfinished. */
.badge-cm_requested        { background: var(--amber-bg);  color: var(--amber);  border-color: var(--amber-border); }
.badge-certified           { background: var(--blue-light); color: var(--blue);  border-color: var(--blue-border); }
.badge-pledged             { background: var(--amber-bg);  color: var(--amber);  border-color: var(--amber-border); }
.badge-consented           { background: var(--green-bg);  color: var(--green);  border-color: var(--green-border); }
.badge-declined            { background: #f0f1f5;          color: var(--text-muted); border-color: var(--border); }
.badge-declined_by_farmer  { background: var(--amber-bg);  color: var(--amber);  border-color: var(--amber-border); }
.badge-withdrawn           { background: #f0f1f5;          color: var(--text-muted); border-color: var(--border); }

/* Pledge request: asked for -> certified, or refused with a reason */
.badge-requested   { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.badge-refused     { background: #f0f1f5;      color: var(--text-muted); border-color: var(--border); }

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.btn-primary:hover { background: var(--navy-dark); box-shadow: 0 4px 12px rgba(27,42,107,0.28); }

.btn-secondary {
  background: var(--white);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { border-color: var(--navy); color: var(--navy); background: var(--navy-light); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: var(--red-border);
}
.btn-danger:hover { background: #f8d7d5; }

.btn-success {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green-border);
}
.btn-success:hover { background: #cceedd; }

.btn-amber {
  background: var(--amber-bg);
  color: var(--amber);
  border-color: var(--amber-border);
}
.btn-amber:hover { background: #fde8c4; }

.btn-violet {
  background: var(--violet-bg);
  color: var(--violet);
  border-color: var(--violet-border);
}
.btn-violet:hover { background: #e0d6f4; }

/* keep legacy names for compatibility */
.btn-gold { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.btn-gold:hover { background: #fde8c4; }

.btn-sm { padding: 6px 12px; font-size: 0.77rem; }
.btn-lg { padding: 12px 24px; font-size: 0.9rem; }
.btn-full { width: 100%; justify-content: center; }

/* Loading spinner */
.btn.loading { pointer-events: none; }
.btn.loading::after {
  content: '';
  width: 12px; height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 4px;
}

/* ══════════════════════════════════════════
   FORMS
══════════════════════════════════════════ */
.form-group { margin-bottom: 16px; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

label {
  display: block;
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}

input, select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.87rem;
  padding: 9px 13px;
  transition: var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--navy);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(27,42,107,0.1);
}

input::placeholder { color: var(--text-muted); }
select option { background: #fff; color: var(--text-primary); }
textarea { resize: vertical; min-height: 80px; }

.form-hint  { font-size: 0.73rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 0.73rem; color: var(--red); margin-top: 4px; }

/* ── Toggle ── */
.toggle-group {
  display: flex;
  gap: 0;
  background: #f0f2f8;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 4px;
}

.toggle-option {
  flex: 1;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
  color: var(--text-muted);
  border: none;
  background: none;
  font-family: var(--font-body);
}

.toggle-option.active {
  background: var(--white);
  color: var(--navy);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ══════════════════════════════════════════
   LOGIN / ROLE SELECTION PAGE
══════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
}

/* Login topbar */
.login-topbar {
  background: var(--navy);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.login-topbar .brand-logo, .login-topbar .brand-logo-text { width: 34px; height: 34px; font-size: 0.85rem; font-weight: 700; color: var(--navy); }
.login-topbar .brand-name { font-size: 1rem; font-weight: 700; color: #fff; }
.login-topbar .brand-sub  { font-size: 0.58rem; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 0.1em; }

.login-body {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 24px 60px;
}

.login-container {
  width: 100%;
  max-width: 980px;
}

.login-welcome {
  text-align: center;
  margin-bottom: 36px;
  padding-top: 12px;
}

.login-welcome h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.login-welcome p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Role cards */
.role-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.role-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px 20px 24px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.role-card:hover {
  border-color: var(--navy-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.role-card.selected-bank   { border-color: var(--blue);   box-shadow: 0 0 0 3px rgba(21,101,216,0.12), var(--shadow-md); }
.role-card.selected-farmer { border-color: var(--green);  box-shadow: 0 0 0 3px rgba(26,138,74,0.12), var(--shadow-md); }
.role-card.selected-arya   { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(109,63,192,0.12), var(--shadow-md); }

.role-icon-wrap {
  width: 56px; height: 56px;
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto 14px;
}

.bank-role   .role-icon-wrap { background: var(--blue-light); }
.farmer-role .role-icon-wrap { background: var(--green-bg); }
.arya-role   .role-icon-wrap { background: var(--violet-bg); }

/* keep legacy role-icon for compat */
.role-icon { font-size: 2rem; display: block; margin-bottom: 12px; }

.role-card h3 {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.role-card p {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.login-form-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px 32px;
  max-width: 440px;
  margin: 0 auto;
  box-shadow: var(--shadow-md);
}

.login-form-box h2 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.login-form-box .form-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ══════════════════════════════════════════
   ALERTS
══════════════════════════════════════════ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  border: 1px solid;
  margin-bottom: 16px;
}

.alert-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }

.alert-info    { background: var(--sky-bg);   border-color: var(--sky-border);   color: var(--sky); }
.alert-success { background: var(--green-bg); border-color: var(--green-border); color: var(--green); }
.alert-warning { background: var(--amber-bg); border-color: var(--amber-border); color: var(--amber); }
.alert-danger  { background: var(--red-bg);   border-color: var(--red-border);   color: var(--red); }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.25s ease;
  pointer-events: all;
  min-width: 280px;
  max-width: 380px;
}

.toast.toast-success { border-left: 4px solid var(--green); }
.toast.toast-error   { border-left: 4px solid var(--red); }
.toast.toast-info    { border-left: 4px solid var(--blue); }
.toast.toast-pending { border-left: 4px solid var(--amber); }

.toast-icon { font-size: 1rem; }
.toast-msg  { flex: 1; color: var(--text-primary); }
.toast-close { color: var(--text-muted); cursor: pointer; font-size: 1rem; background: none; border: none; padding: 0; }

/* ══════════════════════════════════════════
   MODALS
══════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,15,35,0.5);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  animation: slideUp 0.2s ease;
}

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

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 28px; height: 28px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: var(--transition);
}
.modal-close:hover { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }

.modal-body   { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: #fafbfd;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ══════════════════════════════════════════
   LOT CARD
══════════════════════════════════════════ */
.lot-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.lot-card:hover { border-color: var(--navy-border); box-shadow: var(--shadow-md); }

.lot-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
}

.lot-commodity { font-family: var(--font-heading); font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.lot-id { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

.lot-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.lot-stat-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
.lot-stat-value { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); }

.lot-progress {
  height: 5px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 14px;
}

.lot-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--navy));
  border-radius: 100px;
  transition: width 0.6s ease;
}

.lot-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ══════════════════════════════════════════
   PLEDGE CARD
══════════════════════════════════════════ */
.pledge-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.pledge-card-top {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: #fafbfd;
}

.pledge-id-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pledge-card-body { padding: 16px 18px; }

.pledge-details-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.pledge-detail-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
.pledge-detail-value { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); }

.ltv-bar-wrap { margin-bottom: 14px; }
.ltv-bar-label { display: flex; justify-content: space-between; margin-bottom: 6px; }
.ltv-bar-label span   { font-size: 0.75rem; color: var(--text-muted); }
.ltv-bar-label strong { font-size: 0.75rem; font-weight: 700; }

.ltv-bar {
  height: 6px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
}

.ltv-bar-fill {
  height: 100%;
  border-radius: 100px;
  transition: width 0.6s ease;
}

.ltv-safe    { background: var(--green); }
.ltv-warning { background: var(--amber); }
.ltv-danger  { background: var(--red); }

.pledge-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ══════════════════════════════════════════
   ENROLLMENT / PENDING SCREENS
══════════════════════════════════════════ */
.enrollment-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 40px;
}

.enrollment-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  animation: float 3s ease infinite;
}

.enrollment-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.enrollment-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 400px;
  margin-bottom: 28px;
}

/* ══════════════════════════════════════════
   WALLET DISPLAY
══════════════════════════════════════════ */
.wallet-display-card {
  background: linear-gradient(135deg, #eef1fb, #f4f0fb);
  border: 1px solid var(--navy-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.wallet-icon-wrap {
  width: 48px; height: 48px;
  background: var(--blue-light);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.wallet-info { min-width: 0; }
.wallet-info-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.wallet-info-addr  { font-family: var(--font-mono); font-size: 0.78rem; color: var(--navy); word-break: break-all; }

/* ══════════════════════════════════════════
   WALLET ADDRESS CHIP
══════════════════════════════════════════ */
.wallet-address {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--blue);
  background: var(--blue-light);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  display: inline-block;
  border: 1px solid var(--blue-border);
}
.wallet-address:hover { background: #d4e4fa; }

/* ══════════════════════════════════════════
   SECTION DIVIDER / EMPTY STATE
══════════════════════════════════════════ */
.section-divider {
  margin: 24px 0;
  border: none;
  border-top: 1px solid var(--border);
}

.empty-state {
  padding: 52px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 0.87rem; }

/* ══════════════════════════════════════════
   API DEBUG PANEL
══════════════════════════════════════════ */
.api-detail {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.api-detail-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--bg-input);
  user-select: none;
  font-family: var(--font-body);
  border: none;
  width: 100%;
  text-align: left;
}

.api-detail-toggle:hover { color: var(--text-secondary); }

.api-detail-body {
  padding: 12px 14px;
  background: #1a1f36;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: #a8b5cc;
  border-top: 1px solid var(--border);
  display: none;
  white-space: pre-wrap;
}

.api-detail-body.open { display: block; }

.api-method { color: #7dd3fc; font-weight: 600; }
.api-url    { color: #a3e635; }
.api-header { color: #fbbf24; }
.api-value  { color: #a8b5cc; }

/* ══════════════════════════════════════════
   PENDING ROW ANIMATION
══════════════════════════════════════════ */
.pending-row {
  animation: pendingPulse 1.5s ease infinite;
}

@keyframes pendingPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ══════════════════════════════════════════
   SCOPE CHIP
══════════════════════════════════════════ */
.scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 100px;
  font-size: 0.63rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--violet-bg);
  color: var(--violet);
  border: 1px solid var(--violet-border);
  margin-left: 6px;
}

/* ══════════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

.fade-in { animation: fadeIn 0.25s ease; }

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */
@media (max-width: 960px) {
  .main-content { padding: 20px 16px; }
  .role-cards { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .pledge-details-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .login-welcome h1 { font-size: 1.5rem; }
  .card-grid { grid-template-columns: 1fr; }
  .topbar-tab .tab-icon + span { display: none; }
}

/* ══════════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-page); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ══════════════════════════════════════════
   UTILITY
══════════════════════════════════════════ */
.text-navy   { color: var(--navy); }
.text-blue   { color: var(--blue); }
.text-green  { color: var(--green); }
.text-amber  { color: var(--amber); }
.text-red    { color: var(--red); }
.text-muted  { color: var(--text-muted); }
.text-right  { text-align: right; }
.text-center { text-align: center; }

/* keep legacy color utils */
.text-teal   { color: var(--blue); }
.text-gold   { color: var(--amber); }
.text-rose   { color: var(--red); }
.text-violet { color: var(--violet); }

.font-mono    { font-family: var(--font-mono); }
.font-heading { font-family: var(--font-heading); }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.mt-4         { margin-top: 4px; }
.mt-8         { margin-top: 8px; }
.mt-12        { margin-top: 12px; }
.mt-16        { margin-top: 16px; }
.mt-24        { margin-top: 24px; }
.mb-8         { margin-bottom: 8px; }
.mb-16        { margin-bottom: 16px; }
.mb-24        { margin-bottom: 24px; }
.hidden       { display: none !important; }

/* ══════════════════════════════════════════
   ERP QUERY-BASED TABLE STYLES (MATCHING ATTACHED DESIGN)
   ══════════════════════════════════════════ */
.erp-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

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

.erp-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.erp-title-group h2 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.erp-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.erp-select-sm {
  /* Long farmer names would otherwise stretch the select across the bar. */
  max-width: 260px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 0.8rem;
  font-family: var(--font-body);
  color: var(--text-primary);
  cursor: pointer;
}

.erp-btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
}
.erp-btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.erp-query-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #fcfcfd;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.erp-search-field {
  /* Grows to fill the row, but yields before the controls beside it wrap:
     the filter, the reset and the count belong on the same line as the search
     box, not stacked under it. */
  flex: 1 1 240px;
  min-width: 180px;
  position: relative;
}

.erp-search-input {
  width: 100%;
  padding: 7px 12px 7px 32px;
  font-size: 0.82rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-primary);
  font-family: var(--font-body);
}

.erp-search-input:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 2px rgba(27, 42, 107, 0.1);
}

.erp-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.85rem;
  pointer-events: none;
}

.erp-filter-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}

.erp-count-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: auto;
}

.erp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.erp-table th {
  padding: 10px 14px;
  background: #f8f9fc;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.erp-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}

.erp-table tr:hover td {
  background: #f8fafd;
}

/*
 * Fixed-layout collateral table.
 *
 * The action column carries up to three buttons. Left to `auto` layout the
 * browser widens that column to fit them, every other column is squeezed, and
 * the buttons still overflow the table's right edge -- which is what the
 * misalignment was. Fixed layout plus stated widths means the columns are
 * decided by the header, and the buttons wrap inside their cell instead of
 * pushing it.
 */
.erp-table-fixed {
  table-layout: fixed;
  width: 100%;
}

.erp-table-fixed th,
.erp-table-fixed td {
  overflow-wrap: anywhere;
}

.erp-table-fixed .col-check     { width: 40px; }
.erp-table-fixed .col-farmer    { width: 15%; }
.erp-table-fixed .col-commodity { width: 11%; }
.erp-table-fixed .col-lot       { width: 13%; }
.erp-table-fixed .col-num       { width: 9%;  text-align: right; }
.erp-table-fixed .col-status    { width: 10%; }
.erp-table-fixed .col-action    { width: 15%; }

/* Numbers line up on their right edge, so magnitudes are comparable down the
   column; everything else stays left-aligned. */
.erp-table-fixed th.col-num { text-align: right; }

.erp-table-fixed td,
.erp-table-fixed th {
  vertical-align: middle;
}

/* Two-line cells: the value, then its identifier underneath. */
.cell-main {
  font-weight: 600;
  line-height: 1.35;
}

.cell-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin-top: 2px;
}

/* Buttons inside a cell. Never on the <td> itself -- a flex table cell loses
   its column width and drags the row out of alignment. */
.cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.erp-table tr.row-selected td {
  background: #f0f7ff;
}

/* The batch bar above the table, shown once something is selected. */
.erp-batch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: #eef6ff;
  border-bottom: 1px solid #b3d7ff;
  flex-wrap: wrap;
}

.erp-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--navy);
  cursor: pointer;
}

/* Cropwise Grouping */
.crop-group-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

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

.crop-group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
}

.crop-badge-count {
  background: var(--blue-light);
  color: var(--blue);
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Simplified Farmer Dashboard Cards */
.farmer-metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.farmer-metric-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
}

.farmer-metric-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--blue-light);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
  flex-shrink: 0;
}

.farmer-metric-val {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.farmer-metric-lbl {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}


/* ── API connection chip & local-only marker ───────────────────────────────
   The portal now talks to a real backend, so two things must be visible at a
   glance: whether it is connected, and which screens are showing data no API
   backs. Both live in the topbar so they follow the user across views. */

.api-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.api-chip:hover { background: rgba(127, 127, 127, 0.12); }

.api-chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.api-chip-ok    { color: #15803d; border-color: rgba(21, 128, 61, 0.35); }
.api-chip-warn  { color: #b45309; border-color: rgba(180, 83, 9, 0.35); }
.api-chip-muted { color: var(--text-muted); }

.local-only-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  margin-left: 10px;
  border-radius: 4px;
  border: 1px dashed rgba(180, 83, 9, 0.5);
  background: rgba(180, 83, 9, 0.08);
  color: #b45309;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
  cursor: help;
}
