:root {
  --primary: #1a7f7a;
  --primary-dark: #115753;
  --primary-light: #e8f5f4;
  --accent: #d4a574;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg: #fafbfc;
  --white: #ffffff;
  --error: #dc2626;
  --success: #16a34a;
}

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

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--bg) 0%, #f1f5f9 100%);
  color: var(--text);
  line-height: 1.5;
  padding: 1rem 0.5rem;
  min-height: 100vh;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 15px 50px rgba(26, 127, 122, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  padding: 2rem 2rem;
  position: relative;
  overflow: hidden;
}

.header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h60v60H0z' fill='none'/%3E%3Cpath d='M30 0v60M0 30h60' stroke='%23ffffff' stroke-width='0.5' opacity='0.1'/%3E%3C/svg%3E");
  opacity: 0.3;
}

.header-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.logo {
  height: 50px;
  animation: fadeIn 0.8s ease-out 0.2s both;
  object-fit: contain;
  max-width: 300px;
  display: block;
}

.header-text {
  flex: 1;
  color: var(--white);
  animation: fadeIn 0.8s ease-out 0.4s both;
}

.header-text h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.header-text p {
  font-size: 0.875rem;
  opacity: 0.9;
  font-weight: 400;
}

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

/* Form Content */
.form-content {
  padding: 1.75rem 2rem;
}

.section {
  margin-bottom: 2rem;
  animation: fadeIn 0.6s ease-out both;
}

.section:nth-child(1) { animation-delay: 0.1s; }
.section:nth-child(2) { animation-delay: 0.2s; }
.section:nth-child(3) { animation-delay: 0.3s; }
.section:nth-child(4) { animation-delay: 0.4s; }

.section-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary-light);
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--accent);
}

/* Form Groups */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.form-group {
  position: relative;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.35rem;
  transition: color 0.2s;
}

.form-group label .required {
  color: var(--error);
  margin-left: 2px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.7rem 0.875rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.3s ease;
  background: var(--white);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

.form-group input.error {
  border-color: var(--error);
}

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

/* Prescriber Cards */
.prescriber-card {
  background: linear-gradient(135deg, var(--primary-light) 0%, #ffffff 100%);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  position: relative;
  transition: all 0.3s ease;
  animation: slideIn 0.4s ease-out;
}

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

.prescriber-card:hover {
  box-shadow: 0 8px 24px rgba(26, 127, 122, 0.12);
  transform: translateY(-2px);
}

.prescriber-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.prescriber-number {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--primary-dark);
}

/* Signature Canvas */
.signature-wrapper {
  margin-top: 0.5rem;
}

.signature-canvas {
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: linear-gradient(135deg, #fafbfc 0%, #ffffff 100%);
  cursor: crosshair;
  touch-action: none;
  transition: all 0.3s ease;
  display: block;
  width: 100%;
  height: 160px;
}

.signature-canvas:hover {
  border-color: var(--primary);
  background: var(--white);
}

.signature-canvas.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

.signature-info {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.signature-info::before {
  content: '✍️';
  font-size: 1.1rem;
}

/* Buttons */
.btn {
  padding: 0.7rem 1.75rem;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  box-shadow: 0 4px 12px rgba(26, 127, 122, 0.2);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(26, 127, 122, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--white);
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-secondary:hover {
  background: var(--primary-light);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 2px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg);
  border-color: var(--text-muted);
  color: var(--text);
}

.btn-remove {
  background: transparent;
  color: var(--error);
  border: 2px solid var(--border);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.btn-remove:hover {
  background: #fef2f2;
  border-color: var(--error);
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.875rem;
  margin-top: 1.25rem;
}

.button-group.center {
  justify-content: center;
}

/* Footer */
.footer {
  background: var(--bg);
  padding: 1.5rem 2rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.footer-address {
  margin-bottom: 0.5rem;
}

.footer-contact {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.footer-contact a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-contact a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 0.5rem 0.25rem;
  }

  .header {
    padding: 1.5rem 1.25rem;
  }

  .header-content {
    flex-direction: column;
    text-align: center;
  }

  .header-text h1 {
    font-size: 1.35rem;
  }

  .logo {
    height: 45px;
  }

  .form-content {
    padding: 1.25rem;
  }

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

  .prescriber-card {
    padding: 1.25rem;
  }

  .button-group {
    flex-direction: column;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }
}

@media print {
  body {
    background: white;
    padding: 0;
  }

  .container {
    box-shadow: none;
    border-radius: 0;
    max-width: 100%;
  }

  .btn, .btn-remove {
    display: none !important;
  }

  .header {
    background: var(--primary);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    page-break-after: avoid;
  }

  .section {
    page-break-inside: avoid;
  }

  .form-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
    gap: 1rem !important;
  }

  .prescriber-card {
    page-break-inside: avoid;
    background: var(--primary-light);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .signature-canvas {
    border: 2px solid var(--border);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .signature-info {
    display: none;
  }

  .footer {
    background: var(--bg);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Maintain colors in print */
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* Loading Animation */
.loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--white);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
/* SOP mobile overrides */
img {
  max-width: 100%;
  height: auto;
}

@media (max-width: 980px) {
  body {
    padding: 0.5rem !important;
  }

  .packet {
    padding: 0.5rem 0 !important;
  }

  .page {
    width: 100% !important;
    min-height: auto !important;
    margin: 0 0 0.8rem !important;
    padding: 1rem !important;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1) !important;
  }

  .container {
    max-width: 100% !important;
    border-radius: 12px !important;
  }
}

@media (max-width: 560px) {
  .page {
    padding: 0.78rem !important;
  }

  .header-text h1,
  .title,
  .dosage-title {
    font-size: 1rem !important;
  }
}

@media print {
  .page {
    box-shadow: none !important;
  }
}
