@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Libre+Baskerville:wght@400;700&display=swap');

/* ===== CSS Variables ===== */
:root {
  --blue: #0a5ba8;
  --deep: #06366c;
  --sky: #e9f3fb;
  --ink: #19324a;
  --line: #dbe6ef;
  --muted: #617489;
  --green: #187247;
  --green-bg: #e8f5ee;
  --red: #a73b3b;
  --red-bg: #fff0f0;
  --radius: 10px;
  --shadow: 0 6px 20px rgba(22, 76, 120, 0.06);
  --shadow-lg: 0 16px 48px rgba(22, 76, 120, 0.18);
  --transition: 0.2s ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: #f4f8fb;
  color: var(--ink);
  font: 13px/1.55 'DM Sans', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ===== Top Bar ===== */
.topbar {
  min-height: 96px;
  background: #fff;
  border-bottom: 3px solid var(--blue);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px max(4vw, 24px);
  gap: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
}
.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand img {
  width: 210px;
  height: 86px;
  object-fit: contain;
  object-position: left;
}
.brand span {
  display: block;
  color: var(--blue);
  font-size: 17px;
  font-weight: 600;
}
.brand strong {
  display: block;
  color: var(--deep);
  font: 700 17px 'Libre Baskerville', serif;
}
.tag {
  font-size: 10px;
  letter-spacing: 1.4px;
  font-weight: 700;
  color: #68819a;
  text-align: right;
}

/* ===== Main ===== */
main {
  max-width: 1400px;
  padding: 26px max(4vw, 24px);
  margin: auto;
}

/* ===== Hero ===== */
.hero {
  max-width: 720px;
  margin-bottom: 20px;
}
.eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.3px;
  color: var(--blue);
  margin: 0 0 5px;
  text-transform: uppercase;
}
.hero h1 {
  font: 700 clamp(22px, 3.2vw, 34px)/1.15 'Libre Baskerville', serif;
  margin: 0 0 10px;
  color: var(--deep);
}
.hero > p:last-child {
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
}

/* ===== Alert ===== */
.alert {
  max-width: 900px;
  padding: 11px 15px;
  margin: 0 0 18px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  animation: slideDown 0.3s ease;
}
.alert.success { background: var(--green-bg); color: var(--green); border: 1px solid #bde2cb; }
.alert.error { background: var(--red-bg); color: var(--red); border: 1px solid #efc4c4; }
.alert-icon { font-size: 16px; flex-shrink: 0; }
.alert-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 0 4px;
}
.alert-close:hover { opacity: 1; }
.btn-print-last {
  background: var(--green);
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 6px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-print-last:hover { opacity: 0.85; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Layout Grid ===== */
.layout {
  display: grid;
  grid-template-columns: minmax(290px, 0.78fr) minmax(0, 1.7fr);
  gap: 20px;
}

/* ===== Card ===== */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-card { padding: 20px; }
.register-card { padding: 20px; min-width: 0; }

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.section-title h2 {
  font: 700 16px 'Libre Baskerville', serif;
  color: var(--deep);
  margin: 0;
  line-height: 1.35;
}
.counter {
  background: var(--sky);
  color: var(--blue);
  padding: 4px 9px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

/* ===== Form ===== */
label {
  display: block;
  font-weight: 600;
  color: #36516b;
  margin: 0 0 12px;
  font-size: 12px;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #bfd0df;
  border-radius: 7px;
  padding: 8px 10px;
  margin-top: 4px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(10, 91, 168, 0.12);
}
textarea { resize: vertical; }
small {
  display: block;
  font-size: 10px;
  line-height: 1.4;
  font-weight: 400;
  color: var(--muted);
  margin-top: 3px;
}

/* ===== Buttons ===== */
.primary, .secondary {
  border: none;
  font: inherit;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 7px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  font-size: 13px;
}
.primary {
  background: var(--blue);
  color: #fff;
}
.primary:hover { background: var(--deep); transform: translateY(-1px); }
.primary:active { transform: translateY(0); }
.secondary {
  background: #f0f4f8;
  color: var(--ink);
  border: 1px solid var(--line);
}
.secondary:hover { background: #e2e9f0; }

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.form-actions .primary { flex: 1; }
.form-actions .secondary { flex: 0 0 auto; }

/* ===== Required field marker ===== */
.req {
  color: var(--red);
  font-weight: 700;
  margin-left: 2px;
}

/* ===== Field error state ===== */
.field-error {
  border-color: var(--red) !important;
  box-shadow: 0 0 0 3px rgba(167, 59, 59, 0.14) !important;
  animation: fieldShake 0.35s ease;
}
@keyframes fieldShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* ===== Toast notification ===== */
.toast-wrap {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 340px;
  max-width: calc(100vw - 28px);
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px 14px;
  border-left: 4px solid var(--red);
  animation: toastIn 0.3s cubic-bezier(0.21, 1.02, 0.73, 1);
}
.toast.success { border-left-color: var(--green); }
.toast-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--red);
}
.toast.success .toast-icon { background: var(--green); }
.toast-body { flex: 1; min-width: 0; }
.toast-title {
  font-weight: 700;
  color: var(--deep);
  font-size: 13px;
  margin: 0 0 2px;
}
.toast-msg {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
}
.toast-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  opacity: 0.6;
  padding: 0;
  line-height: 1;
}
.toast-close:hover { opacity: 1; }
.toast.hide { animation: toastOut 0.25s ease forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(40px); }
}

/* ===== Export buttons ===== */
.export { display: flex; gap: 7px; }
.export a {
  border-radius: 7px;
  padding: 7px 11px;
  text-decoration: none;
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  transition: background var(--transition);
}
.export a:hover { background: var(--deep); }
.export .outline {
  background: #fff;
  color: var(--blue);
  border: 1px solid var(--blue);
}
.export .outline:hover { background: var(--sky); }

/* ===== Tools bar ===== */
.tools {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}
.tools input {
  max-width: 320px;
  margin: 0;
}
.tools span { color: var(--muted); font-size: 11px; text-align: right; }
.tools strong { color: var(--deep); font-family: monospace; }

/* ===== Table ===== */
.table-wrap {
  overflow: auto;
  max-height: 560px;
  border: 1px solid var(--line);
  border-radius: 7px;
}
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th {
  position: sticky;
  top: 0;
  background: var(--sky);
  color: var(--deep);
  font-size: 10px;
  letter-spacing: .5px;
  text-transform: uppercase;
  text-align: left;
  padding: 9px 8px;
  z-index: 2;
}
td {
  padding: 8px;
  border-top: 1px solid var(--line);
  vertical-align: top;
  line-height: 1.45;
  font-size: 12px;
}
.col-no {
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  width: 36px;
}
.col-date { white-space: nowrap; color: var(--muted); }
.col-subject { min-width: 220px; }
.col-actions { white-space: nowrap; width: 90px; }
.th-actions { text-align: center; width: 90px; }
code {
  white-space: nowrap;
  font-size: 11px;
  color: var(--blue);
  font-weight: 700;
  background: var(--sky);
  padding: 2px 5px;
  border-radius: 4px;
}
tbody tr:hover { background: #f8fbfe; }

/* ===== Icon Buttons ===== */
.btn-icon {
  border: none;
  background: none;
  font-size: 14px;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
  transition: background var(--transition);
  line-height: 1;
}
.btn-icon:hover { background: var(--sky); }
.btn-delete:hover { background: var(--red-bg); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}
.empty-state p:first-child { font-size: 17px; margin: 0 0 6px; }
.empty-state p:last-child { font-size: 12px; margin: 0; }

/* ===== Modal Overlay ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 54, 108, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 460px;
  max-height: 90vh;
  overflow: auto;
  animation: scaleIn 0.25s ease;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 0;
}
.modal-header h3 {
  margin: 0;
  font: 700 16px 'Libre Baskerville', serif;
  color: var(--deep);
}
.modal-close {
  border: none;
  background: none;
  font-size: 21px;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  line-height: 1;
}
.modal-close:hover { color: var(--red); }
.modal-body { padding: 14px 20px; }
.modal-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 12px;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 20px 16px;
}
.modal-body label {
  margin-bottom: 10px;
}

/* ===== Preview Table ===== */
.preview-table {
  width: 100%;
  border-collapse: collapse;
  min-width: auto;
}
.preview-table th {
  position: static;
  background: none;
  text-align: left;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  width: 110px;
  vertical-align: top;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--line);
}
.preview-table td {
  padding: 8px 10px;
  font-weight: 600;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 22px;
  color: #6b8193;
  border-top: 1px solid var(--line);
  font-size: 11px;
  background: #fff;
}

/* ===== Receipt (Print) ===== */
.receipt-print {
  display: none;
}

/* ===== PRINT STYLES ===== */
@media print {
  /* Hide everything except receipt */
  body > *:not(.receipt-print) { display: none !important; }
  .receipt-print {
    display: block !important;
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 9999;
  }
  .receipt-inner {
    max-width: 600px;
    margin: 30px auto;
    padding: 30px;
    font-family: 'DM Sans', Arial, sans-serif;
    color: #000;
  }
  .receipt-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 10px;
  }
  .receipt-logo {
    width: 130px;
    height: 70px;
    object-fit: contain;
  }
  .receipt-header h2 {
    font: 700 24px 'Libre Baskerville', serif;
    margin: 0 0 4px;
    color: #06366c;
  }
  .receipt-header h3 {
    font-size: 24px;
    margin: 0;
    color: #0a5ba8;
    font-weight: 600;
    font-family: 'DM Sans', sans-serif;
  }
  .receipt-title {
    text-align: center;
    font: 700 18px 'Libre Baskerville', serif;
    margin: 20px 0;
    color: #06366c;
    letter-spacing: 1px;
  }
  .receipt-table {
    width: 100%;
    border-collapse: collapse;
    min-width: auto;
  }
  .receipt-table th {
    text-align: left;
    padding: 10px 14px;
    background: #e9f3fb;
    color: #06366c;
    font-size: 12px;
    font-weight: 700;
    width: 160px;
    border: 1px solid #bfd0df;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: static;
  }
  .receipt-table td {
    padding: 10px 14px;
    border: 1px solid #bfd0df;
    font-size: 13px;
    font-weight: 500;
  }
  .receipt-footer {
    text-align: center;
    font-size: 11px;
    color: #888;
    margin-top: 16px;
  }
  hr {
    border: none;
    border-top: 2px solid #0a5ba8;
    margin: 12px 0;
  }
}

/* ===== Responsive ===== */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .brand img { width: 150px; height: 60px; }
  .brand span { font-size: 15px; }
  .brand strong { font-size: 18px; }
  .tag { display: none; }
}

@media (max-width: 540px) {
  main { padding: 20px 14px; }
  .topbar { min-height: 80px; padding: 10px 14px; }
  .brand { gap: 8px; }
  .brand strong { font-size: 14px; }
  .brand span { font-size: 11px; }
  .brand img { width: 84px; height: 38px; }
  .form-card, .register-card { padding: 16px; }
  .section-title, .tools { flex-direction: column; align-items: stretch; }
  .tools span { text-align: left; }
  .export { width: 100%; }
  .export a { flex: 1; text-align: center; }
  .form-actions { flex-direction: column; }
  .form-actions .primary, .form-actions .secondary { width: 100%; }
  .modal { width: 95%; max-width: none; }
  .toast-wrap { left: 14px; right: 14px; top: 14px; width: auto; }
}

/* ===== Auth Pages ===== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.auth-container {
  width: 100%;
  max-width: 400px;
}
.auth-card {
  background: #fff;
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
}
.auth-header {
  text-align: center;
  margin-bottom: 24px;
}
.auth-logo {
  height: 50px;
  object-fit: contain;
  margin-bottom: 12px;
}
.auth-header h1 {
  font: 700 20px 'Libre Baskerville', serif;
  color: var(--deep);
  margin: 0 0 4px;
}
.auth-header p {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}
.auth-links {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  font-size: 12px;
  font-weight: 600;
}
.auth-links a {
  color: var(--blue);
  text-decoration: none;
}
.auth-links a:hover {
  text-decoration: underline;
}
.auth-footer {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  margin-top: 16px;
}
.auth-divider {
  border: none;
  border-top: 1px dashed var(--line);
  margin: 20px 0;
}
.auth-hint {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 12px;
  text-align: center;
}
.alert-info {
  background: var(--sky);
  color: var(--deep);
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 12px;
  margin-bottom: 16px;
  border: 1px solid #bfd0df;
}

/* ===== User Menu (Topbar) ===== */
.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--deep);
}
.btn-admin {
  background: #fff;
  color: var(--blue);
  border: 1px solid var(--blue);
  padding: 5px 10px;
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.2s;
}
.btn-admin:hover {
  background: var(--sky);
}
.btn-logout {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #efc4c4;
  padding: 5px 10px;
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.2s;
}
.btn-logout:hover {
  background: var(--red);
  color: #fff;
}

/* ===== Print Signatures ===== */
.receipt-signatures {
  display: flex;
  justify-content: space-between;
  margin-top: 40px;
  margin-bottom: 20px;
  text-align: center;
}
.sig-box {
  width: 40%;
}
.sig-box p {
  margin: 0;
  font-size: 13px;
}
.sig-line {
  margin-top: 50px;
  border-bottom: 1px solid #333;
  margin-bottom: 8px;
}
