:root {
  color-scheme: light;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  --ink: #172126;
  --muted: #60707a;
  --line: #d2dde3;
  --panel: #ffffff;
  --surface: #eef3f4;
  --soft: #f7fafb;
  --accent: #0f766e;
  --accent-strong: #0a5f59;
  --accent-soft: #e2f2ef;
  --danger: #b42318;
  --warn: #a15c07;
  --thead: #22343c;
  --row-alt: #f3f8f8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  height: 34px;
  min-width: 78px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

input,
select {
  height: 34px;
}

textarea {
  min-height: 88px;
  resize: vertical;
  padding-top: 9px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.16);
}

#loginUsername,
#newUsername,
#reportFromDate,
#reportToDate,
input[type="password"] {
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  padding: 10px 12px 14px;
}

.login-view {
  min-height: calc(100vh - 40px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 14px 40px rgba(34, 52, 60, 0.12);
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 20px;
  font-weight: 800;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.workspace {
  display: grid;
  gap: 12px;
}

.app-layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.side-nav {
  position: sticky;
  top: 12px;
  display: grid;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(34, 52, 60, 0.06);
}

.content-area {
  min-width: 0;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(34, 52, 60, 0.07);
}

.brand-block {
  display: grid;
  gap: 6px;
  border-right: 4px solid var(--accent);
  padding-right: 14px;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  color: var(--muted);
  line-height: 1.8;
}

.meta-line bdi,
td bdi,
.metric-value {
  direction: ltr;
  unicode-bidi: isolate;
}

.userbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  color: var(--muted);
}

.userbar strong {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab-button {
  width: 100%;
  text-align: right;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.tab-button.active {
  background: var(--thead);
  border-color: var(--thead);
  color: #fff;
}

.nav-section {
  display: grid;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 2px;
}

.nav-title {
  color: var(--muted);
  font-weight: 800;
  padding: 0 8px;
}

.sub-tab {
  padding-right: 18px;
}

.panel {
  display: grid;
  gap: 12px;
}

.search-grid,
.user-form,
.report-filter-grid {
  display: grid;
  gap: 8px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.search-grid {
  grid-template-columns: repeat(4, minmax(130px, 1fr)) auto;
}

.advanced-search {
  grid-column: 1 / -1;
  border: 1px solid #d9e5e8;
  border-radius: 8px;
  background: #fbfdfd;
  padding: 8px;
}

.advanced-search summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 800;
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.user-form {
  grid-template-columns: repeat(4, minmax(130px, 1fr)) 82px auto;
}

.report-filter-grid {
  grid-template-columns: repeat(5, minmax(112px, 1fr)) auto;
}

.field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-weight: 700;
}

.check-field {
  display: flex;
  gap: 8px;
  align-items: center;
  height: 34px;
  color: var(--muted);
  font-weight: 700;
}

.check-field input {
  width: 18px;
  height: 18px;
}

.actions,
.modal-actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

.primary {
  background: var(--accent);
  color: #fff;
}

.primary:hover {
  background: var(--accent-strong);
}

.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.danger-button {
  background: #fff1f0;
  color: var(--danger);
  border-color: #f3b6b1;
}

.wide-button {
  width: 100%;
}

.status-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 8px;
}

.status-band > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: 0 4px 14px rgba(34, 52, 60, 0.04);
}

.metric-label {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}

.status-band strong {
  font-size: 20px;
}

.message {
  border: 1px solid #f1d19b;
  background: #fff8ed;
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 10px;
}

.message.error {
  border-color: #f3b6b1;
  background: #fff1f0;
  color: var(--danger);
}

.message.success {
  border-color: #a7d8c8;
  background: #edf8f5;
  color: var(--accent-strong);
}

.table-wrap {
  overflow: auto;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: calc(100vh - 274px);
  box-shadow: 0 8px 24px rgba(34, 52, 60, 0.06);
}

.users-table-wrap {
  max-height: calc(100vh - 180px);
}

.report-table-wrap {
  max-height: calc(100vh - 260px);
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 1380px;
}

.users-table-wrap table {
  min-width: 980px;
}

.report-table-wrap table {
  min-width: 1540px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--thead);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:nth-child(even) {
  background: var(--row-alt);
}

tbody tr:hover {
  background: var(--accent-soft);
}

tbody td {
  white-space: nowrap;
}

td:nth-child(1) {
  min-width: 160px;
  font-weight: 700;
}

td:nth-child(3),
td:nth-child(4),
td:nth-child(5),
td:nth-child(8),
td:nth-child(9),
td:nth-child(10) {
  white-space: nowrap;
}

td:nth-child(11) {
  min-width: 240px;
}

.report-table-wrap td:nth-child(9),
.report-table-wrap td:nth-child(12),
.report-row td {
  white-space: normal;
}

.search-table-wrap {
  overflow-x: hidden;
  max-height: calc(100vh - 250px);
}

.search-table-wrap table {
  min-width: 100%;
  table-layout: fixed;
}

.search-table-wrap th,
.search-table-wrap td {
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}

.search-table-wrap th,
.report-table-wrap th {
  white-space: nowrap;
  overflow-wrap: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.35;
  text-align: center;
}

.search-table-wrap th:nth-child(1),
.search-table-wrap td:nth-child(1) {
  width: 11%;
}

.search-table-wrap th:nth-child(2),
.search-table-wrap td:nth-child(2) {
  width: 9%;
}

.search-table-wrap th:nth-child(3),
.search-table-wrap td:nth-child(3) {
  width: 7%;
}

.search-table-wrap th:nth-child(4),
.search-table-wrap td:nth-child(4) {
  width: 5.5%;
}

.search-table-wrap th:nth-child(5),
.search-table-wrap td:nth-child(5) {
  width: 7.5%;
}

.search-table-wrap th:nth-child(6),
.search-table-wrap td:nth-child(6) {
  width: 5.5%;
}

.search-table-wrap th:nth-child(7),
.search-table-wrap td:nth-child(7) {
  width: 16%;
}

.search-table-wrap th:nth-child(8),
.search-table-wrap td:nth-child(8) {
  width: 6%;
}

.search-table-wrap th:nth-child(9),
.search-table-wrap td:nth-child(9),
.search-table-wrap th:nth-child(10),
.search-table-wrap td:nth-child(10) {
  width: 4.8%;
}

.search-table-wrap th:nth-child(11),
.search-table-wrap td:nth-child(11) {
  width: 13.9%;
}

.search-table-wrap th:nth-child(12),
.search-table-wrap td:nth-child(12) {
  width: 9%;
}

.search-table-wrap td:nth-child(3),
.search-table-wrap td:nth-child(4),
.search-table-wrap td:nth-child(5),
.search-table-wrap td:nth-child(8),
.search-table-wrap td:nth-child(9),
.search-table-wrap td:nth-child(10),
.report-table-wrap td:nth-child(5),
.report-table-wrap td:nth-child(11) {
  direction: ltr;
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
}

.search-table-wrap td:nth-child(3) .cell-view,
.search-table-wrap td:nth-child(4) .cell-view,
.search-table-wrap td:nth-child(5) .cell-view,
.search-table-wrap td:nth-child(8) .cell-view,
.search-table-wrap td:nth-child(9) .cell-view,
.search-table-wrap td:nth-child(10) .cell-view,
.report-table-wrap td:nth-child(5) .cell-view,
.report-table-wrap td:nth-child(11) .cell-view {
  direction: ltr;
  text-align: center;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
}

.search-table-wrap .result-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  min-width: 0;
  align-content: start;
}

.search-table-wrap .follow-button,
.search-table-wrap .report-button {
  width: 100%;
  min-width: 0;
  height: 27px;
  padding: 0 5px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.search-table-wrap .report-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.search-table-wrap .count-pill {
  min-width: 17px;
  margin-right: 0;
  padding: 0 3px;
  font-size: 11px;
}

.search-table-wrap .report-row td {
  width: auto;
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
  text-align: right;
}

.report-table-wrap {
  overflow-x: hidden;
  max-height: calc(100vh - 252px);
}

.report-table-wrap table {
  min-width: 100%;
  table-layout: fixed;
}

.audit-table-wrap {
  max-height: 320px;
}

.audit-table-wrap table {
  min-width: 900px;
}

.report-table-wrap th,
.report-table-wrap td {
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}

.report-table-wrap th:nth-child(1),
.report-table-wrap td:nth-child(1) {
  width: 8%;
}

.report-table-wrap th:nth-child(2),
.report-table-wrap td:nth-child(2) {
  width: 7%;
}

.report-table-wrap th:nth-child(3),
.report-table-wrap td:nth-child(3) {
  width: 10%;
}

.report-table-wrap th:nth-child(4),
.report-table-wrap td:nth-child(4) {
  width: 9%;
}

.report-table-wrap th:nth-child(5),
.report-table-wrap td:nth-child(5) {
  width: 7%;
}

.report-table-wrap th:nth-child(6),
.report-table-wrap td:nth-child(6) {
  width: 13%;
}

.report-table-wrap th:nth-child(7),
.report-table-wrap td:nth-child(7) {
  width: 5%;
}

.report-table-wrap th:nth-child(8),
.report-table-wrap td:nth-child(8) {
  width: 7%;
}

.report-table-wrap th:nth-child(9),
.report-table-wrap td:nth-child(9) {
  width: 11%;
}

.report-table-wrap th:nth-child(10),
.report-table-wrap td:nth-child(10) {
  width: 7%;
}

.report-table-wrap th:nth-child(11),
.report-table-wrap td:nth-child(11) {
  width: 6%;
}

.report-table-wrap th:nth-child(12),
.report-table-wrap td:nth-child(12) {
  width: 10%;
}

.cell-view {
  display: block;
  width: 100%;
  height: auto;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  line-height: inherit;
  text-align: inherit;
  cursor: zoom-in;
  overflow: visible;
  text-overflow: clip;
  white-space: inherit;
  overflow-wrap: inherit;
}

.cell-view:hover,
.cell-view:focus-visible {
  color: var(--accent-strong);
  text-decoration: underline;
}

.detail-panel {
  width: min(760px, 100%);
}

.cell-detail-body {
  max-height: min(58vh, 520px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  line-height: 1.9;
  white-space: pre-wrap;
  user-select: text;
  direction: rtl;
  text-align: right;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 18px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 210px;
}

.follow-button,
.report-button {
  min-width: 96px;
}

.count-pill {
  display: inline-flex;
  min-width: 22px;
  justify-content: center;
  margin-right: 6px;
  border-radius: 999px;
  background: #e8eef2;
  color: var(--ink);
  padding: 0 6px;
}

mark {
  background: #fde68a;
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.5;
}

.state-ok {
  background-color: #e6f5ef;
  color: #08704f;
}

.state-warning {
  background-color: #fff4d8;
  color: #946200;
}

.state-danger,
.state-expired {
  background-color: #ffe8e6;
  color: #b42318;
}

.state-pending {
  background-color: #edf2ff;
  color: #3956a4;
}

.state-neutral {
  background-color: #eef3f4;
  color: var(--muted);
}

.state-has-followup {
  border-right: 3px solid var(--accent);
}

.state-no-followup {
  border-right: 3px solid #cdd8de;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 33, 38, 0.46);
}

.modal-panel {
  width: min(980px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  display: grid;
  gap: 14px;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 16px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.26);
}

.modal-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.modal-record {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.8;
}

.icon-button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.followup-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}

.followup-form .wide,
.followup-form .message,
.followup-form .modal-actions {
  grid-column: 1 / -1;
}

.history-block {
  display: grid;
  gap: 10px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--soft);
  direction: rtl;
  text-align: right;
}

.report-row > td {
  padding: 0;
  background: #f8fbfb;
}

.expanded-source-row {
  background: #e9f6f3 !important;
}

.inline-reports {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #c3d8d5;
  border-bottom: 1px solid #c3d8d5;
  background: #f8fbfb;
  direction: rtl;
  text-align: right;
}

.inline-reports-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  color: var(--muted);
  justify-content: flex-start;
  text-align: right;
}

.inline-reports-title strong {
  color: var(--ink);
}

.compact-empty {
  padding: 14px;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 12px;
  justify-content: flex-start;
  text-align: right;
}

.history-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 4px;
}

.history-actions button {
  height: 30px;
  min-width: 72px;
}

.admin-section {
  display: grid;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.section-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.section-toolbar h2 {
  font-size: 17px;
  margin-bottom: 4px;
}

.section-meta {
  color: var(--muted);
}

#reportsPanel .admin-section {
  padding: 12px;
  box-shadow: 0 8px 24px rgba(34, 52, 60, 0.06);
}

#reportsPanel .section-toolbar {
  align-items: end;
}

#reportsPanel .report-filter-grid {
  padding: 10px;
}

.user-row-controls {
  display: grid;
  gap: 6px;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.mobile-card-list {
  display: none;
}

.data-card {
  display: grid;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 6px 18px rgba(34, 52, 60, 0.06);
}

.data-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.data-card-header h3 {
  font-size: 15px;
  line-height: 1.6;
}

.data-card-header p {
  margin: 2px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.data-card-header > span {
  align-self: start;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

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

.card-field {
  display: grid;
  gap: 3px;
  min-width: 0;
  border: 1px solid #dce7eb;
  border-radius: 6px;
  background: var(--soft);
  padding: 7px 8px;
}

.card-field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.card-field .cell-view {
  text-align: right;
  line-height: 1.75;
}

.numeric-field .cell-view {
  direction: ltr;
  text-align: left;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
  font-size: 12px;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.card-actions.single-action {
  grid-template-columns: 1fr;
}

.card-actions button {
  width: 100%;
  min-width: 0;
}

.user-card .card-field {
  background: #fff;
}

.check-card-field .check-field {
  justify-content: flex-start;
  padding-top: 4px;
}

@media (max-width: 1050px) {
  .topbar,
  .app-layout,
  .search-grid,
  .advanced-grid,
  .user-form,
  .report-filter-grid,
  .section-toolbar,
  .status-band,
  .followup-form {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: static;
  }

  .userbar,
  .actions,
  .modal-actions {
    justify-content: stretch;
  }

  .actions button,
  .modal-actions button {
    flex: 1;
  }

  .table-wrap {
    max-height: none;
  }

  .section-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 8px;
  }

  .search-table-wrap,
  .users-table-wrap,
  .audit-table-wrap,
  .report-table-wrap {
    display: none;
  }

  .mobile-card-list {
    display: grid;
    gap: 10px;
  }

  .data-card:not(.report-card) .card-field:nth-child(7),
  .data-card:not(.report-card) .card-field:nth-child(8),
  .report-card .card-field:nth-child(5),
  .report-card .card-field:nth-child(7),
  .report-card .card-field:nth-child(8),
  .report-card .card-field:nth-child(9) {
    grid-column: 1 / -1;
  }

  .audit-card .card-field:nth-child(3) {
    grid-column: 1 / -1;
  }

  .user-card .card-field {
    grid-column: 1 / -1;
  }

  .data-card .inline-reports {
    margin: 0 -2px;
  }

  #loadFollowupsReportButton {
    font-size: 0;
  }

  #loadFollowupsReportButton::after {
    content: attr(data-mobile-label);
    font-size: 13px;
  }
}
