/* ==========================================================================
   APAR (CAS 2018) - Screen & Print Stylesheet
   ========================================================================== */

:root {
  --bg-page: #edf1f7;
  --bg-paper: #ffffff;
  --text-main: #1a1f29;
  --text-muted: #525d6d;
  --border-dark: #2c3440;
  --border-light: #cbd5e1;
  --accent: #1b365d;
  --accent-hover: #122643;
  --focus-ring: #0b57d0;
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-doc: "Times New Roman", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
}

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-doc);
  line-height: 1.45;
}

.visually-hidden {
  position: absolute;
  clip-path: inset(50%);
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  white-space: nowrap;
}

/* ---------- Sticky Toolbar (Screen Only) ---------- */
.app-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #ffffff;
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
  font-family: var(--font-ui);
}

.toolbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.95rem;
  color: var(--accent);
}

.save-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #e6f4ea;
  color: #137333;
}

.save-badge.is-saving {
  background: #fef7e0;
  color: #b06000;
}

.toolbar-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.toolbar-nav a {
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.toolbar-nav a:hover {
  background: #f1f5f9;
  color: var(--accent);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.privacy-strip {
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  padding: 0.28rem 1rem;
  text-align: center;
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-sm {
  font-size: 0.76rem;
  padding: 0.28rem 0.6rem;
  background: #f1f5f9;
  color: var(--accent);
  border-color: var(--border-light);
}

.btn-sm:hover {
  background: #e2e8f0;
}

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

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

.btn-secondary {
  background: #ffffff;
  color: var(--text-main);
  border-color: var(--border-light);
}

.btn-secondary:hover {
  background: #f8fafc;
}

.btn-danger {
  background: #ffffff;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fef2f2;
}

/* ---------- Confirmation Dialog ---------- */
.confirm-dialog {
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 1.5rem;
  max-width: 420px;
  width: calc(100% - 2rem);
  font-family: var(--font-ui);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.2);
}

.confirm-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.confirm-dialog h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  color: var(--text-main);
}

.confirm-dialog p {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.btn-remove-row {
  background: transparent;
  color: var(--danger);
  border: none;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
}

.btn-remove-row:hover {
  background: #fee2e2;
}

:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- Document Sheet ---------- */
.page-wrapper {
  padding: 1.5rem 1rem 3rem;
}

.apar-document {
  max-width: 960px;
  margin: 0 auto;
  background: var(--bg-paper);
  padding: 2.25rem 2.5rem;
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.09);
  font-size: 15px;
}

/* ---------- Official Header ---------- */
.doc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.crest {
  flex: 0 0 auto;
}

.crest img {
  display: block;
  width: 76px;
  height: 76px;
  object-fit: contain;
}

.header-text {
  text-align: center;
  flex: 1;
}

.header-text h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.03em;
  font-weight: 700;
}

.header-text .uni-name {
  margin: 0.1rem 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.header-text .college-addr {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
}

.header-rule {
  border: 0;
  border-top: 2px solid var(--accent);
  margin: 0.75rem 0 1.1rem;
}

.doc-title-block {
  text-align: center;
  margin-bottom: 1.4rem;
}

.doc-title-block h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
}

.doc-title-block .subtitle {
  margin: 0.25rem 0 0.75rem;
  font-size: 0.95rem;
}

.academic-year-row {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.year-note {
  margin: 0;
  font-size: 0.9rem;
  text-decoration: underline;
}

/* ---------- Sections & Headings ---------- */
.form-section {
  margin-bottom: 2rem;
}

.section-heading {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: underline;
  margin: 1.4rem 0 0.9rem;
}

.subsection-heading {
  font-size: 0.96rem;
  font-weight: 700;
  margin: 1.1rem 0 0.5rem;
  line-height: 1.35;
}

.center-note {
  text-align: center;
  margin: -0.5rem 0 0.9rem;
  font-size: 0.92rem;
}

.field-title {
  margin: 0.75rem 0 0.45rem;
  font-weight: 500;
}

.sub-title {
  margin: 0.5rem 0 0.35rem;
  font-size: 0.94rem;
}

.q-num {
  display: inline-block;
  min-width: 1.65rem;
  font-weight: 600;
}

/* ---------- Form Controls ---------- */
.numbered-fields {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.inline-field {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.45rem 0.65rem;
}

.inline-field label {
  font-weight: 500;
  flex: 0 0 auto;
}

.line-input {
  flex: 1 1 220px;
  min-width: 140px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-main);
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-bottom: 1.5px solid var(--border-dark);
  border-radius: 4px 4px 0 0;
  padding: 0.35rem 0.5rem;
}

.short-input {
  flex: 0 1 200px;
  min-width: 130px;
}

.uppercase-input {
  text-transform: uppercase;
}

.stacked-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.sub-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-left: 1.6rem;
  margin-bottom: 0.45rem;
}

.sub-inline-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.65rem 1.25rem;
  margin-top: 0.35rem;
}

.box-textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-main);
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
  resize: vertical;
  overflow-y: hidden;
  line-height: 1.4;
}

.label-with-action {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--accent);
  cursor: pointer;
}

.checkbox-inline input[type="checkbox"] {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
}

.word-count {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.hint {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---------- Tables ---------- */
.table-block {
  margin: 0.9rem 0 1.25rem;
}

.table-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border-dark);
  padding: 0.3rem 0.35rem;
  vertical-align: top;
}

.data-table th {
  background: #f8fafc;
  font-weight: 700;
  text-align: center;
  vertical-align: middle;
}

.data-table .text-left {
  text-align: left;
}

.data-table .text-center {
  text-align: center;
  vertical-align: middle;
}

.col-sno {
  width: 2.6rem;
  text-align: center;
}

.col-year {
  width: 4.5rem;
}

.col-action {
  width: 2.5rem;
  text-align: center;
}

.table-input,
.table-textarea,
.table-select {
  width: 100%;
  min-width: 0;
  font-family: inherit;
  font-size: 0.86rem;
  color: var(--text-main);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 0.25rem 0.3rem;
  line-height: 1.3;
}

.table-textarea {
  resize: vertical;
  overflow-y: hidden;
  min-height: 2rem;
}

.table-input:hover,
.table-textarea:hover,
.table-select:hover,
.table-input:focus,
.table-textarea:focus,
.table-select:focus {
  background: #f8fafc;
  border-color: var(--border-light);
}

.compact-table {
  font-size: 0.8rem;
}

.compact-table .table-input,
.compact-table .table-textarea,
.compact-table .table-select {
  font-size: 0.78rem;
  padding: 0.2rem;
}

.calc-cell {
  text-align: center;
  vertical-align: middle !important;
  font-weight: 600;
  background: #f8fafc;
}

.b1-grade-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: center;
}

.calc-pct {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
}

.grade-input {
  text-align: center;
  font-weight: 700;
}

/* ---------- Criteria & Footnotes ---------- */
.criteria-box {
  margin: 0.4rem 0 0.8rem 1.4rem;
  font-size: 0.92rem;
}

.criteria-box p,
.criteria-box ol {
  margin: 0.2rem 0;
}

.footnote {
  font-size: 0.88rem;
  margin-top: 0.5rem;
}

.footnote ul {
  margin: 0.25rem 0 0.25rem 1.25rem;
  padding: 0;
}

/* ---------- Enclosures ---------- */
.enclosures-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 1.5rem;
  margin-top: 0.75rem;
}

.enclosure-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.enclosure-num {
  min-width: 1.75rem;
  font-weight: 600;
}

/* ---------- Part D Declaration ---------- */
.declaration-section {
  margin-top: 1.5rem;
}

.declaration-text {
  text-align: justify;
  margin-bottom: 1.4rem;
}

.sig-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
  margin: 1.5rem 0;
}

.sig-left {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.sig-right,
.hod-sig-block {
  text-align: center;
  min-width: 240px;
}

.hod-sig-block {
  margin-left: auto;
  margin-top: 2.5rem;
  width: fit-content;
}

.sig-line {
  border-bottom: 1px solid var(--border-dark);
  height: 2.2rem;
  margin-bottom: 0.35rem;
}

.section-divider {
  border: 0;
  border-top: 1px dashed var(--border-light);
  margin: 1.5rem 0;
}

.cert-paragraph {
  line-height: 2;
}

.inline-blank {
  font-family: inherit;
  font-size: 0.95rem;
  border: none;
  border-bottom: 1.5px dotted var(--border-dark);
  background: #f8fafc;
  padding: 0.1rem 0.35rem;
  min-width: 190px;
  color: var(--text-main);
}

.short-blank {
  min-width: 130px;
}

/* ---------- Mobile Adjustments ---------- */
@media (max-width: 720px) {
  .apar-document {
    padding: 1.25rem 1rem;
  }

  .doc-header {
    flex-direction: column;
    text-align: center;
  }

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

/* ==========================================================================
   PRINT STYLES (A4 Clean Output)
   ========================================================================== */
@page {
  size: A4 portrait;
  margin: 12mm 12mm 14mm 12mm;
}

@media print {
  .no-print {
    display: none !important;
  }

  html,
  body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .page-wrapper {
    padding: 0 !important;
  }

  .apar-document {
    max-width: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    font-size: 10.5pt !important;
    line-height: 1.35 !important;
  }

  .page-break-before {
    break-before: page;
  }

  .table-scroll {
    overflow: visible !important;
  }

  /* Strip input chrome so filled values look cleanly printed on paper */
  .line-input,
  .box-textarea,
  .inline-blank,
  select.line-input {
    background: transparent !important;
    border: none !important;
    border-bottom: 1px solid #000000 !important;
    border-radius: 0 !important;
    padding: 1px 3px !important;
    color: #000000 !important;
    appearance: none !important;
    -webkit-appearance: none !important;
  }

  .box-textarea {
    border: 1px solid #888888 !important;
    padding: 3px 5px !important;
  }

  .table-input,
  .table-textarea,
  .table-select {
    background: transparent !important;
    border: none !important;
    padding: 1px 2px !important;
    color: #000000 !important;
    appearance: none !important;
    -webkit-appearance: none !important;
  }

  input::placeholder,
  textarea::placeholder {
    color: transparent !important;
  }

  .data-table {
    font-size: 8.5pt !important;
  }

  .compact-table {
    font-size: 7.4pt !important;
  }

  .compact-table .table-input,
  .compact-table .table-textarea,
  .compact-table .table-select {
    font-size: 7.4pt !important;
  }

  .data-table th {
    background: #f2f2f2 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  thead {
    display: table-header-group;
  }

  tr,
  .table-block,
  .data-table,
  .inline-field,
  .stacked-field,
  .declaration-section,
  .hod-cert {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .section-heading,
  .subsection-heading,
  .field-title,
  .sub-title {
    break-after: avoid;
  }
}
