:root {
  --dd-blue: #2563eb;
  --dd-blue-dark: #1d4ed8;
  --dd-teal: #06b6d4;
  --dd-green: #16a34a;
  --dd-amber: #f59e0b;
  --dd-red: #dc2626;
  --dd-navy: linear-gradient(135deg, #0f2540 0%, #14335c 60%, #0d6efd 130%);
  --dd-navy-solid: #0f2540;
  --dd-bg: #eef2f9;
}

* { box-sizing: border-box; }

body {
  background-color: var(--dd-bg);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1c2536;
}

/* Gujarati translation text — hidden by default, revealed via the topbar toggle */
.gu-text { display: none; }
body.show-gujarati .gu-text {
  display: inline-block;
  color: #7a8699;
  font-weight: 400;
  font-size: 0.85em;
  margin-left: 0.3rem;
}
body.show-gujarati .bottom-nav-label .gu-text,
body.show-gujarati th .gu-text { display: block; margin-left: 0; }
body.show-gujarati th .gu-text { text-transform: none; font-weight: 400; color: rgba(255,255,255,0.65) !important; }
body.show-gujarati .btn .gu-text { color: inherit; opacity: 0.85; }

.gu-toggle-btn {
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: 2rem;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255,255,255,0.08);
  transition: background-color 0.15s ease;
}
.gu-toggle-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.gu-toggle-btn.active { background: var(--dd-teal); border-color: var(--dd-teal); color: #05323b; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--dd-navy);
  z-index: 1030;
  box-shadow: 0 2px 14px rgba(0,0,0,0.18);
}
.topbar .navbar-brand { font-size: 1.2rem; }

.topbar-search {
  flex: 1 1 auto;
  max-width: 420px;
  margin: 0 1rem;
}
.topbar-search input {
  border-radius: 2rem;
  border: none;
  padding: 0.55rem 1rem 0.55rem 2.5rem;
  background-color: rgba(255,255,255,0.15);
  color: #fff;
}
.topbar-search input::placeholder { color: rgba(255,255,255,0.7); }
.topbar-search input:focus {
  background-color: #fff;
  color: #212529;
  box-shadow: 0 0 0 3px rgba(6,182,212,0.35);
}
.topbar-search input:focus::placeholder { color: #6c757d; }
.topbar-search-wrap { position: relative; }
.topbar-search-wrap i {
  position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%);
  color: rgba(255,255,255,0.7); pointer-events: none;
}
.topbar-search-wrap input:focus + i,
.topbar-search-wrap input:not(:placeholder-shown) + i { color: #6c757d; }

@media (max-width: 767.98px) {
  .topbar-search { display: none; }
}

/* ---------- Layout shell ---------- */
.app-shell { display: block; }

.main-content {
  padding: 1.5rem;
  min-width: 0;
  padding-bottom: 5.5rem; /* clearance for the fixed bottom nav */
  max-width: 1400px;
  margin: 0 auto;
}

.app-footer {
  background: #fff;
  border-top: 1px solid #e9ecef;
  margin-bottom: 4.25rem; /* clearance for the fixed bottom nav */
}

/* ---------- Bottom navigation (primary app nav, mobile-app style) ---------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1040;
  display: flex;
  background: var(--dd-navy);
  box-shadow: 0 -2px 16px rgba(0,0,0,0.2);
  padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
}
.bottom-nav-link {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.4rem 0.2rem;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  border-radius: 0.75rem;
  margin: 0 0.15rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.bottom-nav-link i { font-size: 1.3rem; }
.bottom-nav-label { font-size: 0.72rem; font-weight: 600; text-align: center; line-height: 1.15; }
.bottom-nav-link:hover { color: #fff; background-color: rgba(255,255,255,0.08); }
.bottom-nav-link.active {
  color: #fff;
  background: linear-gradient(180deg, rgba(37,99,235,0.9), rgba(6,182,212,0.55));
}

@media (min-width: 768px) {
  .bottom-nav-link i { font-size: 1.15rem; }
  .bottom-nav-label { font-size: 0.78rem; }
}

/* ---------- Dashboard cards / nav cards ---------- */
.stat-card {
  border: none;
  border-radius: 1rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  height: 100%;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
  background-color: var(--dd-blue);
}
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-card .stat-label { color: #6c757d; font-size: 0.85rem; }

a.nav-card-link { text-decoration: none; }
a.nav-card-link .card {
  border-radius: 1.1rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border-top: 4px solid var(--dd-blue);
  background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
}
a.nav-card-link:hover .card {
  transform: translateY(-4px);
  box-shadow: 0 10px 28px rgba(37,99,235,0.2);
}
a.nav-card-link .card i {
  font-size: 1.9rem;
  width: 56px; height: 56px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 1rem;
  background: rgba(37,99,235,0.1);
}

/* ---------- Forms ---------- */
.entry-form label,
.card-body label.form-label { font-weight: 600; font-size: 0.9rem; color: #344054; }
.entry-form .form-control,
.entry-form .form-select { padding: 0.6rem 0.75rem; font-size: 1rem; }
.form-control, .form-select {
  border-radius: 0.6rem;
  border-color: #dbe2ea;
}
.form-control:focus, .form-select:focus {
  border-color: var(--dd-blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.btn-lg-touch {
  padding: 0.75rem 1.5rem;
  font-size: 1.05rem;
}
.btn { border-radius: 0.6rem; font-weight: 500; }
.btn-primary { background-color: var(--dd-blue); border-color: var(--dd-blue); }
.btn-primary:hover { background-color: var(--dd-blue-dark); border-color: var(--dd-blue-dark); }
.btn-outline-primary { color: var(--dd-blue); border-color: var(--dd-blue); }
.btn-outline-primary:hover { background-color: var(--dd-blue); border-color: var(--dd-blue); }

.card { border-radius: 1rem; border: none; box-shadow: 0 2px 14px rgba(15,37,64,0.07); }
.card-header { background-color: #fff; border-bottom: 1px solid #eef1f5; font-weight: 600; border-radius: 1rem 1rem 0 0 !important; }

/* ---------- Tables ---------- */
.table thead th {
  white-space: nowrap;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #fff !important;
  background: var(--dd-navy-solid) !important;
  border-bottom-width: 0;
  padding: 0.75rem;
}
.table thead th a { color: #fff; }
.table td, .table th { vertical-align: middle; padding: 0.65rem 0.75rem; }
.table-striped > tbody > tr:nth-of-type(odd) > * { background-color: #f8fafc; }
.table-hover > tbody > tr:hover > * { background-color: #e8f1ff; }
.table-bordered { border-color: #e9ecef; }
.matrix-table thead th { position: sticky; top: 0; z-index: 2; }

/* Sticky first column, applied to every scrollable table app-wide — the row
   label (Month/Vendor/Supplier/Date/etc.) stays visible during horizontal
   scroll. Opt out with .no-sticky-col (used only where the first column
   uses rowspan, which sticky positioning can't track correctly). */
.sticky-col,
.table-responsive .table thead tr th:first-child,
.table-responsive .table tbody tr td:first-child,
.table-responsive .table tfoot tr td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background-color: #fff;
  box-shadow: 2px 0 4px rgba(0,0,0,0.06);
}
thead .sticky-col,
.table-responsive .table thead tr th:first-child {
  z-index: 4;
  background: var(--dd-navy-solid) !important;
}
tfoot .sticky-col,
.table-responsive .table tfoot tr td:first-child {
  background-color: #eef1f5;
}
.table-hover > tbody > tr:hover > .sticky-col,
.table-responsive .table-hover tbody tr:hover td:first-child {
  background-color: #e8f1ff;
}
.table-responsive .table-striped tbody tr:nth-of-type(odd) td:first-child {
  background-color: #f8fafc;
}

.no-sticky-col th:first-child,
.no-sticky-col td:first-child {
  position: static !important;
  box-shadow: none !important;
}

.table-responsive {
  border-radius: 0 0 1rem 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.audit-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: middle;
}
.audit-dot-green { background-color: var(--dd-green); box-shadow: 0 0 0 3px rgba(22,163,74,0.15); }
.audit-dot-red { background-color: var(--dd-red); box-shadow: 0 0 0 3px rgba(220,38,38,0.15); }

.badge-status-active { background-color: var(--dd-green); }
.badge-status-inactive { background-color: #6c757d; }

/* ---------- Auth pages ---------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--dd-navy);
  padding: 1rem;
}
.auth-card {
  max-width: 400px;
  width: 100%;
  border-radius: 1.2rem;
  box-shadow: 0 15px 45px rgba(0,0,0,0.3);
}

/* ---------- Mobile ---------- */
@media (max-width: 991.98px) {
  .main-content { padding: 1rem 0.75rem 5.5rem; }
  .card-header { flex-wrap: wrap; }
}
@media (max-width: 575.98px) {
  .stat-card .stat-value { font-size: 1.2rem; }
  .table thead th, .table td { padding: 0.5rem; font-size: 0.9rem; }
  h4 { font-size: 1.15rem; }
  .bottom-nav-label { font-size: 0.65rem; }
}

/* ---------- Tablet / iPad: shrink tables so more columns fit before scrolling ---------- */
@media (max-width: 1180px) {
  .main-content { max-width: none; padding-left: 0.75rem; padding-right: 0.75rem; }
  .table thead th { font-size: 0.68rem; padding: 0.5rem 0.4rem; }
  .table td, .table th { padding: 0.4rem 0.45rem; font-size: 0.85rem; }
  .matrix-cell, .form-control-sm { padding: 0.3rem 0.4rem; font-size: 0.85rem; }
  .matrix-table th, .matrix-table td { min-width: 0; }
  th .gu-text, .bottom-nav-label .gu-text { font-size: 0.62rem; }
  /* Hide number input spinner arrows to reclaim width in dense entry grids */
  input[type="number"]::-webkit-inner-spin-button,
  input[type="number"]::-webkit-outer-spin-button { margin: 0; }
}
@media (max-width: 900px) {
  .table thead th { font-size: 0.62rem; padding: 0.4rem 0.3rem; }
  .table td, .table th { padding: 0.35rem 0.35rem; font-size: 0.8rem; }
  .card-header { padding: 0.65rem 0.75rem; }
  .card-body { padding: 0.85rem; }
}

/* Shrink label columns that were given a generous fixed/min-width for
   desktop, so wide matrix tables (months as columns) fit tighter on iPad. */
@media (max-width: 1024px) {
  .matrix-table th[style*="min-width"] { min-width: 90px !important; }
  #dailyMilkMatrix th[style*="width:160px"],
  .matrix-table th[style*="width:160px"] { width: 70px !important; }
  th[style*="width:120px"] { width: 70px !important; }
}
