:root {
  --jrs-navy: #2D4B8A;
  --jrs-navy-dark: #23394A;
  --jrs-navy-deep: #1B2F5C;
  --jrs-coral: #e95644;
  --jrs-bg: #f3f5f8;
  --jrs-muted: #6b778c;
  --jrs-border: #e2e7ef;
  --sidebar-w: 220px;
}

html { font-size: 14px; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Nunito", system-ui, sans-serif;
  color: #243044;
  background: var(--jrs-bg);
}

.btn {
  --bs-btn-padding-y: .28rem;
  --bs-btn-padding-x: .65rem;
  --bs-btn-font-size: .8125rem;
}
.btn-sm {
  --bs-btn-padding-y: .2rem;
  --bs-btn-padding-x: .5rem;
  --bs-btn-font-size: .75rem;
}
.form-control, .form-select {
  min-height: 2.15rem;
  font-size: .875rem;
  padding: .28rem .6rem;
}
.form-label { margin-bottom: .25rem; font-size: .8rem; font-weight: 700; }

.btn-primary { background: var(--jrs-navy); border-color: var(--jrs-navy); }
.btn-primary:hover { background: var(--jrs-navy-deep); border-color: var(--jrs-navy-deep); }
.btn-outline-primary { color: var(--jrs-navy); border-color: var(--jrs-navy); }
.btn-outline-primary:hover { background: var(--jrs-navy); border-color: var(--jrs-navy); color: #fff; }
.btn-warning { background: var(--jrs-coral); border-color: var(--jrs-coral); color: #fff; }
.btn-warning:hover { background: #e53722; border-color: #e53722; color: #fff; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--jrs-navy), var(--jrs-navy-deep));
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.sidebar-brand {
  padding: .85rem .9rem;
  border-bottom: 1px solid rgba(255,255,255,.12);
  color: #fff;
  text-decoration: none;
  display: block;
}
.sidebar-brand img {
  display: block;
  width: 100%;
  max-height: 48px;
  height: auto;
  object-fit: contain;
  object-position: left center;
  mix-blend-mode: screen;
}
.sidebar-nav { padding: .75rem .6rem; flex: 1; overflow: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .5rem;
  color: rgba(255,255,255,.86); text-decoration: none;
  padding: .5rem .65rem; border-radius: 8px; font-weight: 600; margin-bottom: .15rem;
  font-size: .9rem;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-nav a.active { background: #fff; color: var(--jrs-navy); }
.sidebar-section {
  margin: .75rem .65rem .3rem; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .08em; color: rgba(255,255,255,.55); font-weight: 700;
}
.sidebar-user {
  padding: .85rem; border-top: 1px solid rgba(255,255,255,.12);
}
.sidebar-user strong { display: block; font-size: .9rem; }
.sidebar-user small { color: rgba(255,255,255,.7); }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content { padding: 1.1rem 1.25rem; flex: 1; }
.app-footer { padding: .7rem 1.25rem 1rem; color: var(--jrs-muted); font-size: .8rem; }

.card-jrs {
  background: #fff; border: 0; border-radius: 12px;
  box-shadow: 0 8px 22px rgba(27,47,92,.06);
}
.page-title { display: flex; justify-content: space-between; align-items: flex-end; gap: .85rem; margin-bottom: .85rem; }
.page-title h2 { margin: 0; font-weight: 800; font-size: 1.25rem; }
.page-title p { margin: .15rem 0 0; color: var(--jrs-muted); font-size: .85rem; }

.badge-mock { background: #fff3cd; color: #856404; font-weight: 700; }
.badge-soft { background: #e8eef8; color: var(--jrs-navy); font-weight: 700; }

.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .85rem;
}
.entity-card {
  background: #fff;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 8px 22px rgba(27,47,92,.06);
  padding: .9rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
  min-height: 100%;
}
.entity-card-head {
  display: flex;
  gap: .65rem;
  align-items: flex-start;
}
.entity-card-head .badge { flex-shrink: 0; }
.entity-card-head .flex-grow-1 { min-width: 0; }
.entity-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--jrs-navy);
  color: #fff;
  font-weight: 800;
  font-size: .72rem;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.entity-card-title {
  font-weight: 800;
  font-size: .92rem;
  line-height: 1.25;
  margin: 0;
}
.entity-card-sub {
  color: var(--jrs-muted);
  font-size: .76rem;
  margin: .12rem 0 0;
}
.entity-meta {
  display: flex;
  flex-direction: column;
  gap: .22rem;
  font-size: .8rem;
  color: #3b475c;
  word-break: break-word;
  flex: 1;
}
.entity-meta i { color: var(--jrs-navy); margin-right: .3rem; }
.entity-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-top: auto;
  padding-top: .55rem;
  border-top: 1px solid var(--jrs-border);
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #1B2F5C 0%, #23394A 48%, #2D4B8A 100%);
}
.login-wrap::before,
.login-wrap::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.login-wrap::before {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(233,86,68,.28), transparent 68%);
  top: -140px;
  right: -90px;
}
.login-wrap::after {
  width: 340px;
  height: 340px;
  background: radial-gradient(circle, rgba(255,255,255,.14), transparent 70%);
  bottom: -120px;
  left: -80px;
}
.login-box {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.login-logo {
  display: block;
  height: 84px;
  width: auto;
  max-width: 320px;
  margin: 0 auto 1.25rem;
  object-fit: contain;
  mix-blend-mode: screen;
}
.login-card {
  width: 100%;
  background: #fff;
  color: #243044;
  border: 0;
  border-radius: 18px;
  padding: 2rem 1.75rem 1.6rem;
  box-shadow: 0 22px 50px rgba(12, 20, 40, .28);
}
.login-brand {
  text-align: center;
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--jrs-navy);
}
.login-card h1 { font-size: 1.55rem; font-weight: 800; margin: 1.15rem 0 .95rem; }
.login-card .form-label { font-size: 1rem; margin-bottom: .4rem; }
.login-card .form-control {
  background: #f3f5f8;
  border: 1px solid var(--jrs-border);
  min-height: 48px;
  font-size: 1.05rem;
  padding: .55rem .85rem;
}
.login-card .btn {
  --bs-btn-padding-y: .6rem;
  --bs-btn-padding-x: .9rem;
  --bs-btn-font-size: 1.05rem;
  min-height: 48px;
}
.login-lead {
  text-align: center;
  color: var(--jrs-muted);
  font-size: 1.02rem;
  margin: .25rem 0 0;
}
.login-note {
  color: var(--jrs-muted);
  font-size: .95rem;
  margin: 1rem 0 0;
}
.login-copy {
  text-align: center;
  color: rgba(255,255,255,.78);
  font-size: .95rem;
  margin: 1rem 0 0;
}
.login-art { display: none; }
.login-panel { display: contents; }
.login-hints { font-size: .85rem; color: var(--jrs-muted); margin-top: 1rem; }
.login-hints code { color: var(--jrs-navy); }

.filter-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; align-items: end; }
.stat-card { border: 0; border-radius: 12px; color: #fff; min-height: 84px; text-decoration: none; display: block; }
.stat-card:hover { opacity: .92; color: #fff; }
.stat-card h4 { margin: 0; font-size: 1.35rem; font-weight: 800; }

.fiscal-stat {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 22px rgba(27,47,92,.06);
  padding: .75rem .85rem;
  min-height: 76px;
}
.fiscal-stat .text-muted { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.fiscal-stat strong { display: block; font-size: 1.05rem; font-weight: 800; margin-top: .15rem; }
.fiscal-stat div:last-child { font-size: .8rem; color: var(--jrs-muted); }

.table thead th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--jrs-muted); font-weight: 700; white-space: nowrap;
}
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--jrs-muted); }
.card-form-full {
  width: 100%;
  max-width: none;
}

.fiscal-chat-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1050;
  width: 3.25rem;
  height: 3.25rem;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--jrs-navy), var(--jrs-navy-deep));
  color: #fff;
  font-size: 1.35rem;
  box-shadow: 0 10px 28px rgba(27, 47, 92, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
}
.fiscal-chat-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 32px rgba(27, 47, 92, .42);
  color: #fff;
}
.fiscal-chat-fab.is-open {
  background: var(--jrs-muted);
}

.fiscal-chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5rem;
  z-index: 1049;
  width: min(22rem, calc(100vw - 2rem));
  height: min(32rem, calc(100vh - 7rem));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(27, 47, 92, .18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(.98);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
.fiscal-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.fiscal-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .75rem .85rem;
  background: linear-gradient(135deg, var(--jrs-navy), var(--jrs-navy-deep));
  color: #fff;
}
.fiscal-chat-header h3 {
  margin: 0;
  font-size: .9rem;
  font-weight: 800;
}
.fiscal-chat-header p {
  margin: .1rem 0 0;
  font-size: .72rem;
  opacity: .85;
}
.fiscal-chat-close {
  border: 0;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.fiscal-chat-close:hover { background: rgba(255, 255, 255, .25); }

.fiscal-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: .85rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  background: #f8fafc;
}
.fiscal-chat-msg {
  max-width: 88%;
  padding: .55rem .7rem;
  border-radius: 12px;
  font-size: .8125rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.fiscal-chat-msg.user {
  align-self: flex-end;
  background: var(--jrs-navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.fiscal-chat-msg.bot {
  align-self: flex-start;
  background: #fff;
  color: #243044;
  border: 1px solid var(--jrs-border);
  border-bottom-left-radius: 4px;
}
.fiscal-chat-msg.error {
  align-self: flex-start;
  background: #fff5f5;
  color: #b42318;
  border: 1px solid #fecaca;
}
.fiscal-chat-msg.typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--jrs-border);
  color: var(--jrs-muted);
  font-style: italic;
}

.fiscal-chat-footer {
  padding: .65rem .75rem .75rem;
  border-top: 1px solid var(--jrs-border);
  background: #fff;
}
.fiscal-chat-footer .form-select {
  min-height: 1.85rem;
  font-size: .75rem;
  margin-bottom: .45rem;
}
.fiscal-chat-input-row {
  display: flex;
  gap: .45rem;
  align-items: flex-end;
}
.fiscal-chat-input-row textarea {
  flex: 1;
  min-height: 2.4rem;
  max-height: 6rem;
  resize: none;
  font-size: .8125rem;
  padding: .45rem .55rem;
}
.fiscal-chat-send {
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  border-radius: 10px;
  background: var(--jrs-navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}
.fiscal-chat-send:hover:not(:disabled) { background: var(--jrs-navy-deep); }
.fiscal-chat-send:disabled { opacity: .5; cursor: not-allowed; }

.fiscal-chat-alert {
  margin: .65rem .75rem 0;
  padding: .45rem .55rem;
  font-size: .75rem;
  border-radius: 8px;
  background: #fff8e6;
  color: #8a6116;
  border: 1px solid #fde68a;
}

@media (max-width: 900px) {
  .app-shell { display: block; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .sidebar-brand img { max-width: 160px; }
}
