:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --ink: #1f2a24;
  --muted: #647169;
  --line: #dfe5dc;
  --primary: #236a4b;
  --primary-dark: #173f2e;
  --warn: #b45309;
  --danger: #b42318;
  --soft: #edf5ee;
  --shadow: 0 10px 28px rgba(24, 41, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", Arial, sans-serif;
}

.hidden {
  display: none !important;
}

.login-mode {
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(35, 106, 75, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(35, 106, 75, 0.08) 1px, transparent 1px),
    #f3f6f1;
  background-size: 44px 44px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 460px);
  gap: clamp(28px, 5vw, 72px);
  align-items: center;
  padding: clamp(28px, 6vw, 76px);
}

.login-hero {
  max-width: 720px;
  display: grid;
  gap: 34px;
}

.login-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--primary-dark);
  font-size: 18px;
  font-weight: 800;
}

.login-mark {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(35, 106, 75, 0.22);
  border-radius: 8px;
  color: white;
  background: var(--primary);
  font-size: 14px;
  letter-spacing: 0;
}

.login-copy {
  display: grid;
  gap: 14px;
}

.login-kicker {
  margin: 0;
  color: var(--primary);
  font-size: 14px;
  font-weight: 800;
}

.login-copy h1 {
  max-width: 680px;
  margin: 0;
  color: #18251e;
  font-size: clamp(34px, 4.8vw, 58px);
  line-height: 1.08;
}

.login-copy p {
  max-width: 560px;
  margin: 0;
  color: #526158;
  font-size: 17px;
}

.login-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 150px));
  gap: 12px;
}

.login-stats span {
  display: grid;
  gap: 4px;
  min-height: 76px;
  padding: 13px 14px;
  border: 1px solid rgba(35, 106, 75, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  box-shadow: 0 12px 32px rgba(24, 41, 31, 0.06);
}

.login-stats b {
  color: var(--ink);
  font-size: 24px;
}

.login-panel {
  width: 100%;
  display: grid;
  gap: 16px;
  padding: 30px;
  border: 1px solid rgba(23, 63, 46, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 70px rgba(24, 41, 31, 0.14);
}

.login-panel-head {
  display: grid;
  gap: 6px;
}

.login-panel-head span {
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

.login-panel h2 {
  margin: 0;
  color: #18251e;
  font-size: 26px;
}

.login-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.login-panel input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d6dfd7;
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fbfcfa;
  font: inherit;
}

.login-panel input:focus {
  outline: 3px solid rgba(35, 106, 75, 0.14);
  border-color: var(--primary);
}

.login-submit {
  min-height: 46px;
  font-weight: 800;
}

.login-hints {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.login-hints span {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 8px;
  background: #f8faf7;
  overflow-wrap: anywhere;
}

.login-result {
  min-height: 44px;
  padding: 10px 12px;
  font-size: 13px;
}

.sidebar-action {
  width: 100%;
  margin: 0 0 16px;
  color: #ecf4ef;
  background: #254333;
  border-color: rgba(255, 255, 255, 0.18);
}

body.locale-ug {
  direction: rtl;
  font-family: "UKIJ Ekran", "UKIJ Tuz", "Noto Sans Arabic", "Segoe UI", Arial, sans-serif;
}

body.locale-ug #archive,
body.locale-ug #archivePreview,
body.locale-ug .archive-preview {
  direction: ltr;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", Arial, sans-serif;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
  background: #17231d;
  color: #ecf4ef;
  padding: 18px 14px;
}

.brand {
  font-size: 19px;
  font-weight: 800;
  margin-bottom: 18px;
}

.tenant-card {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 18px;
}

.tenant-card strong,
.tenant-card span {
  display: block;
}

.tenant-card span {
  color: #b7c8be;
  font-size: 12px;
  margin-top: 5px;
}

.tenant-switcher {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
  color: #dbe8e1;
  font-size: 13px;
}

.tenant-switcher select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  padding: 9px;
  color: #ecf4ef;
  background: #254333;
  font: inherit;
}

nav {
  display: grid;
  gap: 6px;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 38px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

nav button {
  border: 0;
  color: #dbe8e1;
  background: transparent;
  text-align: left;
}

body.locale-ug nav button,
body.locale-ug .tenant-switcher,
body.locale-ug .tenant-card,
body.locale-ug .topbar,
body.locale-ug .panel,
body.locale-ug .metrics article {
  text-align: right;
}

nav button.active,
nav button:hover {
  background: #254333;
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

h2 {
  margin: 0 0 14px;
  font-size: 17px;
}

p {
  color: var(--muted);
  line-height: 1.7;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics,
.grid {
  display: grid;
  gap: 14px;
}

.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.metrics article,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.metrics b {
  display: block;
  font-size: 26px;
  margin-bottom: 4px;
}

.metrics span {
  color: var(--muted);
  font-size: 13px;
}

.grid {
  grid-template-columns: repeat(12, 1fr);
}

.span-8 {
  grid-column: span 8;
}

.span-7 {
  grid-column: span 7;
}

.span-5 {
  grid-column: span 5;
}

.span-4 {
  grid-column: span 4;
}

.span-6 {
  grid-column: span 6;
}

.panel-gap {
  margin-top: 14px;
}

.list {
  display: grid;
  gap: 10px;
}

.module-grid,
.module-section,
.module-cards {
  display: grid;
  gap: 12px;
}

.module-section h3 {
  margin: 4px 0 0;
  font-size: 15px;
}

.module-cards {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.module-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fafbf9;
}

.module-card.enabled {
  background: #f1f7f2;
  border-color: #bdd8c4;
}

.module-card-head,
.module-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.module-card strong,
.module-card small {
  display: block;
}

.module-card p {
  margin: 0;
}

.module-card small,
.module-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.warn-text {
  color: var(--warn);
}

.compact-list {
  margin-top: 10px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.item-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 120px;
}

.item strong {
  display: block;
  margin-bottom: 4px;
}

.item small {
  color: var(--muted);
}

.trace-item {
  align-items: flex-start;
}

.readiness-summary {
  color: var(--muted);
  line-height: 1.7;
}

.readiness-item {
  align-items: flex-start;
}

.batch-board {
  display: grid;
  gap: 12px;
}

.compact-board {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.batch-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.batch-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.batch-head strong,
.batch-head small {
  display: block;
}

.batch-head small {
  color: var(--muted);
  margin-top: 4px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: #edf1ec;
  margin: 12px 0;
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.step-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.step-pill {
  min-height: 30px;
  padding: 5px 6px;
  font-size: 12px;
  white-space: nowrap;
}

.step-pill.completed {
  border-color: #c6ddce;
  background: #e7f3ec;
  color: var(--primary-dark);
}

.step-pill.pending {
  border-color: #f1d59d;
  background: #fff4df;
  color: var(--warn);
}

.step-pill.blocked {
  border-color: #f0c5c0;
  background: #fff0ee;
  color: var(--danger);
}

.link-button {
  border: 0;
  min-height: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  text-align: left;
}

.link-button:hover {
  color: var(--primary);
}

.batch-detail {
  display: grid;
  gap: 12px;
}

.detail-cover {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.detail-cover h3,
.detail-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.detail-cover p {
  margin: 0;
}

.detail-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fafbf9;
}

.detail-rows {
  display: grid;
  gap: 7px;
}

.detail-line {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 8px;
  font-size: 13px;
}

.detail-line span {
  color: var(--muted);
}

.detail-line strong {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
}

.trace-chain {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  display: grid;
  gap: 8px;
}

.trace-chain h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.trace-node {
  position: relative;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border-left: 3px solid #c6ddce;
  padding: 8px 8px 8px 10px;
  background: #f6faf6;
  border-radius: 6px;
}

.trace-node.pending {
  border-left-color: #f1d59d;
  background: #fffaf0;
}

.trace-node.blocked {
  border-left-color: #f0c5c0;
  background: #fff7f6;
}

.trace-node span {
  color: var(--muted);
  font-size: 12px;
}

.trace-node strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.trace-search {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.trace-search input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  font: inherit;
}

.trace-search-result {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.search-hit {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.amount-input,
.settlement-select {
  width: 96px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 7px;
  font: inherit;
  font-size: 12px;
}

.settlement-select {
  width: 88px;
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  min-height: 25px;
  font-size: 12px;
  color: var(--primary-dark);
  background: var(--soft);
}

.status.warn {
  color: var(--warn);
  background: #fff4df;
}

.status.danger {
  color: var(--danger);
  background: #fff0ee;
}

.small-action {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 10px 8px;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #fafbf9;
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}

.message.tenant {
  background: #e7f3ec;
  border-color: #c6ddce;
}

.message.support {
  background: #eef3fb;
  border-color: #c9d8ee;
}

.message.system {
  background: #fff8e8;
  border-color: #ead9aa;
}

.message strong {
  display: block;
  margin-bottom: 4px;
}

.record-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.record-form.single-column {
  grid-template-columns: 1fr;
}

.record-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.record-form input,
.record-form select,
.record-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
  background: white;
  font: inherit;
}

.record-form textarea {
  min-height: 96px;
  resize: vertical;
}

.record-form .checkline {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  grid-column: 1 / -1;
}

.record-form .full-row {
  grid-column: 1 / -1;
}

.record-form .checkline input {
  width: auto;
}

.record-form button {
  grid-column: 1 / -1;
}

.button-row {
  display: flex;
  gap: 8px;
  grid-column: 1 / -1;
}

.button-row button {
  flex: 1;
}

.assist-status {
  margin-bottom: 12px;
}

.assist-banner {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fafbf9;
}

.assist-banner.active {
  background: #e7f3ec;
  border-color: #b9d9c5;
}

.assist-banner span,
.audit-item small {
  color: var(--muted);
}

.section-subtitle {
  margin-top: 18px;
}

.result-box {
  min-height: 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf9;
  padding: 12px;
  color: var(--muted);
  line-height: 1.7;
  white-space: pre-wrap;
}

.hint-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6faf6;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.subheading {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-weight: 700;
}

.archive-preview {
  display: grid;
  gap: 18px;
}

.archive-cover {
  border-bottom: 2px solid var(--line);
  padding-bottom: 12px;
}

.archive-cover p {
  margin: 3px 0;
}

.archive-table {
  overflow-x: auto;
}

.archive-table h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.public-trace-page {
  background: #f5f7f3;
}

.public-trace {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 16px;
}

.public-trace-hero {
  padding: 22px 0 8px;
  border-bottom: 1px solid var(--line);
}

.public-trace-hero p {
  margin: 0 0 6px;
  color: var(--muted);
}

.public-trace-hero h1 {
  margin: 0 0 12px;
  font-size: 30px;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  font: inherit;
}

@media (max-width: 900px) {
  .login-screen {
    grid-template-columns: 1fr;
    gap: 26px;
    align-items: start;
    padding: 24px;
  }

  .login-hero {
    gap: 22px;
  }

  .login-copy h1 {
    font-size: 32px;
  }

  .login-copy p {
    font-size: 15px;
  }

  .login-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .login-panel {
    padding: 22px;
  }

  .shell {
    display: block;
  }

  .topbar,
  .item,
  .chat-form {
    display: grid;
  }

  .metrics,
  .grid,
  .record-form,
  .module-cards,
  .compact-board {
    grid-template-columns: 1fr;
  }

  .step-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .span-8,
  .span-7,
  .span-4,
  .span-5,
  .span-6 {
    grid-column: auto;
  }
}

@media (max-width: 560px) {
  .login-screen {
    padding: 18px;
  }

  .login-copy h1 {
    font-size: 28px;
  }

  .login-stats,
  .login-hints {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: white;
  }

  .sidebar,
  .topbar,
  .view:not(#archive),
  #archive > .grid,
  #archive > .panel:not(.print-area) {
    display: none !important;
  }

  .shell,
  main {
    display: block;
    padding: 0;
  }

  .print-area {
    border: 0;
    box-shadow: none;
  }

  table {
    page-break-inside: auto;
  }

  tr {
    page-break-inside: avoid;
  }
}
