:root {
  --blue: #0d47a1;
  --blue2: #1565c0;
  --bg: #eef3f8;
  --card: #fff;
  --border: #cfd8dc;
  --text: #1a1a1a;
  --muted: #546e7a;
  --touch: 48px;
  --font: system-ui, 'Segoe UI', 'Noto Sans Devanagari', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  padding-bottom: 88px;
}

.hdr {
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: #fff;
  padding: 16px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 2px 8px rgba(13, 71, 161, 0.25);
}

.hdr h1 {
  margin: 0;
  font-size: 1.25rem;
}

.hdr p {
  margin: 6px 0 0;
  opacity: 0.92;
  font-size: 0.9rem;
}

.hdr-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
}

.hdr-row > div {
  flex: 1;
}

.btn-back {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

.hdr-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px;
}

.msg {
  display: none;
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-weight: 600;
}

.msg.show.ok {
  display: block;
  background: #e8f5e9;
  color: #1b5e20;
  white-space: pre-line;
  line-height: 1.45;
  font-size: 15px;
}

.msg.show.err {
  display: block;
  background: #ffebee;
  color: #b71c1c;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--blue2);
  border-bottom: 2px solid #e3f2fd;
  padding-bottom: 8px;
}

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

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

.full {
  grid-column: 1 / -1;
}

.lbl {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.lbl.req::after {
  content: ' *';
  color: #c62828;
}

input,
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  min-height: var(--touch);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}

select {
  appearance: auto;
  -webkit-appearance: menulist;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue2);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.2);
  background: #fff;
}

/* Load par laal border NAHI — sirf Save ke baad */
#form.was-validated input:invalid,
#form.was-validated select:invalid,
#form.was-validated textarea:invalid {
  border-color: #e57373;
}

.other-box {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px dashed #90caf9;
}

.other-box[hidden] {
  display: none !important;
}

.actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.actions button {
  flex: 1;
  min-height: var(--touch);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
  border: 2px solid var(--blue2);
}

.btn-save {
  background: var(--blue2);
  color: #fff;
}

.btn-reset {
  background: #fff;
  color: var(--blue2);
}

/* Home */
.home {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.home-card {
  background: var(--card);
  border-radius: 16px;
  max-width: 400px;
  width: 100%;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(13, 71, 161, 0.12);
  text-align: center;
}

.home-banner {
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: #fff;
  padding: 28px 16px;
}

.home-banner h1 {
  margin: 0;
  font-size: 1.1rem;
}

.home-body {
  padding: 24px 20px;
}

.btn-main {
  display: block;
  width: 100%;
  padding: 16px;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--blue2), var(--blue));
  border: none;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
}

.btn-main + .btn-main {
  margin-top: 12px;
}

.btn-secondary {
  background: #fff;
  color: var(--blue);
  border: 2px solid var(--blue);
}

.login-box {
  margin-top: 16px;
  text-align: left;
}

.login-box[hidden] {
  display: none !important;
}

/* Student list */
.wrap-wide {
  max-width: 1100px;
}

.list-toolbar-row {
  display: grid;
  gap: 12px;
}

@media (min-width: 640px) {
  .list-toolbar-row {
    grid-template-columns: 1.4fr 1fr auto;
    align-items: end;
  }
}

.list-count-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.list-count {
  font-weight: 700;
  color: var(--blue2);
  font-size: 14px;
  white-space: nowrap;
}

.btn-refresh {
  min-height: 40px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  border: 2px solid var(--blue2);
  background: #fff;
  color: var(--blue2);
  cursor: pointer;
}

.list-card {
  padding: 0;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.students-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 820px;
}

.students-table th,
.students-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #e8eef3;
  vertical-align: top;
}

.students-table th {
  background: #e3f2fd;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  white-space: nowrap;
  padding: 0;
}

.students-table th.col-num,
.students-table td.col-num {
  width: 44px;
  text-align: center;
  color: var(--muted);
}

.students-table th.col-num {
  padding: 10px 8px;
}

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

.th-sort::after {
  content: '↕';
  opacity: 0.35;
  font-size: 11px;
}

.th-sort.is-asc::after {
  content: '▲';
  opacity: 1;
}

.th-sort.is-desc::after {
  content: '▼';
  opacity: 1;
}

.th-sort:hover {
  background: rgba(21, 101, 192, 0.08);
}

.students-table tbody tr:nth-child(even) {
  background: #f7fafc;
}

.students-table tbody tr.row-click {
  cursor: pointer;
}

.students-table tbody tr.row-click:hover {
  background: #eef5ff;
}

.students-table tbody tr.row-click.is-open {
  background: #e3f2fd;
}

.students-table tbody tr.row-click:focus {
  outline: 2px solid var(--blue2);
  outline-offset: -2px;
}

.students-table .col-name {
  font-weight: 600;
  min-width: 140px;
}

.list-empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px !important;
}

.list-hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.row-detail > td {
  padding: 0 !important;
  background: #f3f7fb;
  border-bottom: 2px solid #90caf9;
}

.inline-detail {
  padding: 14px 14px 18px;
}

.inline-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #d7e3ef;
}

.inline-detail-head strong {
  display: block;
  font-size: 1.05rem;
  color: var(--blue);
}

.inline-detail-sub {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.doc-id-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 14px;
  padding: 10px 12px;
  background: #eef5ff;
  border: 1px solid #c5daf5;
  border-radius: 10px;
}

.doc-id-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.doc-id-copy {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--blue);
}

.doc-id-copy code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  word-break: break-all;
}

.doc-id-hint {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.doc-id-copy:hover .doc-id-hint {
  color: var(--blue2);
}

.doc-id-copy.is-copied .doc-id-hint {
  color: #1b5e20;
}

.inline-detail-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.inline-detail-close,
.btn-edit-inline,
.btn-save-inline,
.btn-cancel-inline {
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.inline-detail-close,
.btn-cancel-inline {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--blue2);
}

.btn-edit-inline {
  border: 2px solid var(--blue2);
  background: #fff;
  color: var(--blue2);
}

.btn-save-inline {
  border: 2px solid var(--blue2);
  background: var(--blue2);
  color: #fff;
}

.btn-save-inline:disabled,
.btn-cancel-inline:disabled {
  opacity: 0.6;
  cursor: wait;
}

.edit-form .detail-edit-item {
  background: #fff;
}

.edit-form .detail-edit-item .lbl {
  margin-bottom: 4px;
}

.edit-form input,
.edit-form select {
  min-height: 42px;
  font-size: 15px;
}

.detail-section {
  margin-bottom: 14px;
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--blue2);
  border-bottom: 2px solid #e3f2fd;
  padding-bottom: 6px;
}

.detail-grid {
  display: grid;
  gap: 8px;
  margin: 0;
}

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

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

.detail-item {
  background: #fff;
  border: 1px solid #e8eef3;
  border-radius: 8px;
  padding: 8px 10px;
}

.detail-item dt {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 0 0 4px;
}

.detail-item dd {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}


.access-denied {
  text-align: center;
  padding: 28px 16px;
}

.access-denied h2 {
  margin: 0 0 8px;
  color: #b71c1c;
  border: 0;
}

.access-denied p {
  margin: 0;
  color: var(--muted);
}


.btn-refresh.is-active {
  background: var(--blue2);
  color: #fff;
}

.btn-delete-inline {
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid #c62828;
  background: #fff;
  color: #c62828;
}

.btn-delete-inline:disabled {
  opacity: 0.6;
  cursor: wait;
}

.compare-card[hidden],
.list-card[hidden] {
  display: none !important;
}

.compare-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.compare-head h2 {
  margin: 0;
  font-size: 15px;
  color: var(--blue2);
}

.compare-summary {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.compare-group {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px dashed #cfd8dc;
}

.compare-group:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

.compare-group-title {
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 10px;
  font-size: 14px;
}

.compare-grid {
  display: grid;
  gap: 12px;
}

@media (min-width: 800px) {
  .compare-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  .compare-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.compare-item {
  background: #f7fafc;
  border: 1px solid #d7e3ef;
  border-radius: 12px;
  padding: 12px;
}

.compare-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.compare-item-head strong {
  display: block;
  color: var(--blue);
  font-size: 14px;
}

.compare-docid {
  width: 100%;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #eef5ff;
  border-radius: 8px;
}

.compare-fields {
  display: grid;
  gap: 6px;
  margin: 0;
}

.compare-field {
  background: #fff;
  border: 1px solid #e8eef3;
  border-radius: 8px;
  padding: 6px 8px;
}

.compare-field.is-diff {
  background: #fff8e1;
  border-color: #ffcc80;
}

.compare-field dt {
  margin: 0 0 2px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}

.compare-field dd {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  word-break: break-word;
}
