/* Mobile-first tender tracker styles */
:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1a2238;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --ok-bg: #f0fdf4;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 15px; line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a.back { color: white; margin-right: 6px; }

.topbar {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white; padding: 16px 18px; box-shadow: 0 2px 6px rgba(0,0,0,.08);
  position: relative;
}
.topbar .brand { font-weight: 700; font-size: 20px; }
.topbar .sub { font-size: 13px; opacity: 0.85; margin-top: 2px; }

/* Right-aligned user pill + logout button (mounted by auth.js) */
.topbar .user-pill {
  position: absolute; top: 12px; right: 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: white;
}
.topbar .user-pill .who { display: flex; align-items: center; gap: 6px; }
.topbar .user-pill .role {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  font-size: 10px; font-weight: 700; letter-spacing: .3px;
  background: rgba(255,255,255,.18);
}
.topbar .user-pill .role-admin { background: #15803d; }
.topbar .user-pill .role-staff { background: #6b7280; }
.topbar .user-pill .logout-btn {
  background: rgba(255,255,255,.15); color: white;
  border: 1px solid rgba(255,255,255,.3);
  padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.topbar .user-pill .logout-btn:hover { background: rgba(255,255,255,.28); }

/* Right-aligned action cluster on pages where header has a Labours/etc link.
   When the user-pill mounts inside this container it switches to in-flow
   (.user-pill-inline) so it sits next to the link rather than overlapping it. */
.topbar .topbar-actions {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.topbar .topbar-link {
  background: rgba(255,255,255,.15); color: white;
  border: 1px solid rgba(255,255,255,.3);
  padding: 6px 12px; border-radius: 8px; font-size: 13px;
  text-decoration: none; white-space: nowrap;
}
.topbar .topbar-link:hover { background: rgba(255,255,255,.28); }
.topbar .user-pill.user-pill-inline {
  position: static; top: auto; right: auto;
}

.container { max-width: 980px; margin: 0 auto; padding: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.card h2, .card h3 { margin: 0 0 10px 0; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap > * + * { margin-left: 8px; }

.btn {
  display: inline-block; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: white; color: var(--ink); cursor: pointer; font-size: 14px; font-weight: 500;
}
.btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.formgrid { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 10px 0; }
.formgrid label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); min-width: 0; }
.formgrid input, .formgrid select {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; margin-top: 4px;
  background: white; color: var(--ink);
  /* Without border-box the padding+border pushes inputs past their grid
     column, which made the Password field spill out of the login card. */
  box-sizing: border-box; width: 100%; max-width: 100%; min-width: 0;
}
@media (min-width: 700px) { .formgrid { grid-template-columns: repeat(2, 1fr); } }

/* Tender cards on dashboard */
.tender-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 700px) { .tender-grid { grid-template-columns: repeat(2, 1fr); } }
.tender-tile {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px;
  background: white; cursor: pointer; transition: transform .08s ease;
}
.tender-tile:hover { transform: translateY(-1px); border-color: var(--primary); }
.tender-tile h3 { margin: 0 0 6px; font-size: 16px; }
.tile-delete {
  position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: white; color: var(--muted);
  cursor: pointer; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: all .1s ease;
}
.tile-delete:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.tender-tile .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 12px; font-size: 12px; }
.tender-tile .stats > div { min-width: 0; }
.tender-tile .stats div b { display: block; font-size: 14px; color: var(--ink); line-height: 1.25; }
/* Small accounting context line that sits under each ₹ amount
   (e.g. "37.75% of tender · 97.87% of earned"). */
.tender-tile .stats .amount-sub {
  display: block; margin-top: 2px; font-size: 11px; line-height: 1.3;
  color: var(--muted);
}
/* Small percentage strip under a ₹ amount inside a table cell (used by
   Payments history rows + totals row). Stays on its own line so the bold
   amount sits flush against the row baseline. */
.amount-pct-sub {
  display: block; margin-top: 3px; font-size: 11px; line-height: 1.35;
  color: var(--muted);
}
.alert-banner { background: var(--danger-bg); color: var(--danger); padding: 8px 10px; border-radius: 6px; font-weight: 600; font-size: 13px; margin-top: 8px; }
.ok-banner { background: var(--ok-bg); color: var(--ok); padding: 8px 10px; border-radius: 6px; font-size: 13px; margin-top: 8px; }

/* Summary panel */
.summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .summary { grid-template-columns: repeat(4, 1fr); } }
.summary .stat { padding: 10px; border-radius: 8px; background: #f9fafb; }
.summary .stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.summary .stat .value { font-size: 18px; font-weight: 700; margin-top: 2px; }
.summary .stat.alert { background: var(--danger-bg); color: var(--danger); }
.summary .stat.ok { background: var(--ok-bg); color: var(--ok); }

/* Progress bar */
.progress { background: #e5e7eb; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress > div { background: var(--primary); height: 100%; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tab { padding: 8px 12px; background: transparent; border: none; border-bottom: 2px solid transparent; cursor: pointer; font-size: 14px; color: var(--muted); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tabpanel { display: none; }
.tabpanel.active { display: block; }

/* Line items */
.section-block { margin-bottom: 18px; }
.section-block h4 { margin: 4px 0 8px; padding: 6px 10px; background: #eef2ff; border-radius: 6px; font-size: 13px; }
.subsection { font-weight: 600; font-size: 13px; color: var(--muted); margin: 8px 4px 4px; }
.item-row {
  display: grid; grid-template-columns: 1fr; gap: 4px;
  padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: 8px; cursor: pointer; background: white;
}
.item-row:hover { border-color: var(--primary); }
.item-row .top { display: flex; justify-content: space-between; gap: 8px; }
.item-row .desc { font-size: 13px; flex: 1; }
.item-row .sr { font-size: 11px; color: var(--muted); margin-right: 6px; font-weight: 600; }
.item-row .meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--muted); }
.item-row .pct-bar { background: #e5e7eb; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.item-row .pct-bar > div { background: var(--ok); height: 100%; }
.item-row.scope-per_flat { border-left: 3px solid var(--primary); }
.item-row.scope-common { border-left: 3px solid var(--warn); }
.tag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 10px; background: #e0e7ff; color: var(--primary); }
.tag.common { background: #fef3c7; color: var(--warn); }

/* Tables */
.table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.table th, .table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { background: #f9fafb; font-weight: 600; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { padding: 4px 10px; background: #eef2ff; border-radius: 12px; font-size: 12px; color: var(--primary); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal-card { background: white; border-radius: 12px; padding: 20px; max-width: 500px; width: 100%; max-height: 90vh; overflow-y: auto; }
