:root {
  --primary: #0f9d6f;
  --primary-dark: #0b7a56;
  --primary-darker: #0a5f44;
  --primary-light: #e3f6ee;
  --primary-soft: #c9ecdc;
  --dark: #142621;
  --card: #ffffff;
  --text: #16241f;
  --muted: #5d6e67;
  --border: #dfe9e4;
  --red: #d64545;
  --red-light: #fdecec;
  --orange: #b9760d;
  --orange-light: #fdf1de;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow-sm: 0 2px 10px rgba(13, 36, 28, 0.06);
  --shadow-md: 0 12px 28px rgba(11, 95, 68, 0.14);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, #f7fbf9 0%, #eaf3ee 100%);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
}

:focus-visible {
  outline: 3px solid #7fd4ae;
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 18;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(247, 251, 249, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.app-shell,
.auth-shell,
.confirm-shell {
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.auth-shell,
.confirm-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
}

body.has-bottom-nav .app-shell,
body.has-bottom-nav .confirm-shell {
  padding-bottom: calc(96px + var(--safe-bottom));
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px 20px;
  margin-bottom: 16px;
}

.nested-card {
  margin-bottom: 0;
  padding: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f6fbf8 100%);
}

h1,
h2 {
  margin-top: 0;
  color: var(--dark);
  letter-spacing: -0.01em;
}

h1 {
  font-size: 24px;
  font-weight: 800;
}

h2 {
  font-size: 19px;
  font-weight: 700;
}

.subtitle {
  color: var(--muted);
  line-height: 1.5;
  font-size: 15px;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  font-size: 15px;
  font-weight: 600;
  color: var(--dark);
}

.step-badge {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--primary-dark);
}

.big-input,
.primary-button,
.action-button,
.choice-button,
.secondary-button,
.danger-button,
.logout-button,
.back-button {
  min-height: 58px;
  font-size: 19px;
  border-radius: var(--radius-md);
}

.big-input,
.textarea-input {
  width: 100%;
  border: 1.5px solid var(--border);
  background: #fff;
  padding: 14px 16px;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.big-input--center {
  text-align: center;
  font-size: 32px;
  font-weight: 700;
}

.textarea-input {
  min-height: 120px;
  resize: vertical;
  font-family: inherit;
}

button,
input,
textarea {
  font: inherit;
}

.primary-button,
.action-button,
.choice-button,
.secondary-button,
.danger-button,
.logout-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}

.primary-button,
.action-button {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.choice-button,
.secondary-button {
  background: var(--primary-light);
  color: var(--primary-darker);
  border: 1.5px solid var(--primary-soft);
}

.small-button {
  min-height: 44px;
  font-size: 16px;
}

.danger-button {
  background: #fff;
  color: var(--red);
  border: 1.5px solid #f3c9c9;
}

.logout-button {
  width: 100%;
  background: var(--dark);
  color: #fff;
}

.primary-button:active,
.action-button:active,
.choice-button:active,
.secondary-button:active,
.danger-button:active,
.logout-button:active,
.back-button:active,
.menu-toggle:active {
  transform: scale(0.97);
}

@media (hover: hover) {
  .primary-button:hover,
  .action-button:hover {
    box-shadow: 0 14px 30px rgba(11, 95, 68, 0.2);
  }

  .choice-button:hover,
  .secondary-button:hover {
    background: var(--primary-soft);
  }
}

.action-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.plain-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.dashboard-hero {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}

.dashboard-actions,
.hero-metadata {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill,
.code-pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.pill {
  background: var(--primary-light);
  color: var(--primary-darker);
}

.code-pill {
  background: var(--dark);
  color: #fff;
}

.status-badge.is-active {
  background: var(--primary-light);
  color: var(--primary-darker);
}

.status-badge.is-inactive {
  background: var(--red-light);
  color: var(--red);
}

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

.desktop-table-card {
  padding: 20px;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 14px;
}

.data-table th {
  background: #f2f7f4;
  color: var(--dark);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table tbody tr:nth-child(even) {
  background: #fbfdfc;
}

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

.secondary-button--sm {
  min-height: 40px;
  font-size: 14px;
  padding: 10px 14px;
}

.form-layout {
  display: grid;
  gap: 18px;
}

.desktop-form-grid {
  display: grid;
  gap: 14px;
}

.toolbar-form {
  display: grid;
  gap: 12px;
}

.toolbar-form--filters {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.center-card {
  max-width: 560px;
  margin: 40px auto;
  text-align: center;
}

.text-alert-red {
  color: var(--red);
  font-weight: 700;
}

.text-alert-orange {
  color: var(--orange);
  font-weight: 700;
}

.summary-card {
  background: #fdfefe;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.summary-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.summary-item strong {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 700;
}

.summary-item span {
  font-size: 18px;
  font-weight: 600;
  color: var(--dark);
}

.flash {
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  border-left: 4px solid transparent;
}

.flash-error {
  background: var(--red-light);
  color: var(--red);
  border-left-color: var(--red);
}

.flash-success {
  background: var(--primary-light);
  color: var(--primary-darker);
  border-left-color: var(--primary);
}

.menu-toggle {
  min-width: 48px;
  min-height: 48px;
  border: none;
  background: var(--dark);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.side-menu {
  position: fixed;
  top: 0;
  right: -300px;
  width: 288px;
  max-width: 90vw;
  height: 100vh;
  background: var(--dark);
  color: #fff;
  z-index: 20;
  padding: calc(20px + var(--safe-top)) 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: right 0.22s ease;
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.25);
}

.side-menu.open {
  right: 0;
}

.side-menu a {
  background: rgba(255, 255, 255, 0.06);
  padding: 15px 16px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  transition: background 0.15s ease;
}

.side-menu a:active {
  background: rgba(255, 255, 255, 0.16);
}

.side-menu__header {
  font-size: 21px;
  font-weight: 800;
  margin-bottom: 8px;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 16, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 19;
}

.menu-overlay.open {
  opacity: 1;
  visibility: visible;
}

.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  background: var(--primary-light);
  color: var(--primary-darker);
  font-weight: 700;
  font-size: 16px;
}

.secondary-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 16px;
}

.auth-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  margin: 16px 0 8px;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.google-button {
  min-height: 58px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--dark);
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, background 0.15s ease;
}

.google-button:active {
  transform: scale(0.97);
}

@media (hover: hover) {
  .google-button:hover {
    background: var(--primary-light);
  }
}

.confirm-card {
  text-align: center;
  width: 100%;
}

.confirm-icon {
  font-size: 60px;
  margin-bottom: 10px;
}

.step-badge {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--primary-light);
  margin-bottom: 12px;
}

.readonly-box {
  background: var(--primary-light);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 16px;
  color: var(--primary-darker);
}

.readonly-box strong {
  color: var(--dark);
}

.hidden-fields {
  display: none;
}

.hidden-fields.open {
  display: block;
}

.medicine-card {
  background: linear-gradient(180deg, #ffffff 0%, #f5fbf8 100%);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 17;
  display: flex;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + var(--safe-bottom));
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.bottom-nav__item svg {
  width: 22px;
  height: 22px;
}

.bottom-nav__item.is-active {
  color: var(--primary-dark);
}

.bottom-nav__item:active {
  background: var(--primary-light);
}

@media (min-width: 480px) {
  .app-shell,
  .auth-shell,
  .confirm-shell {
    padding-left: 20px;
    padding-right: 20px;
  }
}

@media (min-width: 720px) {
  .bottom-nav {
    display: none;
  }

  body.has-bottom-nav .app-shell,
  body.has-bottom-nav .confirm-shell {
    padding-bottom: 28px;
  }

  .app-shell--wide {
    width: min(100%, 1200px);
    padding-left: 24px;
    padding-right: 24px;
  }

  .dashboard-hero {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }

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

  .toolbar-form {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .form-layout {
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    align-items: start;
  }

  .side-menu {
    width: 320px;
  }
}

@media (min-width: 1040px) {
  .app-shell--wide {
    width: min(100%, 1320px);
  }

  .data-table {
    min-width: 0;
  }
}
