:root {
  --brand-primary: #0B1F3A;
  --brand-primary-2: #123056;
  --brand-accent: #A8B0BD;
  --brand-silver: #C5CBD3;
  --brand-surface: #F5F7FA;
  --brand-ink: #0B1F3A;
  --brand-muted: #6B7380;
  --brand-card: #ffffff;
  --brand-border: rgba(11, 31, 58, 0.14);
  --radius: 5px;
  --ctrl-h: 46px;
  --bottom-nav-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-bs-theme="dark"] {
  --brand-primary: #7EA2D6;
  --brand-primary-2: #2A4A78;
  --brand-accent: #C5CBD3;
  --brand-silver: #8E98A8;
  --brand-surface: #0A1220;
  --brand-ink: #E8EEF6;
  --brand-muted: #9AA5B5;
  --brand-card: #121C2C;
  --brand-border: rgba(197, 203, 211, 0.16);
}

@font-face {
  font-family: 'IRANSans';
  src: local('IRANSans'), local('IRANSansX'), local('Vazirmatn');
  font-weight: 100 900;
  font-display: swap;
}

* { box-sizing: border-box; }

html {
  font-size: 15px;
}

@media (min-width: 768px) {
  html { font-size: 16px; }
}

@media (min-width: 1200px) {
  html { font-size: 17px; }
}

html, body {
  font-family: 'IRANSans', 'Vazirmatn', Tahoma, sans-serif !important;
  background: var(--brand-surface);
  color: var(--brand-ink);
  min-height: 100%;
  text-align: center;
}

.field-en {
  direction: ltr !important;
  text-align: center !important;
  font-family: Tahoma, Arial, sans-serif !important;
}

.bill-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.35rem;
  margin-bottom: 1rem;
  width: 100%;
}

.bill-tab {
  border: 1px solid var(--brand-border);
  background: var(--brand-card);
  color: var(--brand-muted);
  border-radius: var(--radius);
  min-height: 40px;
  padding: 0.4rem 0.2rem;
  font-size: clamp(0.68rem, 2.6vw, 0.9rem);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: center;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bill-tab.active {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}

.bill-tab:hover {
  color: var(--brand-primary);
}

.bill-tab.active:hover {
  color: #fff;
}

@media (min-width: 992px) {
  .bill-tabs {
    gap: 0.5rem;
  }
  .bill-tab {
    min-height: 44px;
    font-size: 0.95rem;
    padding: 0.55rem 0.75rem;
  }
}

body.app-body {
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 12px);
}

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

.app-topbar {
  background: linear-gradient(135deg, #0B1F3A 0%, #123056 55%, #0B1F3A 100%);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 8px 24px rgba(11, 31, 58, 0.28);
}

.app-topbar .brand-title {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.app-topbar .brand-sub {
  font-size: 0.72rem;
  opacity: 0.8;
}

.text-bg-navy,
#mobileMenu.offcanvas {
  background: linear-gradient(180deg, #0B1F3A 0%, #123056 100%) !important;
  color: #fff;
}

#mobileMenu .nav-link {
  color: rgba(255, 255, 255, 0.85);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.25rem;
  font-weight: 600;
  text-align: right;
}

#mobileMenu .nav-link.active,
#mobileMenu .nav-link:hover {
  background: rgba(197, 203, 211, 0.18);
  color: #fff;
}

.sidebar-desktop {
  width: 260px;
  background: linear-gradient(180deg, #0B1F3A 0%, #123056 100%);
  border-left: 1px solid rgba(197, 203, 211, 0.18);
  min-height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
  text-align: right;
}

.sidebar-desktop .nav-link {
  color: rgba(255, 255, 255, 0.82);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.25rem;
  font-weight: 600;
  text-align: right;
}

.sidebar-desktop .nav-link.active,
.sidebar-desktop .nav-link:hover {
  background: rgba(197, 203, 211, 0.18);
  color: #ffffff;
}

[data-bs-theme="dark"] .sidebar-desktop {
  background: linear-gradient(180deg, #071427 0%, #0B1F3A 100%);
}

[data-bs-theme="dark"] .sidebar-desktop .nav-link.active,
[data-bs-theme="dark"] .sidebar-desktop .nav-link:hover {
  background: rgba(126, 162, 214, 0.22);
  color: #ffffff;
}

.main-wrap { min-width: 0; text-align: center; }

.stat-card, .panel, .brand-row, .modal-content {
  background: var(--brand-card);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
}

.stat-card {
  padding: 1rem 1.1rem;
  height: 100%;
  box-shadow: 0 8px 24px rgba(11, 31, 58, 0.05);
}

.stat-card .label { color: var(--brand-muted); font-size: 0.85rem; }
.stat-card .value { font-size: 1.45rem; font-weight: 800; margin-top: 0.25rem; }
.stat-card .icon {
  width: 42px; height: 42px; border-radius: var(--radius);
  display: grid; place-items: center;
  background: rgba(168, 176, 189, 0.25);
  color: var(--brand-primary);
  margin: 0 auto;
}

.panel {
  padding: 1.1rem;
  box-shadow: 0 8px 24px rgba(11, 31, 58, 0.05);
}

.btn, .btn-brand, .btn-accent, .btn-outline-secondary, .btn-outline-danger, .btn-outline-primary, .btn-sm, .btn-light {
  border-radius: var(--radius) !important;
  min-height: var(--ctrl-h);
  padding: 0.65rem 1rem !important;
  font-weight: 700;
  font-size: 0.95rem !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.btn-sm {
  min-height: 38px;
  padding: 0.45rem 0.8rem !important;
  font-size: 0.85rem !important;
}

.btn-brand {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}
.btn-brand:hover { background: var(--brand-primary-2); border-color: var(--brand-primary-2); color: #fff; }

.btn-accent {
  background: var(--brand-silver);
  border-color: var(--brand-silver);
  color: #0B1F3A;
}

.form-control, .form-select, textarea.form-control {
  border-radius: var(--radius) !important;
  min-height: var(--ctrl-h);
  padding: 0.65rem 0.85rem;
  font-size: 16px !important;
  border-color: var(--brand-border);
  background: var(--brand-card);
  color: var(--brand-ink);
  text-align: center !important;
}

.form-label {
  font-weight: 700;
  font-size: 0.9rem;
  display: block;
  text-align: center;
  width: 100%;
}

.badge-soft {
  background: rgba(11, 31, 58, 0.08);
  color: var(--brand-primary);
  border-radius: var(--radius);
  padding: 0.35rem 0.7rem;
  font-weight: 700;
}

.badge-done {
  background: rgba(168, 176, 189, 0.35);
  color: #0B1F3A;
  border-radius: var(--radius);
  padding: 0.35rem 0.7rem;
  font-weight: 700;
}

[data-bs-theme="dark"] .badge-done { color: var(--brand-silver); }

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--brand-card);
  border-top: 1px solid var(--brand-border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 1040;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.06);
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--brand-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.bottom-nav a.active { color: var(--brand-primary); }
.bottom-nav i { font-size: 1.25rem; }

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 20%, rgba(168,176,189,0.28), transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(11,31,58,0.45), transparent 35%),
    linear-gradient(160deg, #0B1F3A, #0A1220 60%);
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.login-card {
  width: min(420px, 100%);
  background: rgba(255,255,255,0.97);
  border-radius: var(--radius);
  padding: 1.75rem 1.4rem;
  box-shadow: 0 30px 80px rgba(0,0,0,0.35);
  text-align: center;
}

[data-bs-theme="dark"] .login-card {
  background: rgba(18,28,44,0.96);
}

.login-logo {
  width: 64px; height: 64px; border-radius: var(--radius);
  background: linear-gradient(135deg, #0B1F3A, #A8B0BD);
  display: grid; place-items: center; color: #fff; font-size: 1.6rem;
  margin: 0 auto 1rem;
}

.brand-row {
  display: flex; justify-content: space-between; gap: 0.75rem; align-items: flex-start;
  padding: 1rem;
  margin-bottom: 0.75rem;
  text-align: right;
}

.brand-row.completed {
  border-color: rgba(168, 176, 189, 0.7);
  background: rgba(168, 176, 189, 0.12);
}

.brand-row.slot-empty,
.brand-row.slot-status-empty {
  border-style: dashed;
  border-color: rgba(148, 156, 168, 0.55);
  background: rgba(197, 203, 211, 0.18);
}

.brand-row.slot-status-partial {
  border-style: solid;
  border-color: rgba(217, 119, 6, 0.45);
  background: rgba(251, 191, 36, 0.18);
}

.brand-row.slot-status-shortage {
  border-style: solid;
  border-color: rgba(185, 28, 28, 0.4);
  background: rgba(248, 113, 113, 0.16);
}

.brand-row.slot-status-full {
  border-style: solid;
  border-color: rgba(22, 163, 74, 0.45);
  background: rgba(74, 222, 128, 0.18);
}

.slot-badge {
  border-radius: var(--radius);
  padding: 0.3rem 0.65rem;
  font-weight: 700;
  font-size: 0.78rem;
}

.slot-badge-empty {
  background: rgba(148, 156, 168, 0.22);
  color: #4b5563;
}

.slot-badge-partial {
  background: rgba(217, 119, 6, 0.18);
  color: #b45309;
}

.slot-badge-shortage {
  background: rgba(185, 28, 28, 0.16);
  color: #b91c1c;
}

.slot-badge-full {
  background: rgba(22, 163, 74, 0.18);
  color: #15803d;
}

.brand-card {
  background: var(--brand-card);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
  margin-bottom: 0.85rem;
  overflow: hidden;
  text-align: center;
  box-shadow: 0 8px 22px rgba(11, 31, 58, 0.05);
}

.brand-card--idle {
  border-color: rgba(148, 156, 168, 0.55);
  background: rgba(197, 203, 211, 0.14);
}

.brand-card--partial {
  border-color: rgba(217, 119, 6, 0.45);
  background: rgba(251, 191, 36, 0.14);
}

.brand-card--done {
  border-color: rgba(22, 163, 74, 0.45);
  background: rgba(74, 222, 128, 0.16);
}

.brand-card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.85rem 0.9rem;
  background: linear-gradient(135deg, #0B1F3A 0%, #123056 100%);
  color: #fff;
  text-align: right;
}

.brand-card--idle .brand-card__header {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
}

.brand-card--partial .brand-card__header {
  background: linear-gradient(135deg, #c2410c 0%, #ea580c 100%);
}

.brand-card--done .brand-card__header {
  background: linear-gradient(135deg, #166534 0%, #16a34a 100%);
}

.brand-card__title {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.brand-card__name {
  margin: 0;
  font-size: clamp(0.95rem, 3.2vw, 1.15rem);
  font-weight: 800;
}

.brand-card__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.brand-card__header .badge-soft {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.brand-card__header .badge-done {
  background: rgba(197, 203, 211, 0.35);
  color: #fff;
}

.brand-card__tons {
  text-align: left;
  direction: ltr;
  font-weight: 800;
  font-size: 0.95rem;
}

.brand-card__tons small {
  display: block;
  font-weight: 600;
  font-size: 0.72rem;
  opacity: 0.85;
  direction: rtl;
  text-align: right;
  margin-top: 0.15rem;
}

.brand-card__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  padding: 0.85rem;
}

@media (min-width: 576px) {
  .brand-card__grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 992px) {
  .brand-card__grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.7rem;
    padding: 1rem;
  }
}

.brand-stat {
  background: rgba(11, 31, 58, 0.04);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
  padding: 0.65rem 0.45rem;
  min-height: 78px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
}

.brand-stat__label {
  color: var(--brand-muted);
  font-size: clamp(0.68rem, 2.4vw, 0.78rem);
  font-weight: 700;
  line-height: 1.3;
}

.brand-stat__value {
  font-size: clamp(0.95rem, 3.4vw, 1.15rem);
  font-weight: 800;
  color: var(--brand-ink);
  line-height: 1.2;
}

.brand-stat__unit {
  font-size: 0.68rem;
  color: var(--brand-muted);
}

.brand-stat--ok {
  background: rgba(18, 120, 80, 0.08);
  border-color: rgba(18, 120, 80, 0.2);
}

.brand-stat--warn {
  background: rgba(180, 90, 30, 0.08);
  border-color: rgba(180, 90, 30, 0.22);
}

.brand-stat--remain {
  background: rgba(11, 31, 58, 0.08);
  border-color: rgba(11, 31, 58, 0.18);
}

.brand-card__progress {
  padding: 0 0.85rem 0.75rem;
}

.brand-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  padding: 0.75rem 0.85rem 0.95rem;
  border-top: 1px solid var(--brand-border);
  background: rgba(11, 31, 58, 0.02);
}

.progress-thin { height: 8px; border-radius: var(--radius); background: rgba(11,31,58,0.08); overflow: hidden; }
.progress-thin > span {
  display: block; height: 100%; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--brand-primary), var(--brand-silver));
}

.nav-pills-mobile .nav-link {
  border-radius: var(--radius);
  white-space: nowrap;
  color: var(--brand-muted);
  font-weight: 700;
  background: transparent;
  min-height: 38px;
}
.nav-pills-mobile .nav-link.active {
  background: var(--brand-primary);
  color: #fff;
}

.table > :not(caption) > * > * {
  background: transparent;
  color: var(--brand-ink);
  vertical-align: middle;
  text-align: center;
}

.modal-content {
  border: 0;
  color: var(--brand-ink);
}

.modal-header, .modal-footer {
  border-color: var(--brand-border);
  text-align: center;
}

.modal-title { font-weight: 800; width: 100%; text-align: center; }
.modal-body { text-align: center; }
.modal-dialog-scrollable .modal-body { max-height: min(70vh, 560px); }

.calc-box {
  background: rgba(11, 31, 58, 0.06);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-top: 0.5rem;
}

.num { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; direction: ltr; display: inline-block; }

jdp-container,
.jdp-container {
  font-family: 'IRANSans', 'Vazirmatn', Tahoma, sans-serif !important;
  z-index: 200000 !important;
}

body.jdp-open {
  overflow: hidden !important;
}

body.jdp-open .bottom-nav {
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 991.98px) {
  body.jdp-open jdp-container,
  body.jdp-open .jdp-container,
  body.jdp-open .jdp-mobile-ready {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100vw !important;
    max-width: 100vw !important;
    transform: none !important;
    margin: 0 !important;
    border-radius: 16px 16px 0 0 !important;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28) !important;
    max-height: 70vh !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

@media (min-width: 992px) {
  body.app-body { padding-bottom: 0; }
  .bottom-nav { display: none; }
}

@media (max-width: 991.98px) {
  .sidebar-desktop { display: none !important; }
}

@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }
}
