:root {
  --brand: #0f4c81;
  --brand-dark: #0b3559;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #12263a;
  --text-soft: #526377;
  --border: #d9e2ec;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

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

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ------------------ HEADER ------------------ */

.page-header {
  margin-bottom: 1.5rem;
}

.page-header__inner {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: white;
  padding: 1.5rem;
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.95;
}

.page-header__inner h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2.25rem, 4vw, 3.25rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0;
  max-width: 780px;
  font-size: 1rem;
  line-height: 1.55;
  opacity: 0.96;
}

.tool-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.tool-nav__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.85rem 1.1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: white;
  text-decoration: none;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.tool-nav__link:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.tool-nav__link--active {
  background: white;
  color: var(--brand-dark);
  border-color: white;
}

/* ------------------ LAYOUT ------------------ */

.layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 1.5rem;
  margin-top: 1.5rem;
  align-items: start;
}

.card {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.preview-subtitle {
  margin-top: 0;
  color: var(--text-soft);
}

/* ------------------ FORM ------------------ */

label {
  display: block;
  font-weight: 700;
  margin-top: 0.9rem;
  margin-bottom: 0.4rem;
}

.form-section {
  margin-top: 0.2rem;
}

.hidden {
  display: none !important;
}

.field-help {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--text-soft);
}

input,
select {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid #b8c7d9;
  border-radius: 12px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

input:disabled,
select:disabled {
  background: #e9eef5;
  color: #6b7280;
  cursor: not-allowed;
  opacity: 1;
}

.button-row {
  margin-top: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

button {
  padding: 0.8rem 1.2rem;
  border-radius: 999px;
  border: none;
  background: var(--brand);
  color: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--brand-dark);
}

.button-secondary {
  background: #1f3a5f;
}

.button-danger {
  background: #8b1d1d;
}

.button-link {
  margin-top: 0.8rem;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--brand-dark);
  text-decoration: underline;
  cursor: pointer;
}

.field-example {
  margin: -0.1rem 0 0.35rem;
  font-size: 0.8rem;
  color: #6b7280;
}

.bulk-tools {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.bulk-tools h3 {
  margin: 0;
}

.button-row--stacked {
  display: grid;
  gap: 0.6rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
}

.modal__content {
  position: relative;
  max-width: 620px;
  margin: 1rem;
  padding: 1.25rem;
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  z-index: 2;
}

/* ------------------ PREVIEW ------------------ */

.preview-frame {
  margin-top: 1rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f8fafc;
  padding: 1rem;
}

.certificate-preview {
  position: relative;
  width: 100%;
  max-width: 1100px;
  aspect-ratio: 11 / 8.5;
  margin: 0 auto;
  background: white;
}

.certificate-bg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.preview-text {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: #111;
  white-space: nowrap;
}

.achievement-number {
  top: 24.5%;
  font-size: clamp(18px, 3vw, 32px);
  font-weight: 800;
  color: #0a2c85;
  letter-spacing: 0.03em;
  width: 84%;
  white-space: normal;
  line-height: 1.15;
}

.achievement-title {
  top: 34.2%;
  font-size: clamp(16px, 2.2vw, 24px);
  font-weight: 700;
  color: #17307a;
}

.cadet-name {
  top: 44.7%;
  font-size: clamp(20px, 3vw, 34px);
  font-family: Georgia, "Times New Roman", serif;
  color: #111;
}

.cadet-rank {
  top: 53.3%;
  font-size: clamp(14px, 1.9vw, 22px);
  font-weight: 800;
  color: #163b8f;
  letter-spacing: 0.02em;
}

.certificate-preview.award-mode .cadet-name {
  top: 41.8%;
}

.certificate-preview.award-mode .cadet-rank {
  top: 50.5%;
}

.preview-rank-image {
  position: absolute;
  top: 50%;
  left: 22%;
  transform: translate(-50%, -50%);
  height: 90px;
  width: auto;
  object-fit: contain;
  display: none;
}

.preview-ribbon-image {
  position: absolute;
  top: 50%;
  left: 79%;
  transform: translate(-50%, -50%);
  height: 37px;
  width: auto;
  object-fit: contain;
  display: none;
}

.presented-line {
  top: 64.4%;
  font-size: clamp(10px, 1.45vw, 18px);
  font-weight: 700;
  color: #222;
}

.unit-line {
  top: 68.4%;
  font-size: clamp(10px, 1.35vw, 17px);
  font-style: italic;
  font-weight: 700;
  color: #222;
}

.left-signer-name {
  left: 28.5%;
  top: 87.3%;
  transform: translateX(-50%);
  font-size: clamp(11px, 1.5vw, 18px);
  color: #111;
}

.left-signer-title {
  left: 28.5%;
  top: 91%;
  transform: translateX(-50%);
  font-size: clamp(10px, 1.2vw, 15px);
  color: #222;
}

.right-signer-name {
  left: 73.7%;
  top: 87.3%;
  transform: translateX(-50%);
  font-size: clamp(11px, 1.5vw, 18px);
  color: #111;
}

.right-signer-title {
  left: 73.7%;
  top: 91%;
  transform: translateX(-50%);
  font-size: clamp(10px, 1.2vw, 15px);
  color: #222;
  width: 19%;
  white-space: normal;
  line-height: 1.2;
}

/* ------------------ TABLET ------------------ */

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

/* ------------------ MOBILE ------------------ */

@media (max-width: 768px) {
  .app-shell {
    padding: 1rem;
  }

  .page-header__inner {
    padding: 1.25rem;
    border-radius: 22px;
  }

  .page-header__inner h1 {
    font-size: 2.1rem;
  }

  .lede {
    font-size: 0.98rem;
    line-height: 1.45;
  }

  .tool-nav {
    gap: 0.6rem;
  }

  .tool-nav__link {
    width: 100%;
    justify-content: center;
  }

  .card {
    padding: 1rem;
    border-radius: 14px;
  }

  label {
    margin-top: 0.8rem;
  }

  input,
  select,
  button {
    font-size: 16px;
  }

  button {
    width: 100%;
  }

  .preview-frame {
    padding: 0.75rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .certificate-preview {
    min-width: 720px;
  }

  .preview-rank-image {
    height: 70px;
    left: 22%;
    top: 50%;
  }

  .preview-ribbon-image {
    height: 29px;
    left: 79%;
    top: 50%;
  }

  .achievement-number {
    font-size: 24px;
  }

  .achievement-title {
    font-size: 20px;
  }

  .cadet-name {
    font-size: 28px;
  }

  .cadet-rank {
    font-size: 18px;
  }

  .presented-line,
  .unit-line,
  .left-signer-name,
  .right-signer-name {
    font-size: 14px;
  }

  .left-signer-title,
  .right-signer-title {
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding: 0.75rem;
  }

  .page-header__inner {
    padding: 1rem;
    border-radius: 18px;
  }

  .page-header__inner h1 {
    font-size: 1.8rem;
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  .lede {
    font-size: 0.92rem;
  }

  .card {
    padding: 0.9rem;
  }

  .preview-frame {
    padding: 0.5rem;
  }

  .certificate-preview {
    min-width: 640px;
  }

  .preview-rank-image {
    height: 60px;
  }

  .preview-ribbon-image {
    height: 25px;
  }
}

.controls-column {
  display: flex;
  flex-direction: column;
}

.page-footer {
  margin-top: auto; /* pushes it to the bottom */
  padding-top: 1.5rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-soft);
}

.page-footer p {
  margin: 0.25rem 0;
}

.page-footer a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}

.page-footer a:hover {
  text-decoration: underline;
}

.guidance-card {
  margin-bottom: 1.5rem;
}

.section-heading {
  margin-bottom: 1rem;
}

.section-heading h2 {
  margin: 0 0 0.4rem;
}

.section-heading p {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.55;
}

.callout {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  border: 1px solid #e7c27d;
  background: #fff7e6;
}

.callout h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.callout ul {
  margin: 0;
  padding-left: 1.2rem;
}

.callout li + li {
  margin-top: 0.45rem;
}

.callout--warning {
  background: #fff7e6;
  border-color: #e7c27d;
}
