/* ============================================================
   Design tokens
   Subject: a community trust's merit-scholarship form.
   The physical form it replaces is a bordered ledger document
   with a maroon trust seal, ruled fields, and a marks grid.
   That vocabulary (rule lines, ledger grid, seal-red accent,
   warm paper ground) is carried into the digital version
   rather than reaching for a generic SaaS card look.
   ============================================================ */
:root {
  --paper: #FBF7F0;
  --paper-raised: #FFFFFF;
  --ink: #26201B;
  --ink-soft: #6B5F54;
  --rule: #DCD1C0;
  --maroon: #7A2A2E;
  --maroon-dark: #5C1F23;
  --gold: #B4862F;
  --success: #3F7A57;
  --success-bg: #EAF3ED;
  --error: #B23A3A;
  --error-bg: #FBEDED;
  --focus: #2F6FA8;

  --font-display: "Merriweather", "Noto Serif Gujarati", serif;
  --font-body: "Inter", "Noto Sans Gujarati", sans-serif;

  --radius: 6px;
  --shadow-doc: 0 1px 2px rgba(38, 32, 27, 0.06), 0 8px 24px -12px rgba(38, 32, 27, 0.18);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px);
  background-size: 100% 2.1rem;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

a { color: var(--maroon); }

/* ---------------- Masthead ---------------- */
.masthead {
  background: var(--paper-raised);
  border-bottom: 3px double var(--maroon);
}

.masthead-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 1.4rem;
  text-align: center;
}

.masthead-seal {
  font-size: 0.78rem;
  color: var(--gold);
  letter-spacing: 0.04em;
  margin: 0 0 0.35rem;
}

.masthead-gu {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 4.2vw, 1.85rem);
  color: var(--maroon-dark);
  margin: 0 0 0.25rem;
  line-height: 1.35;
}

.masthead-en {
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 2.6vw, 1.15rem);
  font-style: italic;
  color: var(--ink-soft);
  margin: 0 0 0.6rem;
}

.masthead-address {
  font-size: 0.82rem;
  color: var(--ink-soft);
  max-width: 46rem;
  margin: 0 auto;
}

/* ---------------- Page heading band ---------------- */
.page-heading {
  max-width: 800px;
  margin: 1.75rem auto 0;
  padding: 0 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-heading h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0;
  color: var(--ink);
}

.page-heading .year-pill {
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--maroon-dark);
  background: #F3E6C8;
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-size: 0.95rem;
  white-space: nowrap;
}

/* ---------------- Document card ---------------- */
.doc {
  max-width: 800px;
  margin: 1.25rem auto 3rem;
  padding: 0 1.5rem;
}

.doc-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-doc);
  padding: 1.75rem 1.5rem 2rem;
}

@media (min-width: 640px) {
  .doc-card { padding: 2.25rem 2.5rem 2.5rem; }
}

.section {
  margin-bottom: 1.9rem;
}

.section:last-child { margin-bottom: 0; }

.section-title {
  font-family: var(--font-display);
  font-size: 1.02rem;
  color: var(--maroon-dark);
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.section-title .gu {
  font-size: 0.92em;
  color: var(--ink-soft);
  font-weight: 400;
}

/* ---------------- Form elements ---------------- */
.field {
  margin-bottom: 1.15rem;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

.field label .gu {
  font-weight: 400;
  color: var(--ink-soft);
  margin-left: 0.35rem;
  font-size: 0.9em;
}

.req { color: var(--maroon); }

.field input[type="text"],
.field input[type="tel"],
.field textarea,
.field select {
  width: 100%;
  padding: 0.62rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.98rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field textarea { resize: vertical; min-height: 4.2rem; }

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(47, 111, 168, 0.15);
}

.field input:invalid:not(:placeholder-shown) { }

.field .hint {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: 0.3rem;
}

.field .error-msg {
  font-size: 0.82rem;
  color: var(--error);
  margin-top: 0.35rem;
  display: none;
}

.field.has-error input,
.field.has-error textarea,
.field.has-error select {
  border-color: var(--error);
  background: var(--error-bg);
}

.field.has-error .error-msg { display: block; }

.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 1.25rem;
}

@media (min-width: 560px) {
  .two-col { grid-template-columns: 1fr 1fr; }
}

/* ---------------- Subjects grid (echoes the ledger table) ---------------- */
.subjects-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 4px;
}

table.subjects {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
  font-size: 0.92rem;
}

table.subjects thead th {
  background: #F4EEE2;
  color: var(--maroon-dark);
  font-weight: 600;
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

table.subjects tbody td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}

table.subjects tbody tr:last-child td { border-bottom: none; }

table.subjects input {
  width: 100%;
  padding: 0.42rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper);
  font-size: 0.92rem;
}

table.subjects input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 2px rgba(47, 111, 168, 0.15);
}

.subjects .col-remove { width: 2.4rem; text-align: center; }

.btn-remove-row {
  background: none;
  border: none;
  color: var(--error);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
}

.btn-remove-row:hover { color: var(--maroon-dark); }

.subjects-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.7rem;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.btn-add-row {
  background: none;
  border: 1px dashed var(--gold);
  color: var(--maroon-dark);
  border-radius: 4px;
  padding: 0.4rem 0.85rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-add-row:hover { background: #FAF3E4; }

.btn-add-row:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.totals-strip {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.totals-strip strong { color: var(--ink); font-size: 1rem; }

/* ---------------- File upload ---------------- */
.upload-box {
  border: 1.5px dashed var(--rule);
  border-radius: 6px;
  padding: 1.5rem 1rem;
  text-align: center;
  background: var(--paper);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-box:hover,
.upload-box.dragover {
  border-color: var(--maroon);
  background: #FBF1F0;
}

.upload-box input[type="file"] { display: none; }

.upload-box .upload-icon {
  font-size: 1.6rem;
  color: var(--maroon);
  margin-bottom: 0.4rem;
}

.upload-box .upload-text {
  font-size: 0.92rem;
  color: var(--ink);
  font-weight: 600;
}

.upload-box .upload-hint {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 0.2rem;
}

.file-list {
  list-style: none;
  margin: 0.9rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}

.file-list .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-list .file-remove {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

/* ---------------- Declaration + submit ---------------- */
.declaration {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.9rem 1rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.checkbox-field {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin-top: 0.8rem;
}

.checkbox-field input { margin-top: 0.2rem; }

.checkbox-field label { font-size: 0.88rem; color: var(--ink); font-weight: 500; }

.submit-row {
  margin-top: 1.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn-primary {
  background: var(--maroon);
  color: #fff;
  border: none;
  padding: 0.8rem 1.9rem;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn-primary:hover { background: var(--maroon-dark); }
.btn-primary:active { transform: translateY(1px); }

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: none;
  border: 1px solid var(--rule);
  color: var(--ink);
  padding: 0.75rem 1.4rem;
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-secondary:hover { border-color: var(--ink-soft); }

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  display: none;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.submitting .spinner { display: inline-block; }

/* ---------------- Banners ---------------- */
.banner {
  max-width: 800px;
  margin: 1.5rem auto 0;
  padding: 0 1.5rem;
}

.banner-box {
  border-radius: 4px;
  padding: 0.85rem 1.1rem;
  font-size: 0.92rem;
  border: 1px solid;
}

.banner-box.success {
  background: var(--success-bg);
  border-color: var(--success);
  color: #295C3F;
}

.banner-box.error {
  background: var(--error-bg);
  border-color: var(--error);
  color: #7A2828;
}

/* ---------------- Toast notifications ---------------- */
.toast-stack {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: calc(100% - 2rem);
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--paper-raised);
  border-left: 4px solid var(--error);
  border-radius: 6px;
  box-shadow: 0 10px 30px -8px rgba(38, 32, 27, 0.35), 0 2px 8px rgba(38, 32, 27, 0.12);
  padding: 0.85rem 0.9rem 0.85rem 1rem;
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  animation: toast-in 0.28s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.toast.toast-out {
  animation: toast-out 0.2s ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-10px) scale(0.98); }
}

.toast-icon {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--error-bg);
  color: var(--error);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 0.05rem;
}

.toast-body { flex: 1; min-width: 0; }

.toast-title {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.toast-list {
  margin: 0;
  padding-left: 1.05rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  display: grid;
  gap: 0.15rem;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
  border-radius: 4px;
}

.toast-close:hover { color: var(--ink); background: var(--paper); }

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* ---------------- Footer ---------------- */
.site-footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-soft);
  padding: 0 1.5rem 2.5rem;
}

.site-footer a { color: var(--ink-soft); text-decoration: underline; }

/* ============================================================
   Admin area
   ============================================================ */
.admin-shell {
  min-height: 100vh;
  background: var(--paper);
}

.admin-topbar {
  background: var(--maroon);
  color: #fff;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.admin-topbar .brand {
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.admin-topbar .brand small {
  display: block;
  font-family: var(--font-body);
  font-size: 0.72rem;
  opacity: 0.8;
  font-weight: 400;
}

.admin-topbar a.logout {
  color: #F3E6C8;
  font-size: 0.85rem;
  text-decoration: none;
  border: 1px solid rgba(255,255,255,0.35);
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
}

.admin-topbar a.logout:hover { background: rgba(255,255,255,0.1); }

.admin-body {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
}

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-doc);
  padding: 2.25rem 2rem;
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin: 0 0 0.2rem;
  color: var(--maroon-dark);
  text-align: center;
}

.login-card p.sub {
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0 0 1.5rem;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1rem 1.1rem;
}

.stat-card .num {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--maroon-dark);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.toolbar input[type="search"] {
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  min-width: 220px;
  font-size: 0.9rem;
}

.data-table-wrap {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow-x: auto;
}

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

table.data-table th {
  text-align: left;
  padding: 0.7rem 0.85rem;
  background: #F4EEE2;
  color: var(--maroon-dark);
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

table.data-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

table.data-table tbody tr:hover { background: #FBF7EF; }

.pct-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.82rem;
}

.pct-badge.high { background: var(--success-bg); color: #295C3F; }
.pct-badge.mid { background: #FBF1DA; color: #8A6415; }
.pct-badge.low { background: var(--error-bg); color: #7A2828; }

.detail-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1.75rem;
  max-width: 760px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem 1.5rem;
  margin-bottom: 1.5rem;
}

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

.detail-grid .k {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  margin-bottom: 0.15rem;
}

.detail-grid .v { font-size: 0.96rem; }

.attach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.8rem;
  margin-top: 0.5rem;
}

.attach-grid a {
  display: block;
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.75rem;
  text-align: center;
}

.attach-grid img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
  background: var(--paper);
}

.attach-grid .pdf-tile {
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  font-size: 1.6rem;
  color: var(--maroon);
}

.attach-grid .fname {
  display: block;
  padding: 0.3rem 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
