:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #d9dee7;
  --text: #18202c;
  --muted: #637083;
  --accent: #1f6feb;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  font-size: 18px;
  font-weight: 700;
}

.admin-link {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.topbar-actions form {
  display: flex;
  align-items: center;
  margin: 0;
}

.logout-button {
  width: auto;
  min-height: 26px;
  padding: 0 8px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(145deg, #eef4ff, var(--bg) 55%);
}

.login-card {
  width: min(100%, 390px);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(24, 32, 44, 0.1);
}

.login-heading {
  margin-bottom: 24px;
}

.login-heading span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.login-heading h1 {
  margin-top: 8px;
  font-size: 26px;
}

.login-heading p {
  margin: 8px 0 0;
  color: var(--muted);
}

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

.login-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: #fff1f0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
}

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 14px 86px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.summary div,
.section,
.detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary div {
  min-width: 0;
  padding: 12px;
}

.label,
.category,
.meta,
.empty,
dt {
  color: var(--muted);
}

.summary strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.quick-search,
.filters {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.quick-search {
  grid-template-columns: 1fr 150px 72px;
}

.filters {
  grid-template-columns: 1fr 150px 130px 72px;
}

input,
select,
button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.section,
.detail {
  margin-bottom: 14px;
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

h1,
h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

h2 {
  font-size: 17px;
}

.material-list,
.simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.material-list li,
.simple-list li {
  border-bottom: 1px solid var(--line);
}

.material-list li:last-child,
.simple-list li:last-child {
  border-bottom: 0;
}

.material-link,
.simple-list li {
  display: grid;
  gap: 5px;
  padding: 13px 14px;
}

.recent-movement-list {
  max-height: 230px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.recent-movement-list li {
  padding: 0;
}

.recent-movement-list li a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  color: inherit;
  text-decoration: none;
}

.recent-movement-list li a:hover,
.recent-movement-list li a:focus-visible {
  background: #f7f9fc;
}

.recent-movement-list li a span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-movement-list li a strong {
  white-space: nowrap;
}

.material-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 126px;
  align-items: center;
  gap: 10px;
}

.material-actions {
  display: grid;
  grid-template-columns: repeat(2, 58px);
  gap: 8px;
  padding: 10px 14px 10px 0;
  justify-content: end;
}

.material-list strong {
  font-size: 16px;
}

.category {
  font-size: 13px;
  font-weight: 700;
}

.meta {
  font-size: 14px;
}

.empty {
  margin: 0;
  padding: 16px 14px;
}

.inbound-search {
  padding: 14px 14px 0;
}

.entry-form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.date-policy-notice {
  margin: 14px 14px 0;
  padding: 12px 14px;
  border: 1px solid #b9d6f2;
  border-radius: 8px;
  background: #eef7ff;
  color: #24557a;
  font-size: 14px;
  line-height: 1.55;
}

.entry-form input:disabled {
  background: #f2f4f6;
  color: var(--muted);
  cursor: not-allowed;
  opacity: 1;
}

.movement-status.locked {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.field-error {
  font-size: 13px;
  font-weight: 700;
}

.field span {
  color: var(--muted);
}

.field-error {
  color: var(--danger);
}

.form-errors {
  padding: 10px 12px;
  border: 1px solid #f1b5b0;
  border-radius: 6px;
  background: #fff1f0;
  color: var(--danger);
}

.form-errors p {
  margin: 4px 0;
  font-size: 14px;
  font-weight: 700;
}

.issue-slip-choice {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.issue-slip-choice p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.issue-slip-choice > div {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.issue-slip-choice .issued-slip-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.issued-slip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.issued-slip-row > div:first-child {
  display: grid;
  gap: 3px;
}

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

.issued-slip-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.detail {
  padding: 16px 14px;
}

.back-link {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--accent);
  font-weight: 700;
}

.detail h1 {
  margin: 6px 0 14px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.button-link.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.button-link.disabled {
  cursor: default;
  color: var(--muted);
}

.button-link span {
  margin-left: 8px;
  font-size: 13px;
  opacity: 0.86;
}

.button-link.compact {
  min-height: 38px;
  width: 58px;
  padding: 0;
  font-size: 14px;
}

.movement-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.movement-actions form {
  margin: 0;
}

.compact-danger-button {
  border: 1px solid #f0b8b3;
  border-radius: 999px;
  background: #fff5f4;
  color: var(--danger);
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.movement-status {
  color: #667085;
  font-size: 0.82rem;
  font-weight: 700;
}

.usage-history-scroll {
  max-height: 285px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.usage-history-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  table-layout: fixed;
}

.usage-history-table th,
.usage-history-table td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
}

.usage-history-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.usage-history-table td {
  font-size: 0.92rem;
}

.usage-history-table th:nth-child(1),
.usage-history-table td:nth-child(1),
.usage-history-table th:nth-child(3),
.usage-history-table td:nth-child(3) {
  width: 112px;
  white-space: nowrap;
}

.usage-history-table th:nth-child(2),
.usage-history-table td:nth-child(2) {
  width: 80px;
  white-space: nowrap;
}

.usage-history-table th:nth-child(4),
.usage-history-table td:nth-child(4) {
  width: 95px;
  white-space: nowrap;
}

.usage-history-table th:nth-child(5),
.usage-history-table td:nth-child(5) {
  width: 115px;
  white-space: nowrap;
}

.usage-history-table th:nth-child(7),
.usage-history-table td:nth-child(7) {
  width: 155px;
}

.usage-history-table .movement-actions {
  justify-content: flex-start;
}

.usage-history-note {
  color: var(--muted);
}

.flash-messages {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.flash-message {
  margin: 0;
  border: 1px solid #b8d8c3;
  border-radius: 0.75rem;
  background: #f0fff4;
  color: #176b36;
  padding: 0.75rem 1rem;
  font-weight: 700;
}

.flash-message.error {
  border-color: #f0b8b3;
  background: #fff5f4;
  color: var(--danger);
}

.issue-slip-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.issue-slip-date {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 10px;
  align-items: end;
  padding: 14px 14px 0;
}

.issue-slip-month {
  display: grid;
  grid-template-columns: 110px 110px 110px;
  gap: 10px;
  align-items: end;
  padding: 14px 14px 0;
}

.issue-calendar {
  padding: 14px 14px 0;
}

.issue-calendar-weekdays,
.issue-calendar-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.issue-calendar-weekdays {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.issue-calendar-week {
  margin-bottom: 6px;
}

.issue-calendar-day {
  display: grid;
  align-content: start;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.issue-calendar-day span {
  font-weight: 700;
}

.issue-calendar-day strong {
  margin-top: 7px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.2;
}

.issue-calendar-day em {
  margin-top: 7px;
  color: var(--accent);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  line-height: 1.2;
}

.issue-calendar-day.has-unissued {
  border-color: #f2b8ad;
  background: #fff4f2;
}

.issue-calendar-day.has-issued {
  border-color: #aac6f6;
}

.issue-calendar-day.selected {
  border-color: var(--accent);
  outline: 2px solid rgba(31, 111, 235, 0.16);
}

.issue-calendar-day.muted {
  background: #f1f3f6;
  color: var(--muted);
}

.issue-edit-form {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.issue-edit-guide {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.issue-edit-meta div,
.issue-edit-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.issue-edit-meta strong {
  display: block;
  margin-top: 5px;
}

.issue-edit-list {
  display: grid;
  gap: 10px;
}

.issue-edit-item {
  margin: 0;
}

.issue-edit-item legend {
  padding: 0 4px;
  font-weight: 700;
}

.issue-edit-item.pending {
  border-color: #aac6f6;
  background: #f8fbff;
}

.issue-edit-item legend span {
  margin-left: 6px;
  color: var(--accent);
  font-size: 12px;
}

.issue-edit-grid {
  display: grid;
  grid-template-columns: 90px 110px 110px minmax(180px, 1fr) 64px;
  gap: 10px;
  align-items: end;
}

.delete-field {
  align-items: center;
}

.delete-field input {
  width: auto;
  min-height: 18px;
}

.report-filters {
  display: grid;
  grid-template-columns: 110px 110px 150px;
  gap: 10px;
  align-items: end;
  padding: 14px;
}

.print-toolbar {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.print-options {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}

.print-options form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 10px;
  align-items: end;
  margin: 0;
}

.issue-people-selects {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}

.issue-paper {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 29mm 14mm 14mm;
  background: #ffffff;
  color: #000000;
  border: 1px solid var(--line);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

.issue-paper-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 68mm;
  align-items: start;
  gap: 6mm;
  margin-bottom: 10mm;
}

.issue-paper-head h1 {
  margin-top: 7mm;
  text-align: center;
  font-size: 22pt;
  font-weight: 700;
  line-height: 1.1;
}

.approval-box,
.issue-item-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.approval-box th,
.approval-box td,
.issue-item-table th,
.issue-item-table td {
  border: 1.5px solid #000000;
  text-align: center;
  vertical-align: middle;
}

.approval-box th,
.approval-box td {
  height: 15mm;
  padding: 1mm;
  font-size: 13pt;
  font-weight: 700;
}

.approval-box .approval-title-row th:not(:first-child) {
  height: 10mm;
}

.approval-box th:first-child {
  width: 13mm;
  line-height: 1.35;
}

.approval-final {
  font-weight: 700;
  white-space: nowrap;
  font-size: 12pt;
}

.issue-slip-no {
  margin-bottom: 2mm;
  font-size: 13pt;
  font-weight: 700;
}

.issue-item-table th {
  height: 11mm;
  padding: 1mm;
  font-size: 11pt;
  line-height: 1.15;
}

.issue-item-table td {
  height: 11mm;
  padding: 1mm 1.5mm;
  font-size: 10.5pt;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.issue-item-table td:first-child,
.issue-item-table td:last-child {
  text-align: left;
}

.item-name {
  width: 37%;
}

.item-unit {
  width: 10%;
}

.item-qty,
.item-stock {
  width: 11%;
}

.item-purpose {
  width: 31%;
}

.issue-bottom {
  position: relative;
  min-height: 76mm;
  padding-top: 16mm;
}

.issue-sentence {
  margin: 0;
  font-size: 15pt;
  font-weight: 700;
}

.issue-date {
  margin: 14mm 0 0;
  text-align: center;
  font-size: 14pt;
  font-weight: 700;
}

.issue-people {
  width: 84mm;
  display: grid;
  gap: 5mm;
  margin: 8mm 14mm 0 auto;
  font-size: 14pt;
}

.person-row {
  display: grid;
  grid-template-columns: 20mm 40mm 14mm;
  align-items: center;
  column-gap: 3mm;
  min-height: 8mm;
}

.person-label {
  font-size: 11pt;
  font-weight: 700;
  padding-right: 3mm;
  text-align: right;
  white-space: nowrap;
}

.person-row strong {
  font-size: 12pt;
  font-weight: 700;
  letter-spacing: 0;
  text-align: left;
  line-height: 1.2;
  white-space: nowrap;
}

.person-row .wide-name {
  width: auto;
  text-align-last: auto;
}

.person-sign {
  font-size: 10pt;
  text-align: right;
  white-space: nowrap;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.detail-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

dt {
  margin-bottom: 5px;
  font-size: 13px;
}

dd {
  margin: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.bottom-nav a {
  min-width: 0;
  padding: 11px 4px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.bottom-nav a.active {
  color: var(--accent);
}

.bottom-nav a[aria-disabled="true"] {
  opacity: 0.55;
}

@media (max-width: 640px) {
  .issue-slip-choice > div {
    grid-template-columns: 1fr;
  }

  .issued-slip-row {
    align-items: stretch;
    flex-direction: column;
  }

  .issued-slip-actions {
    justify-content: flex-end;
  }

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

  .quick-search,
  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .quick-search input,
  .quick-search button,
  .filters input,
  .filters button {
    grid-column: 1 / -1;
  }

  .summary strong {
    font-size: 20px;
  }

  .material-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .material-actions {
    grid-template-columns: repeat(2, 58px);
    justify-content: start;
    padding: 0 14px 13px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .issue-slip-links,
  .issue-slip-date,
  .issue-slip-month,
  .issue-edit-meta,
  .issue-edit-grid,
  .issue-people-selects,
  .print-options form,
  .report-filters,
  .print-options {
    grid-template-columns: 1fr;
  }

  .issue-calendar-day {
    min-height: 58px;
    padding: 6px 4px;
    font-size: 12px;
  }

  .issue-calendar-day strong {
    font-size: 11px;
  }

  .issue-paper {
    width: 100%;
    min-height: auto;
    padding: 14px;
    overflow-x: auto;
  }

  .issue-paper-head {
    grid-template-columns: 1fr;
  }

  .issue-paper-head h1 {
    font-size: 26px;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  body {
    background: #ffffff;
  }

  .topbar,
  .bottom-nav,
  .print-toolbar {
    display: none;
  }

  .page {
    max-width: none;
    padding: 0;
  }

  .issue-paper {
    width: 210mm;
    min-height: 297mm;
    border: 0;
    padding: 29mm 14mm 14mm;
  }
}
