@import url('https://fonts.googleapis.com/css2?family=Suwannaphum:wght@100;300;400;700;900&display=swap');

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

:root {
  --primary: #1a1a2e;
  --accent-blue: #1565c0;
  --accent-red: #c62828;
  --danger: #d32f2f;
  --success: #2e7d32;
  --warning: #f57c00;
  --gray-50: #f9f9f9;
  --gray-100: #f0f0f0;
  --gray-200: #e0e0e0;
  --gray-400: #9e9e9e;
  --gray-600: #666;
  --gray-800: #333;
  --white: #fff;
  --radius: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.1);
}

body {
  font-family: 'Suwannaphum', sans-serif;
  font-size: 15px;
  color: var(--gray-800);
  background: var(--gray-50);
  min-height: 100vh;
}

/* ── HEADER ── */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 32px;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 72px;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.logo-svg {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}

.site-title {
  font-size: 26px;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: .5px;
  text-transform: uppercase;
}

/* ── NAV BAR ── */
.nav-bar {
  background: var(--white);
  border-bottom: 2px solid var(--gray-200);
  padding: 0 32px;
}

.nav-bar-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 44px;
  gap: 24px;
}

.nav-link {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-800);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: border-color .15s, color .15s;
}

.nav-link:hover,
.nav-link.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); }

/* ── MAIN LAYOUT ── */
.page-main {
  max-width: 1100px;
  margin: 32px auto;
  padding: 0 24px;
}

/* ── FORM CARD ── */
.form-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 32px 40px 40px;
  box-shadow: var(--shadow);
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.form-title {
  font-size: 28px;
  font-weight: 400;
  color: var(--gray-800);
  margin-bottom: 28px;
}

.form-divider {
  border: none;
  border-top: 1px solid var(--gray-200);
  margin: 20px 0 24px;
}

/* ── FORM GROUPS ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px 32px;
}

.form-grid.one-col { grid-template-columns: 1fr; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-card { padding: 20px; }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-800);
}

label .required { color: var(--accent-red); margin-left: 2px; }

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: 'Suwannaphum', sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--white);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(21,101,192,.12);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.field-hint {
  font-size: 12px;
  color: var(--gray-600);
  margin-top: 2px;
}

.field-hint strong { color: var(--gray-800); }

/* Date field */
.date-wrapper {
  position: relative;
}

.date-wrapper input[type="date"] {
  padding-right: 40px;
}

.date-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--gray-600);
}

/* Section sub-heading */
.sub-heading {
  font-size: 24px;
  font-weight: 400;
  color: var(--gray-800);
  margin: 32px 0 4px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius);
  font-family: 'Suwannaphum', sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}

.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--primary);
  color: var(--white);
}

.btn-primary:hover { opacity: .88; }

.btn-submit {
  background: #111;
  color: var(--white);
  padding: 12px 28px;
  font-size: 15px;
  border-radius: 6px;
  margin-top: 28px;
}

.btn-submit:hover { background: #333; }

.btn-outline {
  background: transparent;
  color: var(--gray-800);
  border: 1px solid var(--gray-200);
}

.btn-outline:hover { background: var(--gray-100); }

.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { opacity: .85; }

.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover { opacity: .85; }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-icon { padding: 6px 8px; }

/* ── TOAST / ALERTS ── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 280px;
  max-width: 400px;
  padding: 14px 18px;
  will-change: opacity, transform;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 400;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn .25s ease;
}

.toast.success { background: #e8f5e9; border-left: 4px solid var(--success); color: #1b5e20; }
.toast.error   { background: #ffebee; border-left: 4px solid var(--danger);  color: #b71c1c; }
.toast.info    { background: #e3f2fd; border-left: 4px solid var(--accent-blue); color: #0d47a1; }

@keyframes slideIn {
  from { opacity: 0; transform: translate3d(20px, 0, 0); }
  to   { opacity: 1; transform: translate3d(0, 0, 0); }
}

/* ── DASHBOARD STATS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--gray-600);
  margin-top: 6px;
}

.stat-card.blue  .stat-value { color: var(--accent-blue); }
.stat-card.red   .stat-value { color: var(--danger); }
.stat-card.green .stat-value { color: var(--success); }

/* ── TABLE ── */
.table-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
  gap: 12px;
}

.table-toolbar h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input {
  padding: 7px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: 'Suwannaphum', sans-serif;
  font-size: 14px;
  outline: none;
  width: 220px;
}

.search-input:focus { border-color: var(--accent-blue); }

.filter-select {
  padding: 7px 32px 7px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: 'Suwannaphum', sans-serif;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  background: var(--white);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

thead tr {
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
}

th {
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--gray-600);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}

.badge-male   { background: #e3f2fd; color: #1565c0; }
.badge-female { background: #fce4ec; color: #c62828; }
.badge-yes    { background: #ffebee; color: #c62828; }
.badge-no     { background: #e8f5e9; color: #2e7d32; }

.table-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--gray-400);
  font-size: 15px;
}

.table-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--gray-200);
  font-size: 13px;
  color: var(--gray-600);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--white);
  border-radius: 8px;
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  transform: translateY(20px);
  transition: transform .2s;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-200);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--gray-600);
  line-height: 1;
  padding: 4px;
  border-radius: var(--radius);
}

.modal-close:hover { background: var(--gray-100); }

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── CONFIRM DIALOG ── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}

.confirm-overlay.open { opacity: 1; pointer-events: auto; }

.confirm-box {
  background: var(--white);
  border-radius: 8px;
  padding: 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
  text-align: center;
}

.confirm-box p { margin: 8px 0 20px; color: var(--gray-600); }
.confirm-box .confirm-actions { display: flex; gap: 12px; justify-content: center; }

/* ── LOADING ── */
.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  will-change: transform;
}

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

/* ── SHARED SPACING UTILITIES ── */
.modal-grid-mt  { margin-top: 18px; }
.modal-date-field { margin-top: 18px; max-width: 200px; }
.confirm-title  { font-size: 16px; }
.reg-date-field      { margin-top: 24px; max-width: 260px; }
.rx-other-section    { margin-top: 28px; }
.rx-comments-section { margin-top: 24px; }

/* ── PRINT ── */
@media print {
  .site-header, .nav-bar, .btn, .table-toolbar { display: none !important; }
  body { background: white; }
  .table-card { box-shadow: none; border: none; }
}
