:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #66717d;
  --line: #d8e0e7;
  --paper: #ffffff;
  --page: #eef7f8;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --blue: #2563eb;
  --coral: #f9734f;
  --sun: #f7b731;
  --violet: #7c3aed;
  --green: #16a34a;
  --danger: #b42318;
  --soft: #e7f4f2;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, #eef7f8 0%, #f7fbff 38%, #fff8ef 100%);
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(243, 247, 248, 0.74), rgba(243, 247, 248, 0.92)),
    url("https://images.unsplash.com/photo-1576091160550-2173dba999ef?auto=format&fit=crop&w=1800&q=80") center / cover;
}

.login-panel {
  width: min(900px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 32px;
  align-items: center;
  padding: 36px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(216, 224, 231, 0.9);
  border-radius: 8px;
  box-shadow: 0 22px 55px rgba(23, 33, 43, 0.14);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.muted {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.login-form,
.section-band,
.records-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

label {
  display: grid;
  gap: 7px;
  color: #33404c;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c7d2da;
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.primary-button,
.ghost-button,
.small-button,
.text-button {
  min-height: 40px;
  border-radius: 6px;
  padding: 0 16px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #1d9a8f);
  color: #fff;
  box-shadow: 0 9px 20px rgba(15, 118, 110, 0.2);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button,
.small-button {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.ghost-button:hover,
.small-button:hover {
  border-color: #9fcfc8;
  background: #f1fbf9;
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
}

.text-button {
  background: transparent;
  color: var(--muted);
  padding: 0 8px;
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.workspace {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 16px 24px;
  background:
    linear-gradient(100deg, rgba(255, 255, 255, 0.96), rgba(241, 251, 249, 0.96)),
    linear-gradient(90deg, rgba(15, 118, 110, 0.18), rgba(249, 115, 79, 0.1));
  border-bottom: 1px solid rgba(159, 207, 200, 0.75);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  font-size: 24px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-tabs {
  position: sticky;
  top: 73px;
  z-index: 7;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(216, 224, 231, 0.8);
  backdrop-filter: blur(12px);
}

.quick-tab {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 16px;
  color: #26323c;
  background: #fff;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(23, 33, 43, 0.08);
}

.quick-tab:nth-child(1) {
  border-color: rgba(37, 99, 235, 0.25);
}

.quick-tab:nth-child(2) {
  border-color: rgba(249, 115, 79, 0.28);
}

.quick-tab:nth-child(3) {
  border-color: rgba(15, 118, 110, 0.3);
}

.quick-tab:nth-child(4) {
  border-color: rgba(247, 183, 49, 0.42);
}

.quick-tab:nth-child(5) {
  border-color: rgba(124, 58, 237, 0.24);
}

.quick-tab.active,
.quick-tab:hover {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border-color: transparent;
}

.layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 24px 30px;
}

.records-panel {
  align-self: start;
  position: sticky;
  top: 146px;
  padding: 16px;
  box-shadow: 0 14px 34px rgba(23, 33, 43, 0.07);
}

.panel-heading,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading span {
  min-width: 30px;
  text-align: center;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.search-box {
  margin: 14px 0;
}

.records-list,
.drug-list,
.snippet-list {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.records-list {
  max-height: 260px;
}

.drug-list {
  max-height: 230px;
}

.snippet-list {
  max-height: 180px;
}

.library-panel {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.logo-panel {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.logo-preview {
  display: grid;
  place-items: center;
  min-height: 76px;
  border: 1px dashed #b9c7cf;
  border-radius: 8px;
  background: #f8fbfc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
}

.logo-preview img {
  display: block;
  max-width: 100%;
  max-height: 82px;
  object-fit: contain;
}

.file-button {
  min-height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.password-panel {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.password-panel .panel-heading {
  margin-bottom: 4px;
}

.password-message {
  min-height: 17px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.password-message.error {
  color: var(--danger);
}

.password-message.success {
  color: var(--accent-dark);
}

.library-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 14px;
}

.record-item,
.drug-item,
.snippet-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 10px;
}

.drug-item,
.snippet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.drug-item button,
.snippet-item button {
  flex: 0 0 auto;
}

.snippet-text {
  min-width: 0;
  line-height: 1.35;
  font-size: 12px;
  font-weight: 700;
}

.snippet-actions {
  display: flex;
  gap: 5px;
}

.insert-row {
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 900;
}

.record-item strong,
.record-item span {
  display: block;
}

.record-item strong {
  font-size: 13px;
}

.record-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.emr-form {
  display: grid;
  gap: 16px;
}

.section-band {
  padding: 18px;
  position: relative;
  overflow: hidden;
  scroll-margin-top: 150px;
  box-shadow: 0 14px 34px rgba(23, 33, 43, 0.06);
}

.section-band::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--accent);
}

.patient-section::before {
  background: var(--blue);
}

.clinical-section::before {
  background: var(--coral);
}

.prescription-section::before {
  background: var(--accent);
}

.tests-section::before {
  background: var(--sun);
}

.followup-section::before {
  background: var(--violet);
}

.patient-section {
  background: linear-gradient(180deg, #ffffff 0%, #f4f8ff 100%);
  border-color: rgba(37, 99, 235, 0.18);
}

.clinical-section {
  background: linear-gradient(180deg, #ffffff 0%, #fff7f3 100%);
  border-color: rgba(249, 115, 79, 0.2);
}

.tests-section {
  background: linear-gradient(180deg, #ffffff 0%, #fffaf0 100%);
  border-color: rgba(247, 183, 49, 0.26);
}

.followup-section {
  background: linear-gradient(180deg, #ffffff 0%, #f7f4ff 100%);
  border-color: rgba(124, 58, 237, 0.18);
}

.prescription-section {
  border-color: #9fcfc8;
  background: linear-gradient(180deg, #ffffff 0%, #f4fbfa 72%, #eef7fb 100%);
  box-shadow: 0 14px 34px rgba(15, 118, 110, 0.09);
}

.section-band h2 {
  margin-bottom: 16px;
}

.section-title h2 {
  margin-bottom: 0;
}

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

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

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

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

.rx-line {
  height: 2px;
  margin: 10px 0 16px;
  background: linear-gradient(90deg, var(--accent), #7aa7c7, transparent);
}

.medicine-card-list {
  display: grid;
  gap: 14px;
}

.medicine-card {
  border: 1px solid #c9e7e2;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 13px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(23, 33, 43, 0.05);
}

.medicine-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.rx-symbol {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  height: 30px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 16px;
  font-weight: 900;
}

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

.medicine-grid label:nth-child(1),
.medicine-grid label:nth-child(2),
.medicine-notes {
  grid-column: span 2;
}

.medicine-grid [data-med="drug"],
.medicine-grid [data-med="generic"],
.medicine-grid [data-med="dose"] {
  color: #0f3f3b;
  font-size: 15px;
  font-weight: 800;
}

.medicine-tools {
  display: none;
}

.field-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.remove-row {
  width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--danger);
  font-weight: 800;
}

.print-sheet {
  display: none;
}

@media (max-width: 980px) {
  .login-panel,
  .layout,
  .grid.two,
  .grid.three,
  .grid.four,
  .medicine-grid {
    grid-template-columns: 1fr;
  }

  .medicine-grid label:nth-child(1),
  .medicine-grid label:nth-child(2),
  .medicine-notes {
    grid-column: auto;
  }

  .records-panel {
    position: static;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .quick-tabs {
    top: 133px;
  }

  .section-band {
    scroll-margin-top: 210px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: #fff;
  }

  .login-screen,
  .workspace {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .print-sheet {
    display: block;
    color: #111;
    font-size: 12px;
  }

  .print-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 2px solid #111;
    padding-bottom: 10px;
    margin-bottom: 12px;
  }

  .print-brand {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .print-logo {
    width: 58px;
    height: 58px;
    object-fit: contain;
  }

  .print-header h1 {
    font-size: 22px;
  }

  .print-meta {
    text-align: right;
    line-height: 1.5;
  }

  .print-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px 14px;
    margin-bottom: 12px;
  }

  .print-block {
    border-top: 1px solid #999;
    padding-top: 8px;
    margin-top: 9px;
    break-inside: avoid;
  }

  .print-block h2 {
    font-size: 13px;
    margin: 0 0 6px;
  }

  .print-block p {
    white-space: pre-wrap;
    margin: 0;
    line-height: 1.45;
  }

  .print-treatment {
    margin-top: 12px;
    break-inside: avoid;
  }

  .treatment-title {
    color: #333;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }

  .rx-heading {
    margin-top: 2px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 28px;
    font-weight: 800;
  }

  .rx-rule {
    height: 2px;
    margin: 2px 0 10px;
    background: #111;
  }

  .print-medicine-list {
    display: grid;
    gap: 7px;
  }

  .print-medicine-item {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 8px;
    padding: 7px 8px;
    border: 1px solid #777;
    border-radius: 5px;
    break-inside: avoid;
  }

  .print-med-number {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    background: #111;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
  }

  .print-med-title {
    display: flex;
    align-items: baseline;
    gap: 7px;
    flex-wrap: wrap;
  }

  .print-med-title strong {
    font-size: 15px;
  }

  .print-med-title span {
    color: #333;
    font-size: 12px;
  }

  .print-med-details {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 12px;
    margin-top: 3px;
    line-height: 1.35;
  }

  .print-med-details span {
    display: inline-block;
  }

  .print-tests-row {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    margin-top: 10px;
    padding: 7px 8px;
    border: 1px solid #777;
    border-radius: 5px;
    break-inside: avoid;
  }

  .print-tests-row h2 {
    font-size: 12px;
    margin: 0;
  }

  .print-tests-row p {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.4;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
  }

  .print-table th {
    background: #eef6f4;
    font-size: 12px;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #444;
    padding: 5px;
    text-align: left;
    vertical-align: top;
  }

  .print-table td:nth-child(1),
  .print-table td:nth-child(2) {
    font-size: 14px;
    font-weight: 800;
  }

  .print-footer {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-top: 24px;
    padding-top: 12px;
    border-top: 1px solid #999;
  }

  .print-signature {
    display: grid;
    gap: 4px;
    text-align: right;
  }

  .print-signature span {
    font-size: 14px;
    font-weight: 900;
  }

  .print-signature strong {
    font-size: 12px;
  }
}
