:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #f7f9f8;
  --line: #dce3df;
  --line-strong: #b8c5bf;
  --text: #18241f;
  --muted: #617169;
  --ink: #102830;
  --ink-2: #183845;
  --gold: #bf8225;
  --gold-soft: #fff4db;
  --teal: #0f766e;
  --teal-dark: #0b5f59;
  --teal-soft: #dff4f0;
  --red: #b42318;
  --red-soft: #ffe5e1;
  --amber: #9a6500;
  --amber-soft: #fff1cf;
  --green: #227a3c;
  --green-soft: #e2f4e7;
  --blue: #245b9f;
  --blue-soft: #e3eefc;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #e9efed 0, var(--bg) 250px),
    repeating-linear-gradient(90deg, rgba(16, 40, 48, 0.035) 0 1px, transparent 1px 72px);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

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

button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 7px 12px;
  white-space: nowrap;
}

button:hover {
  border-color: var(--teal);
}

button.primary {
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
  border-color: var(--teal-dark);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.18);
}

button.primary:hover {
  background: var(--teal-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

select,
input,
textarea {
  min-height: 40px;
  width: 100%;
  border: 1px solid #c6d0ca;
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff, #fbfcfb);
  color: var(--text);
  padding: 7px 10px;
}

textarea {
  resize: vertical;
}

select:focus,
input:focus,
textarea:focus,
button:focus {
  outline: 2px solid rgba(15, 118, 110, 0.22);
  outline-offset: 1px;
}

a {
  color: var(--blue);
  font-weight: 700;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: #506259;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

legend {
  display: block;
  margin-bottom: 6px;
  color: #506259;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
  background:
    linear-gradient(135deg, rgba(10, 39, 52, 0.94), rgba(13, 72, 65, 0.9)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, transparent 1px 72px),
    #0b2c37;
}

.login-screen::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(244, 183, 64, 0.18), transparent 36%),
    linear-gradient(180deg, transparent 0 58%, rgba(4, 16, 24, 0.4));
}

.login-frame {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(390px, 0.65fr);
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.login-brand {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 22px;
  padding: clamp(34px, 5vw, 74px);
  color: #ffffff;
  background:
    linear-gradient(180deg, rgba(9, 37, 49, 0.14), rgba(7, 24, 33, 0.72)),
    linear-gradient(135deg, rgba(241, 181, 48, 0.16), transparent 46%);
}

.brand-mark {
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(246, 206, 115, 0.68);
  border-radius: 8px;
  background: linear-gradient(145deg, #f4c45c, #b8791c);
  color: #102830;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.24);
}

.brand-mark span {
  font-size: 25px;
  font-weight: 900;
}

.login-brand .eyebrow {
  color: #f4c45c;
}

.login-brand h1 {
  margin: 4px 0 0;
  max-width: 680px;
  color: #ffffff;
  font-size: clamp(42px, 6vw, 74px);
  line-height: 1.05;
}

.brand-subtitle {
  margin: 10px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 17px;
  font-weight: 700;
}

.brand-divider {
  width: min(360px, 100%);
  height: 1px;
  background: linear-gradient(90deg, #f4c45c, rgba(255, 255, 255, 0));
}

.brand-copy {
  display: grid;
  gap: 8px;
  max-width: 650px;
}

.brand-copy strong {
  font-size: 20px;
}

.brand-copy span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 16px;
  line-height: 1.65;
}

.login-card {
  align-self: stretch;
  display: grid;
  align-content: center;
  gap: 16px;
  border: 0;
  border-left: 1px solid rgba(31, 41, 35, 0.08);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.96);
  padding: clamp(28px, 4vw, 58px);
  box-shadow: none;
}

.login-card-head {
  margin-bottom: 4px;
}

.login-card h2 {
  margin: 2px 0 4px;
  color: #17231d;
  font-size: 30px;
  line-height: 1.1;
}

.login-card p,
.login-card-head p {
  margin: 0;
  color: var(--muted);
}

.login-card input {
  min-height: 44px;
  border-color: #c8d0ca;
  background: #fbfcfb;
}

.login-card button.primary {
  min-height: 44px;
  margin-top: 4px;
  background: #0b5f59;
  border-color: #0b5f59;
}

.login-error {
  min-height: 20px;
  color: var(--red) !important;
  font-weight: 750;
}

.app-shell {
  width: min(1680px, calc(100% - 28px));
  margin: 0 auto 28px;
  padding-top: 18px;
}

.topbar,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  position: relative;
  align-items: center;
  margin-bottom: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(16, 40, 48, 0.98), rgba(11, 95, 89, 0.94)),
    linear-gradient(90deg, rgba(191, 130, 37, 0.22), transparent 38%);
  color: #ffffff;
  padding: 18px 20px;
  box-shadow: 0 18px 42px rgba(16, 40, 48, 0.18);
  overflow: hidden;
}

.topbar::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold), rgba(255, 255, 255, 0.18), transparent);
}

.topbar h1,
.section-head h2 {
  margin: 0;
  line-height: 1.15;
}

.topbar h1 {
  color: #ffffff;
  font-size: 28px;
}

.section-head h2 {
  font-size: 18px;
}

.topbar p,
.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.topbar p {
  color: rgba(255, 255, 255, 0.74);
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #f4c45c;
}

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

.active-user {
  align-self: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 800;
}

.entry-panel,
.filters,
.red-flag-panel,
.register-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(24, 36, 31, 0.07);
}

.entry-panel {
  position: relative;
  padding: 16px;
  overflow: hidden;
}

.entry-panel::before,
.register-section::before,
.red-flag-panel::before {
  content: "";
  display: block;
  height: 4px;
  margin: -16px -16px 14px;
  background: linear-gradient(90deg, var(--teal), var(--gold), transparent);
}

.grievance-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: stretch;
}

.grievance-form .section-head {
  grid-column: 1 / -1;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 2px;
}

.grievance-form > label,
.form-stage,
.stage-grid > label,
.reason-detail-fields,
.conditional-block {
  min-width: 0;
}

.form-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fbfcfb);
  overflow: hidden;
}

.application-stage {
  border-color: rgba(15, 118, 110, 0.25);
}

.compliance-stage {
  border-color: rgba(191, 130, 37, 0.32);
}

.stage-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fbfa;
  padding: 12px;
}

.application-stage .stage-head {
  background: linear-gradient(90deg, var(--teal-soft), #ffffff);
}

.compliance-stage .stage-head {
  background: linear-gradient(90deg, var(--gold-soft), #ffffff);
}

.stage-number {
  width: 32px;
  height: 32px;
  display: grid;
  flex: 0 0 32px;
  place-items: center;
  border-radius: 999px;
  background: var(--teal);
  color: #ffffff;
  font-weight: 900;
}

.compliance-stage .stage-number {
  background: var(--gold);
}

.stage-head h3 {
  margin: 0;
  font-size: 16px;
}

.stage-head p {
  margin: 3px 0 0;
  color: var(--muted);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
  padding: 14px;
}

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

.locked select {
  background: var(--surface-2);
  color: var(--muted);
}

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

.reason-detail-fields {
  min-height: 40px;
}

.upload-field small {
  display: block;
  margin-top: 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.action-field {
  align-self: stretch;
}

.action-options {
  min-height: 40px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border: 1px solid #c6d0ca;
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff, #fbfcfb);
  padding: 7px;
}

.action-choice {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  padding: 4px 10px 4px 8px;
}

.action-choice input {
  width: auto;
  min-height: auto;
}

.action-choice span {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: none;
}

.conditional-block {
  display: grid;
  gap: 6px;
}

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

.field-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.form-message {
  min-height: 20px;
  color: var(--green);
  font-weight: 750;
  text-align: right;
}

.form-message.error {
  color: var(--red);
}

.filters {
  display: grid;
  grid-template-columns: 140px 140px 180px 160px minmax(220px, 1fr) 150px 112px;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
  padding: 12px;
  background:
    linear-gradient(180deg, #ffffff, #fbfcfb),
    var(--surface);
}

.flag-toggle {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #c6d0ca;
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff, #fbfcfb);
  padding: 6px 10px;
}

.flag-toggle input {
  width: auto;
  min-height: auto;
}

.flag-toggle span {
  margin: 0;
  color: var(--text);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.kpi {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f9fbfa);
  padding: 14px;
  box-shadow: 0 10px 26px rgba(24, 36, 31, 0.06);
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--teal);
}

.kpi span,
.kpi small {
  display: block;
  color: var(--muted);
}

.kpi strong {
  display: block;
  margin: 4px 0;
  font-size: 26px;
  line-height: 1;
  color: var(--ink);
}

.kpi.danger {
  border-color: #f1aaa3;
  background: linear-gradient(180deg, #fff8f7, var(--red-soft));
}

.kpi.danger::before {
  background: var(--red);
}

.red-flag-panel,
.register-section {
  margin-top: 12px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.red-flag-panel::before {
  background: linear-gradient(90deg, var(--red), var(--gold), transparent);
}

.table-wrap {
  position: relative;
  margin-top: 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.table-wrap.compact {
  max-height: 310px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1700px;
  border-collapse: separate;
  border-spacing: 0;
  background: #ffffff;
}

th,
td {
  border-bottom: 1px solid #ccd7d1;
  border-right: 1px solid #d6e0db;
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom-color: #cbd6d0;
  background: linear-gradient(180deg, #f6f9f8, #eaf0ed);
  color: #2f4037;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  border-right: 4px solid #6f8479;
}

th:nth-child(12),
td:nth-child(12) {
  border-left: 4px solid #6f8479;
}

th:nth-child(13),
td:nth-child(13) {
  border-right: 4px solid #6f8479;
}

td {
  max-width: 260px;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

tbody tr:hover {
  background: #f8fbfa;
}

.flagged-row {
  background: #fff8f7;
  box-shadow: inset 4px 0 0 var(--red);
}

.application-start-row > td {
  border-top: 3px solid #d92d20;
}

.repeated-action-row td {
  border-top: 2px solid #8fa49a;
  background: #fbfdfc;
}

td[rowspan] {
  background: #ffffff;
  vertical-align: middle;
}

.serial-cell {
  font-size: 15px;
  text-align: center;
}

.action-col {
  background: #fbfdfc;
}

.flag-badge,
.soft-flag,
.clear-badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.flag-badge {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid #f0b1aa;
}

.flag-badge.jsk {
  background: #fff1cf;
  color: #8b1d14;
  border-color: #e3a84f;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef3f1;
  color: #40534a;
  border: 1px solid #c8d5ce;
  font-size: 12px;
  font-weight: 800;
}

.source-badge.jsk {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: #b8cdf0;
}

.soft-flag {
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid #f0cd84;
}

.clear-badge,
.status-pill.done {
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid #b8dec2;
}

.status-pill.pending {
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid #f0cd84;
}

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

@media (max-width: 1180px) {
  .stage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

@media (max-width: 760px) {
  .login-screen {
    padding: 0;
    place-items: stretch;
  }

  .login-frame {
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .login-brand {
    min-height: 48vh;
    padding: 28px 22px;
  }

  .login-brand h1 {
    font-size: 36px;
  }

  .login-card {
    padding: 26px 20px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .app-shell {
    width: min(100% - 18px, 1660px);
    margin-top: 10px;
  }

  .topbar,
  .section-head {
    display: grid;
  }

  .topbar {
    padding: 16px;
  }

  .top-actions,
  .form-actions {
    justify-content: stretch;
  }

  .top-actions > *,
  .form-actions > * {
    flex: 1;
  }

  .grievance-form,
  .stage-grid,
  .filters,
  .conditional-fields,
  .kpis {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .form-message {
    text-align: left;
  }
}
