:root {
  --ink: #22172f;
  --muted: #74677f;
  --line: #ded4ea;
  --surface: #ffffff;
  --bg: #f4eefb;
  --primary: #6d28d9;
  --primary-dark: #4c1d95;
  --accent: #a21caf;
  --success: #5b8c2a;
  --warning: #a16207;
  --danger: #be185d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.dark-mode {
  --ink: #f5edff;
  --muted: #c9b8dc;
  --line: #4a365f;
  --surface: #1d1429;
  --bg: #130c1d;
  --primary: #a78bfa;
  --primary-dark: #c4b5fd;
  --accent: #f0abfc;
  --success: #9cca5d;
  --warning: #f0b454;
  --danger: #fb7185;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(244, 238, 251, 0.96), rgba(244, 238, 251, 1)),
    url("https://images.unsplash.com/photo-1488998427799-e3362cec87c3?auto=format&fit=crop&w=1800&q=80");
  background-size: cover;
  background-attachment: fixed;
}

body.dark-mode {
  background:
    linear-gradient(180deg, rgba(19, 12, 29, 0.97), rgba(19, 12, 29, 1)),
    url("https://images.unsplash.com/photo-1488998427799-e3362cec87c3?auto=format&fit=crop&w=1800&q=80");
  background-size: cover;
  background-attachment: fixed;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid rgba(109, 40, 217, 0.16);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(10px);
}

body.dark-mode .topbar {
  border-bottom-color: rgba(196, 181, 253, 0.2);
  background: rgba(19, 12, 29, 0.88);
}

.topbar-title {
  grid-column: 2;
  text-align: center;
}

.topbar-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.topbar-actions button {
  min-height: 38px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 22px;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.view {
  display: grid;
  gap: 18px;
}

.tabs {
  display: flex;
  gap: 8px;
  grid-column: 3;
  justify-self: end;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.tab,
button,
.button-link {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.button-link {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.tab {
  color: var(--muted);
  background: transparent;
}

.theme-toggle {
  width: 42px;
  padding: 0;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  font-size: 20px;
  line-height: 1;
}

.language-select {
  width: auto;
  min-height: 42px;
  border-color: var(--line);
  padding: 0 10px;
  color: var(--ink);
  background: var(--surface);
  font-size: 13px;
  font-weight: 800;
}

.tab.is-active {
  color: #fff;
  background: var(--primary);
}

.section-tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 30px rgba(68, 30, 112, 0.1);
}

body.dark-mode .section-tabs {
  background: rgba(29, 20, 41, 0.94);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
}

.section-tab {
  flex: 1;
  min-height: 42px;
  color: var(--muted);
  background: transparent;
}

.section-tab.is-active {
  color: #fff;
  background: var(--primary);
}

.public-section {
  display: grid;
  gap: 18px;
}

.split,
.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.9fr);
  gap: 18px;
}

.admin-grid {
  grid-template-columns: 1fr;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 40px rgba(68, 30, 112, 0.1);
}

body.dark-mode .panel {
  background: rgba(29, 20, 41, 0.96);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

.notice-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid #fecaca;
  border-left: 4px solid #dc2626;
  border-radius: 8px;
  margin-bottom: 18px;
  padding: 12px 14px;
  color: #991b1b;
  background: #fef2f2;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.55;
}

.notice-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: #dc2626;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
}

body.dark-mode .notice-note {
  border-color: #7f1d1d;
  border-left-color: #ef4444;
  color: #fecaca;
  background: #2a1114;
}

body.dark-mode .notice-icon {
  background: #ef4444;
}

.template-search {
  margin-bottom: 18px;
}

.wide {
  grid-column: 1 / -1;
  min-width: 0;
}

.title-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 16px;
}

.monitoring-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

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

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

.recipient-actions button {
  min-height: 38px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.inline-check input {
  width: auto;
}

.login-panel {
  max-width: 680px;
  width: min(680px, 100%);
  justify-self: center;
  align-self: center;
}

#adminView {
  min-height: min(540px, calc(100vh - 180px));
}

.section-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.badge {
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--primary-dark);
  background: #efe7ff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

body.dark-mode .badge {
  color: #f5edff;
  background: #3b2454;
}

.form {
  display: grid;
  gap: 14px;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d7c8e8;
  border-radius: 7px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-weight: 500;
}

body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  border-color: #4a365f;
  color: var(--ink);
  background: #130c1d;
}

body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(109, 40, 217, 0.2);
  border-color: var(--primary);
}

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

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

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

body.dark-mode .secondary {
  background: #1a1025;
}

.text-button {
  min-height: 38px;
  padding: 0;
  color: var(--primary-dark);
  background: transparent;
}

.text-button:hover {
  color: var(--primary);
  text-decoration: underline;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.danger-icon {
  color: #b91c1c;
  background: transparent;
}

.danger-icon:hover {
  color: #dc2626;
  background: transparent;
}

body.dark-mode .danger-icon {
  color: #fecaca;
  background: transparent;
}

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

.template-groups {
  display: grid;
  gap: 18px;
}

.template-category {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffcff;
}

body.dark-mode .template-category {
  background: #1a1025;
}

.template-category-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  border-radius: 0;
  border-bottom: 1px solid #d8c2ff;
  padding: 14px 16px;
  color: var(--ink);
  background: #fbf7ff;
  text-align: left;
}

.template-category-head:hover {
  background: #f5efff;
}

body.dark-mode .template-category-head {
  border-bottom-color: var(--line);
  background: #20162e;
}

body.dark-mode .template-category-head:hover {
  background: #281a39;
}

.category-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary-dark);
  font-size: 18px;
  font-weight: 850;
}

.category-title span:last-child {
  overflow-wrap: anywhere;
}

.category-chevron {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #d8c2ff;
  border-radius: 999px;
  color: var(--primary-dark);
  background: #fff;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}

body.dark-mode .category-title {
  color: var(--primary-dark);
}

body.dark-mode .category-chevron {
  border-color: #4a365f;
  background: #1a1025;
}

.category-count {
  min-width: 32px;
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--primary-dark);
  background: #efe7ff;
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

body.dark-mode .category-count {
  color: #f5edff;
  background: #3b2454;
}

.template-category-body {
  padding: 14px;
}

#submissionList {
  min-height: 0;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 150px repeat(3, minmax(120px, 0.7fr)) auto;
  gap: 10px;
  align-items: end;
  margin: -4px 0 16px;
  border: 1px solid #eadff5;
  border-radius: 8px;
  padding: 12px;
  background: #fbf7ff;
}

body.dark-mode .filter-bar {
  border-color: var(--line);
  background: #1a1025;
}

.filter-bar label {
  gap: 5px;
  font-size: 12px;
}

.filter-bar input,
.filter-bar select {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 13px;
}

.filter-bar button {
  min-height: 38px;
}

.empty {
  color: var(--muted);
  font-weight: 650;
}

.item {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

body.dark-mode .item {
  background: #1d1429;
}

.submission-card {
  border-left: 4px solid var(--primary);
}

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

.submission-title {
  display: flex;
  align-items: start;
  gap: 12px;
}

.submission-detail {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.status-pill {
  border-radius: 999px;
  padding: 6px 9px;
  color: #fff;
  background: var(--primary);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.doc-link {
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #fbf7ff;
}

body.dark-mode .doc-link {
  background: #1a1025;
}

.doc-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.doc-actions > * {
  position: relative;
}

.doc-actions > * + * {
  margin-left: 10px;
  padding-left: 10px;
}

.doc-actions > * + *::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 1px;
  background: var(--line);
}

.doc-actions button {
  min-height: 38px;
}

.doc-actions a {
  min-height: 38px;
  display: inline-grid;
  place-items: center;
}

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

.meta-grid div {
  min-width: 0;
  border: 1px solid #eadff5;
  border-radius: 7px;
  padding: 10px;
  background: #fbf7ff;
}

body.dark-mode .meta-grid div {
  border-color: var(--line);
  background: #1a1025;
}

.meta-grid span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-grid strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.applicant-list {
  display: grid;
  gap: 6px;
}

.applicant-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(110px, 0.5fr) minmax(120px, 0.6fr);
  gap: 8px;
  border: 1px solid #eadff5;
  border-radius: 7px;
  padding: 9px 10px;
  color: #4a3a5f;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
}

body.dark-mode .applicant-row {
  border-color: var(--line);
  color: var(--ink);
  background: #1a1025;
}

.applicant-row span {
  overflow-wrap: anywhere;
}

.read-result,
.status-note {
  border-radius: 7px;
  padding: 10px 12px;
  color: #5f526f;
  background: #fbf7ff;
  font-size: 13px;
  line-height: 1.5;
}

body.dark-mode .read-result {
  color: var(--muted);
  background: #1a1025;
}

.status-note {
  color: var(--primary-dark);
  background: #f0e8ff;
  font-weight: 750;
}

body.dark-mode .status-note {
  color: #f5edff;
  background: #3b2454;
}

.status-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.status-row .status-note {
  margin: 0;
}

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

.item-title {
  font-weight: 850;
}

.item-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.item a {
  color: var(--primary-dark);
  font-weight: 800;
  text-decoration: none;
}

body.dark-mode .item a,
body.dark-mode .doc-link {
  color: var(--primary-dark);
}

.progress {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 6px;
}

.step {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  place-items: center;
  padding: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.step.is-done {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.step.is-rejected {
  color: #fff;
  border-color: var(--danger);
  background: var(--danger);
}

.admin-actions {
  display: grid;
  grid-template-columns: minmax(130px, 0.4fr) minmax(0, 1fr) auto auto;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.emergency-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--danger);
  background: #fff4fa;
  white-space: nowrap;
}

body.dark-mode .emergency-toggle {
  background: #3a1527;
}

.emergency-toggle input {
  width: auto;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  padding: 13px 15px;
  color: #fff;
  background: var(--ink);
  font-weight: 750;
  transition: 180ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 12, 38, 0.54);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(68, 30, 112, 0.28);
}

body.dark-mode .modal-panel {
  background: #1d1429;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
}

.download-confirm-panel {
  width: min(520px, 100%);
}

.download-file-name {
  margin-bottom: 16px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 850;
  line-height: 1.45;
}

.letter-preview {
  border: 1px solid #eadff5;
  border-radius: 8px;
  padding: 28px;
  color: #22172f;
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.64);
}

body.dark-mode .letter-preview {
  border-color: var(--line);
}

.letter-document {
  display: grid;
  gap: 24px;
}

.letter-sheet {
  width: min(760px, 100%);
  margin: 0 auto;
  line-height: 1.8;
  font-family: "Times New Roman", serif;
  font-size: 16px;
}

.letter-sheet p {
  margin: 0 0 12px;
}

.letter-date {
  text-align: right;
}

.letter-recipient {
  margin-bottom: 36px;
}

.letter-recipient-line {
  margin-bottom: 6px;
}

.letter-title {
  margin: 0 0 28px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
}

.letter-intro {
  margin-bottom: 20px;
}

.letter-table {
  border-collapse: collapse;
  margin: 0 0 32px 52px;
}

.letter-table td {
  padding: 2px 18px 8px 0;
  vertical-align: top;
}

.letter-table td:first-child {
  min-width: 110px;
}

.letter-body {
  text-align: justify;
}

.signature-block {
  width: min(260px, 100%);
  margin-top: 30px;
  margin-left: 48px;
}

.signature-space {
  height: 84px;
}

.letter-attachment-page {
  width: min(760px, 100%);
  min-height: 960px;
  margin: 0 auto;
  padding: 24px;
  background: #ffffff;
  page-break-before: always;
  break-before: page;
}

.attachment-frame {
  display: grid;
  place-items: center;
  min-height: 900px;
}

.attachment-image {
  max-width: 100%;
  max-height: 900px;
  object-fit: contain;
}

.is-hidden {
  display: none !important;
}

@media (min-width: 861px) {
  body {
    min-height: 100vh;
    overflow: hidden;
  }

  .topbar {
    min-height: 112px;
  }

  main {
    height: calc(100vh - 112px - 56px);
    overflow: hidden;
  }

  .view,
  #adminPanel {
    min-height: 0;
  }

  #adminPanel {
    height: 100%;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  #adminView {
    height: 100%;
  }

  .monitoring-panel {
    min-height: 0;
    overflow: hidden;
  }

  #submissionList {
    overflow: auto;
    padding-right: 4px;
  }

  #publicView {
    max-height: 100%;
    overflow: auto;
    padding-right: 4px;
  }
}

@media (max-width: 860px) {
  body {
    background-attachment: scroll;
  }

  main {
    width: min(100% - 24px, 1180px);
    margin: 18px auto 36px;
  }

  .topbar,
  .item-head,
  .submission-head,
  .submission-title,
  .admin-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: flex;
    text-align: center;
  }

  .tabs {
    align-self: center;
    justify-self: center;
  }

  .language-select {
    width: 100%;
  }

  .template-category-head {
    min-height: 54px;
    padding: 12px;
  }

  .category-title {
    font-size: 16px;
  }

  .template-category-body {
    padding: 12px;
  }

  .tabs,
  .inline-form,
  .filter-bar,
  .split,
  .admin-grid,
  .generator-grid,
  .admin-actions,
  .status-row {
    grid-template-columns: 1fr;
  }

  .tabs {
    display: grid;
    grid-template-columns: 1fr;
  }

  .section-tabs {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .meta-grid,
  .applicant-row {
    grid-template-columns: 1fr;
  }

  .doc-actions {
    justify-content: stretch;
  }

  .doc-actions > * {
    width: 100%;
    margin-left: 0;
    padding-left: 0;
  }

  .doc-actions > *::before {
    display: none;
  }

  .doc-actions > .icon-button {
    width: 40px;
    min-width: 40px;
  }

  button,
  .button-link,
  .doc-actions a,
  .doc-actions button,
  .title-actions button,
  .section-tab,
  .tab {
    min-height: 40px;
    padding-inline: 12px;
    font-size: 13px;
    line-height: 1.2;
    text-align: center;
  }

  .title-actions {
    justify-content: stretch;
  }

  .title-actions > * {
    width: 100%;
  }

  h1 {
    font-size: 30px;
  }

  .panel {
    padding: 16px;
  }

  .modal {
    align-items: end;
    padding: 0;
  }

  .modal-panel {
    width: 100%;
    max-height: 92vh;
    border-radius: 8px 8px 0 0;
    padding: 18px;
  }
}
