.admin-app {
  display: grid;
  grid-template-columns: 14.5rem minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100svh;
  background: #f1f4f8;
}

.admin-rail {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
  padding: 1.65rem 1rem 1rem;
  background: #192b44;
  color: #fff;
}

.admin-brand {
  display: inline-block;
  align-self: start;
  margin: 0 .7rem;
  font-size: 1.14rem;
  font-weight: 670;
  letter-spacing: -.025em;
  text-decoration: none;
}

.admin-nav {
  display: grid;
  margin-top: 2.45rem;
  gap: .3rem;
}

.admin-nav a {
  display: flex;
  align-items: center;
  gap: .64rem;
  min-height: 43px;
  padding: .5rem .68rem;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #d7e2f2;
  font-size: .86rem;
  font-weight: 520;
  text-decoration: none;
}

.admin-nav a .icon { color: #abc0e2; }
.admin-nav a[aria-current="page"] {
  border-color: #506685;
  background: #2b4162;
  color: #fff;
}

.admin-nav a[aria-current="page"] .icon { color: #dce9ff; }
.admin-nav a:hover, .admin-rail-footer :is(a, button):hover { background: #263d5a; color: #fff; }
.admin-rail :is(a, button):focus-visible { outline-color: #c1d6fc; }

.admin-rail-footer {
  display: grid;
  gap: .1rem;
  margin-top: auto;
  padding-top: .8rem;
  border-top: 1px solid #495a72;
}

.admin-rail-footer :is(a, button) {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-height: 42px;
  padding: .5rem .7rem;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #d7e2f2;
  font-size: .86rem;
  text-align: left;
  text-decoration: none;
}

.admin-main {
  width: min(100%, 83rem);
  min-width: 0;
  margin-inline: auto;
  padding: clamp(1.3rem, 3.2vw, 3.1rem) clamp(1rem, 4vw, 3.4rem) 2.75rem;
}

.admin-page-heading, .admin-card-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .8rem 1rem;
}

.admin-page-heading { margin-bottom: 1.35rem; }
.admin-page-heading h1 {
  font-size: clamp(1.7rem, 3.2vw, 2.45rem);
  font-weight: 680;
}

.admin-heading-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; }
.admin-app .button, .admin-dialog .button {
  min-height: 42px;
  padding-inline: .85rem;
  border-color: #bbc8da;
  border-radius: 5px;
  text-decoration: none;
  white-space: normal;
}

.admin-app .button.primary, .admin-dialog .button.primary { border-color: var(--blue); }
.admin-app #edit-region { gap: .22rem; }
.admin-card {
  min-width: 0;
  border: 1px solid #d5deea;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 6px #192b4407;
}

.admin-card-heading { padding: .95rem 1.2rem; }
.admin-card h2 {
  font-size: 1.13rem;
  font-weight: 660;
  letter-spacing: -.022em;
}

.report-overview {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem 1.65rem;
  padding: 1.18rem 1.2rem;
  border-top: 3px solid #2955a4;
}

.admin-kicker { color: var(--muted); font-size: .78rem; font-weight: 590; }
.report-identity h2 { margin-top: .14rem; font-size: clamp(1.2rem, 2.4vw, 1.65rem); line-height: 1.25; }
.report-totals { display: flex; gap: clamp(.85rem, 2vw, 1.5rem); }
.report-totals div { padding-left: .95rem; border-left: 1px solid var(--line); }
.report-totals dt { color: var(--muted); font-size: .77rem; }
.report-totals dd {
  margin-top: .02rem;
  color: #244b91;
  font-size: 1.36rem;
  font-weight: 670;
  line-height: 1.2;
}

.date-tools {
  display: flex;
  align-items: end;
  gap: .5rem;
  margin-left: auto;
}

.admin-field {
  display: grid;
  gap: .28rem;
  min-width: 0;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 550;
}

.admin-field :is(input, select, textarea), .admin-search {
  min-width: 0;
  min-height: 42px;
  border: 1px solid #aebdd0;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: .875rem;
}

.admin-field :is(input, select, textarea) { width: 100%; padding: .42rem .65rem; }
.admin-field textarea { min-height: 77px; resize: vertical; font: inherit; }
.admin-search { display: flex; align-items: center; gap: .42rem; padding-inline: .65rem .32rem; }
.admin-search .icon { color: #557097; }
.admin-search input { width: min(12rem, 100%); min-width: 0; border: 0; background: transparent; padding: .4rem .1rem; }
.admin-search input:focus-visible { outline: none; }
.admin-search:focus-within { border-color: var(--focus); outline: 2px solid #d5e2fb; }

.report-content { display: grid; gap: 1rem; margin-top: 1rem; }
.admin-table { font-size: .865rem; }
.admin-table :is(td, th) { padding: .68rem 1.2rem; border-top: 1px solid #e0e6ef; text-align: left; }
.admin-table thead { background: #f2f5fa; color: var(--muted); }
.admin-table thead th { font-size: .78rem; font-weight: 620; }
.admin-table tbody th { overflow-wrap: anywhere; font-weight: 600; }
.admin-table tbody tr:hover { background: #f7f9fd; }
.region-table :is(td, th):nth-child(2) { width: 7rem; text-align: right; white-space: nowrap; }
.region-table :is(td, th):last-child { width: 12.5rem; text-align: right; }
.region-table .empty-row td { padding-block: 1.45rem; color: var(--muted); text-align: left; }
.region-district { display: block; margin-top: .15rem; color: var(--muted); font-size: .75rem; font-weight: 440; }

.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: .4rem; }
.admin-app .row-edit { min-height: 36px; gap: .38rem; padding-inline: .55rem; color: #263e61; font-size: .8rem; }
.row-edit .icon { width: 1rem; height: 1rem; }
.action-menu { position: relative; }
.action-menu summary { list-style: none; }
.action-menu summary::-webkit-details-marker { display: none; }
.admin-app .action-trigger {
  width: 42px;
  padding: 0;
  color: #263e61;
  font-size: 1.28rem;
  line-height: 1;
  letter-spacing: .05em;
  user-select: none;
}

.row-actions .action-trigger { width: 36px; min-height: 36px; }
.action-popover {
  position: absolute;
  z-index: 4;
  top: calc(100% + .26rem);
  right: 0;
  display: grid;
  min-width: 11rem;
  padding: .25rem;
  border: 1px solid #cad6e5;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 18px #192b4423;
  text-align: left;
}

.action-popover :is(a, button) {
  padding: .55rem .65rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font-size: .84rem;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
}

.action-popover :is(a, button):hover { background: var(--tint); }
.danger { color: #9c292d !important; }
.button.danger-fill { background: #9c292d; color: white; border-color: #9c292d; }
.button.danger-fill:hover { background: #792125; }

.admin-table-scroll { overflow: auto; }
.audit-table { min-width: 580px; }
.audit-table :is(th,td) { white-space: nowrap; }
.audit-table th:first-child { border-top-left-radius: 7px; }
.audit-table th:last-child { border-top-right-radius: 7px; }
.audit-action { font-weight: 560; }
.audit-action[data-operation="create"] { color: #205944; }
.audit-action[data-operation="update"] { color: #264a83; }
.audit-action[data-operation="delete"] { color: #8d2930; }

.excel-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(15rem, 20rem); align-items: start; gap: 1rem; }
.excel-panel { padding: 1.2rem; }
.excel-panel > .caption { margin-top: .6rem; font-size: .86rem; }
.excel-link { margin-top: .95rem; }
.excel-upload { margin-top: 1rem; }
.excel-upload .admin-field { max-width: 13rem; }
.excel-upload > .button { margin-top: 1.2rem; }
.file-drop {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  min-height: 9.5rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px dashed #9baec9;
  border-radius: 7px;
  background: #f6f9fd;
  color: #243f66;
  text-align: center;
  cursor: pointer;
}

.file-drop :is(strong, span) { overflow-wrap: anywhere; }
.file-drop > .icon { width: 1.5rem; height: 1.5rem; margin-bottom: .48rem; }
.file-drop:hover, .file-drop.is-dropping { border-color: var(--focus); background: #edf4ff; }
.file-drop.is-selected { border-style: solid; border-color: #9db5dc; background: #eff5fd; }
.file-drop.is-invalid { border-color: #a52e32; }
.file-drop:has(:disabled) { cursor: default; }
.file-drop:focus-within { outline: 2px solid var(--focus); outline-offset: 3px; }

.message { font-size: .86rem; color: #205944; }
.message.error { color: #9c292d; }
.message:empty { display: none; }
#workspace-message {
  margin-bottom: .85rem;
  padding: .65rem .8rem;
  border: 1px solid #bcd8cb;
  border-radius: 5px;
  background: #f0f8f4;
}

#workspace-message.error { border-color: #e6c6c7; background: #fbf2f2; }

.admin-dialog {
  width: min(calc(100% - 1rem), 840px);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 12px 32px #16283a36;
}

.admin-dialog :is(form, .picker-layout) { display: flex; flex-direction: column; max-height: calc(100dvh - 1.6rem); }
.dialog-heading, .dialog-content, .dialog-actions { padding: .95rem 1.15rem; }
.dialog-heading { border-bottom: 1px solid var(--line); }
.dialog-heading h2 { font-size: 1.35rem; line-height: 1.25; font-weight: 660; }
.dialog-content { overflow: auto; }
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .5rem;
  border-top: 1px solid var(--line);
  background: #f5f7fb;
}

.dialog-actions .message { width: 100%; }
.risk-tabs { display: flex; flex-wrap: wrap; gap: .32rem; margin-top: .7rem; }
.risk-tabs button {
  min-height: 36px;
  padding: .32rem .62rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 590;
}

.risk-tabs button:hover { background: var(--tint); }
.risk-tabs button[aria-pressed="true"] { border-color: #9db5dc; background: #eaf1fd; color: #224eab; }
.risk-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 152px), 1fr)); gap: .6rem .72rem; }
.risk-fields .admin-field { grid-template-rows: 1fr auto; }
.risk-section { min-width: 0; margin: .8rem 0 0; padding: .56rem .72rem .72rem; border: 1px solid var(--line); border-radius: 6px; }
.risk-section legend { font-weight: 650; font-size: .88rem; padding-inline: .25rem; }
.year-field { margin-top: .82rem; }
.transfer-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(75px, 95px) auto;
  align-items: end;
  gap: .5rem;
  margin-bottom: .65rem;
  padding-bottom: .65rem;
  border-bottom: 1px solid var(--line);
}

.text-button { min-height: 38px; padding: .22rem .35rem; border: 0; background: none; color: var(--blue); text-decoration: underline; font-size: .85rem; }
.confirm-dialog, .compact-dialog { max-width: 470px; }
.picker-dialog { max-width: 560px; }
.picker-heading .admin-search { margin-top: .8rem; }
.picker-heading .admin-search input { width: 100%; }
.picker-results { min-height: 7rem; max-height: 47dvh; }
.picker-results ul { display: grid; gap: .18rem; padding: 0; list-style: none; }
.picker-results button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: .47rem .6rem;
  border: 0;
  border-radius: 5px;
  background: #fff;
  font-size: .91rem;
  font-weight: 580;
  text-align: left;
}

.picker-results button:is(:hover, :focus-visible) { background: #ecf2fc; }
.picker-results button:focus-visible { outline-offset: -2px; }
.import-note { padding: .65rem .75rem; background: var(--tint); margin-bottom: .65rem; font-size: .875rem; }
.button:disabled { opacity: .6; cursor: default; }

@media (max-width: 900px) {
  .admin-app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .admin-rail {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    min-height: 0;
    padding: .58rem 1rem .47rem;
  }
  .admin-brand { margin: 0; }
  .admin-nav { display: flex; grid-area: 2 / 1 / 3 / -1; flex-wrap: wrap; margin-top: .35rem; }
  .admin-rail-footer { display: flex; margin: 0; padding: 0; border: 0; }
  .admin-rail-footer :is(a, button) { padding-inline: .35rem; }
}

@media (max-width: 680px) {
  .admin-page-heading .desktop-import { display: none; }
  .excel-grid { grid-template-columns: 1fr; }
  .date-tools { margin-left: 0; }
  .report-overview { justify-content: space-between; }
  .region-table :is(td, th) { padding-inline: .6rem; }
  .region-table :is(td, th):last-child { width: 5.85rem; }
  .region-table :is(td, th):nth-child(2) { width: 4rem; }
  .admin-app .row-edit { width: 36px; padding: 0; }
  .row-edit span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .transfer-line { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .admin-app { --rail-gap: .35rem; }
  .admin-brand { font-size: .98rem; }
  .admin-rail { column-gap: var(--rail-gap); }
  .admin-nav a { gap: .25rem; padding-inline: .34rem; min-height: 40px; font-size: .77rem; }
  .admin-nav .icon { width: 1rem; height: 1rem; }
  .admin-card-heading, .report-overview, .excel-panel { padding-inline: .78rem; }
  .admin-card-heading .admin-heading-actions { flex: 1 1 100%; }
  .admin-heading-actions .admin-search { flex: 1; }
  .admin-heading-actions .admin-search input { width: 100%; }
  .add-region-label { display: none; }
}
