:root {
  --bg: #eef3f7;
  --surface: #ffffff;
  --surface-soft: #f8fbfd;
  --ink: #17202a;
  --muted: #64748b;
  --line: #d7e0ea;
  --teal: #0f766e;
  --teal-deep: #0b5d56;
  --blue: #28518f;
  --gold: #b7791f;
  --red: #b42318;
  --shadow: 0 18px 44px rgba(28, 42, 58, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(15, 118, 110, 0.20), transparent 28%),
    radial-gradient(circle at 84% 8%, rgba(183, 121, 31, 0.16), transparent 26%),
    linear-gradient(180deg, #f7fafc 0%, var(--bg) 72%);
  color: var(--ink);
  font-family: Arial, "Noto Sans Thai", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.login-view {
  min-height: calc(100vh - 40px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(840px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  overflow: hidden;
  border: 1px solid rgba(215, 224, 234, 0.9);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand-panel {
  min-height: 330px;
  display: flex;
  flex-direction: column;
  justify-content: end;
  padding: 34px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.92), rgba(40, 81, 143, 0.86)),
    #0f766e;
  color: white;
}

.login-logo {
  width: 118px;
  height: 118px;
  object-fit: contain;
  margin-bottom: auto;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  padding: 10px;
}

.brand-panel .eyebrow,
.brand-panel p {
  color: rgba(255, 255, 255, 0.78);
}

.login-panel {
  display: grid;
  gap: 14px;
  align-content: center;
  padding: 30px;
}

.login-message {
  min-height: 20px;
  color: var(--red);
  font-weight: 700;
}

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

.app-view {
  width: min(1240px, 100%);
  margin: 0 auto;
}

.topbar,
.session-bar,
.app-brand,
.dashboard-head,
.toolbar,
.editor-head,
.editor-actions,
.action-bar,
.band-title,
.tool-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar,
.dashboard-head,
.editor-head,
.band-title {
  justify-content: space-between;
}

.topbar {
  margin-bottom: 18px;
}

.app-brand {
  min-width: 0;
}

.app-logo {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-top: 6px;
  font-size: 32px;
  line-height: 1.1;
}

h2 {
  font-size: 21px;
}

h3 {
  font-size: 16px;
}

p {
  color: var(--muted);
  margin-top: 4px;
}

.eyebrow {
  color: var(--teal-deep);
  font-weight: 800;
  text-transform: uppercase;
}

.session-bar {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.session-chip {
  min-height: 40px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  color: #334155;
}

.dashboard-view,
.editor-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.dashboard-view {
  padding: 18px;
}

.toolbar {
  flex-wrap: wrap;
  margin: 16px 0;
}

.toolbar label {
  width: 220px;
}

label span {
  display: block;
  color: #334155;
  font-weight: 700;
  margin-bottom: 6px;
}

.comorbidity-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.comorbidity-panel > span {
  display: block;
  color: #334155;
  font-weight: 800;
  margin-bottom: 10px;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
}

.check-row label {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.check-row input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.check-row input[name="comorbidity_other"] {
  flex: 1 1 220px;
  min-width: 180px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 9px 11px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(15, 118, 110, 0.15);
  border-color: rgba(15, 118, 110, 0.55);
}

textarea {
  resize: vertical;
}

.dashboard-table {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: #334155;
  background: #f2f6fa;
}

tr:hover td {
  background: #fbfdff;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.status-tag {
  display: inline-block;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: #334155;
}

.status-tag.ready {
  color: var(--teal-deep);
  border-color: #99d8d1;
  background: #eefdfa;
}

.tool-row {
  gap: 7px;
}

.tool-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  cursor: pointer;
}

.tool-button.print {
  color: white;
  background: var(--blue);
  border-color: var(--blue);
}

.tool-button.edit {
  color: var(--teal-deep);
}

.tool-button.archive {
  color: #7c3aed;
  border-color: #ddd6fe;
  background: #f5f3ff;
}

.tool-button.audit {
  color: #28518f;
  border-color: #bfdbfe;
  background: #eff6ff;
  font-weight: 800;
}

.tool-button.delete {
  color: var(--red);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.34);
}

.audit-modal {
  width: min(640px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.audit-list {
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding: 12px 18px 18px;
}

.audit-item {
  display: grid;
  gap: 6px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.audit-item div,
.audit-item time {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
}

.audit-item strong {
  color: var(--ink);
}

.audit-item code {
  display: block;
  overflow-wrap: anywhere;
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
  padding: 8px;
}

.editor-card {
  padding: 18px;
}

.section-band {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.band-title span {
  color: var(--gold);
  font-weight: 800;
}

.module-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 14px;
  background: #ffffff;
  max-width: 100%;
  overflow: hidden;
}

.module-head,
.module-section-head {
  display: flex;
  align-items: end;
  gap: 10px;
}

.module-head {
  flex-wrap: wrap;
}

.module-head label,
.module-head .field-block {
  flex: 1 1 260px;
}

.field-block > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.module-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.module-picker label {
  flex: 0 1 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #243044;
  font-weight: 700;
}

.module-picker input[type="checkbox"] {
  width: 17px;
  min-height: 17px;
  padding: 0;
}

.module-mount {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  max-width: 100%;
}

.module-empty {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: #f8fafc;
}

.module-section {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  max-width: 100%;
  overflow: hidden;
}

.module-card {
  display: grid;
  gap: 10px;
}

.module-card > h4 {
  margin: 2px 0 0;
  color: #0f766e;
  font-size: 15px;
}

.module-section h4 {
  margin: 0 0 10px;
  color: #243044;
  font-size: 14px;
}

.module-section-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.module-section-head h4 {
  margin: 0;
}

.compact-button {
  min-height: 34px;
  padding: 6px 10px;
}

.coronary-list {
  display: grid;
  gap: 10px;
}

.coronary-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 36px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.coronary-row input,
.coronary-row select {
  min-height: 38px;
}

.module-checks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.module-checks label {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: normal;
}

.module-checks input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.module-free-text {
  flex: 1 1 220px;
  min-width: 180px;
}

.module-free-text span {
  margin-bottom: 4px;
}

.module-field-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.referral-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

.module-section-note {
  display: block;
  margin-top: 10px;
}

.module-section-note textarea {
  min-height: 64px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.note-field {
  display: block;
  margin-top: 12px;
}

.summary-action-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.action-bar {
  flex-wrap: wrap;
  margin-top: 16px;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 9px 14px;
  cursor: pointer;
}

.primary-button {
  color: white;
  background: var(--teal);
  border-color: var(--teal);
}

.primary-button:hover {
  background: var(--teal-deep);
}

.secondary-button {
  color: #243044;
  background: #edf2f7;
}

.danger-button {
  color: white;
  background: var(--red);
  border-color: var(--red);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.7);
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.form-message {
  min-width: 120px;
  color: var(--muted);
  text-align: right;
}

.form-message.ok {
  color: var(--teal-deep);
}

.form-message.error {
  color: var(--red);
}

@media (max-width: 900px) {
  .login-card {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    min-height: 230px;
  }

  .topbar,
  .dashboard-head,
  .editor-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .session-bar,
  .editor-actions {
    justify-content: flex-start;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .module-field-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

}

@media (max-width: 620px) {
  .app-shell {
    padding: 12px;
  }

  .dashboard-view,
  .editor-card {
    border-radius: 14px;
    padding: 14px;
  }

  h1 {
    font-size: 27px;
  }

  .toolbar,
  .session-bar,
  .action-bar,
  .summary-action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-action-row .primary-button {
    width: 100%;
  }

  .toolbar label,
  .form-grid,
  .module-field-grid {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .module-head,
  .module-section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .module-head label,
  .module-head .field-block {
    flex: 0 1 auto;
    width: 100%;
  }

  .module-picker label {
    width: 100%;
  }

  .module-head button,
  .module-section-head button {
    width: 100%;
  }

  .module-checks {
    align-items: stretch;
    flex-direction: column;
  }

  .module-checks label {
    width: 100%;
    align-items: flex-start;
  }

  .module-checks input[type="checkbox"] {
    flex: 0 0 auto;
    margin-top: 1px;
  }

  .coronary-row {
    grid-template-columns: 1fr;
  }

  .referral-grid {
    grid-template-columns: 1fr;
  }
}
