:root {
  --ink: #202122;
  --muted: #54595d;
  --line: #a2a9b1;
  --line-soft: #eaecf0;
  --paper: #ffffff;
  --paper-warm: #f8f9fa;
  --accent: #1f6f5f;
  --accent-dark: #155347;
  --accent-pale: #e8f3f0;
  --warning: #8a5a00;
  --warning-bg: #fff7df;
  --success: #26734d;
  --sidebar-width: 236px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

[hidden] {
  display: none !important;
}

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

button,
select {
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  padding: 28px 18px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(rgba(21, 83, 71, .9), rgba(21, 83, 71, .96)),
    linear-gradient(135deg, #1f6f5f, #0f3f36);
}

.login-card {
  width: min(100%, 430px);
  padding: clamp(28px, 6vw, 46px);
  background: var(--paper);
  border-top: 5px solid var(--accent);
  box-shadow: 0 20px 55px rgba(0, 0, 0, .25);
}

.login-brand {
  width: 58px;
  height: 58px;
  margin-bottom: 24px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--accent);
  border-radius: 50% 50% 50% 14%;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 35px;
  font-weight: 700;
}

.login-card h1 {
  margin: 5px 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 7vw, 38px);
  font-weight: 500;
  line-height: 1.08;
}

.login-intro {
  margin: 0 0 24px;
  color: var(--muted);
}

.login-field {
  margin-top: 15px;
  display: grid;
  gap: 6px;
}

.login-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.login-field input {
  width: 100%;
  padding: 11px 12px;
}

.login-submit {
  width: 100%;
  margin-top: 22px;
}

.login-submit:disabled {
  cursor: wait;
  opacity: .65;
}

.login-error {
  min-height: 22px;
  margin: 10px 0 0;
  color: #b32424;
  font-size: 13px;
  text-align: center;
}

.login-local-note {
  margin: 14px 0 0;
  padding-top: 14px;
  color: var(--muted);
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  text-align: center;
}

.site-header {
  min-height: 82px;
  padding: 13px clamp(18px, 4vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--accent);
  border-radius: 50% 50% 50% 12%;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 29px;
  font-weight: 700;
}

.brand strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(20px, 2vw, 27px);
  line-height: 1.1;
}

.brand small {
  color: var(--muted);
}

.anniversary {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--accent-dark);
}

.anniversary span {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 38px;
  font-weight: 700;
  line-height: 1;
}

.anniversary p {
  margin: 0;
  padding-left: 9px;
  border-left: 1px solid var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1.25;
  text-transform: uppercase;
}

.logout-button {
  margin-left: 12px;
  white-space: nowrap;
}

.privacy-banner {
  padding: 8px clamp(18px, 4vw, 56px);
  color: #604200;
  background: var(--warning-bg);
  border-bottom: 1px solid #e6c75e;
  font-size: 13px;
}

.app-shell {
  max-width: 1500px;
  min-height: calc(100vh - 119px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: calc(100vh - 119px);
  padding: 34px 24px;
  border-right: 1px solid var(--line-soft);
  background: var(--paper-warm);
}

.sidebar-heading h2,
.section-heading h2,
.patient-heading h2 {
  margin: 2px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

.sidebar-heading h2 {
  font-size: 20px;
}

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

.month-nav {
  margin-top: 22px;
  display: grid;
}

.month-link {
  width: 100%;
  padding: 8px 4px 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #3366cc;
  background: transparent;
  border: 0;
  border-left: 3px solid transparent;
  text-align: left;
}

.month-link:hover {
  text-decoration: underline;
}

.month-link.is-active {
  color: var(--ink);
  background: var(--accent-pale);
  border-left-color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.month-link span:last-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.sidebar-note {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.sidebar-note span {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
}

.sidebar-note p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 42px clamp(24px, 5vw, 70px) 70px;
}

.intro {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  padding-bottom: 27px;
  border-bottom: 1px solid var(--line);
}

.intro h1 {
  max-width: 760px;
  margin: 5px 0 9px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 4vw, 48px);
  font-weight: 500;
  letter-spacing: -.025em;
  line-height: 1.05;
}

.intro p:not(.eyebrow) {
  max-width: 700px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.intro-date {
  min-width: 155px;
  align-self: end;
  text-align: right;
}

.intro-date span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.intro-date strong {
  color: var(--accent-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 27px;
  font-weight: 500;
}

.template-section,
.patient-section {
  padding-top: 35px;
}

.template-section {
  max-width: 960px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 25px;
}

.section-heading h2 {
  font-size: 27px;
}

.template-picker {
  display: grid;
  gap: 5px;
}

.template-picker span,
.message-editor > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input,
textarea {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 2px;
}

select {
  min-width: 240px;
  padding: 8px 34px 8px 10px;
}

select:focus,
input:focus,
textarea:focus {
  outline: 2px solid rgba(31, 111, 95, .25);
  border-color: var(--accent);
}

.message-editor {
  margin-top: 17px;
  display: grid;
  gap: 6px;
}

textarea {
  width: 100%;
  min-height: 132px;
  padding: 13px 14px;
  resize: vertical;
  line-height: 1.55;
}

.editor-footer {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

.editor-footer p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

code {
  padding: 2px 4px;
  color: var(--accent-dark);
  background: var(--accent-pale);
}

.button-row,
.action-row {
  display: flex;
  gap: 8px;
}

.button {
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-weight: 700;
}

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

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

.button-quiet {
  color: var(--ink);
  background: var(--paper);
}

.button-quiet:hover {
  background: var(--paper-warm);
}

.save-status {
  min-height: 20px;
  margin-top: 4px;
  color: var(--success);
  font-size: 12px;
  text-align: right;
}

.preview-box {
  margin-top: 8px;
  padding: 10px 13px;
  background: var(--paper-warm);
  border-left: 3px solid var(--accent);
}

.preview-box summary {
  color: #3366cc;
  cursor: pointer;
  font-weight: 700;
}

.preview-box p {
  margin: 11px 0 2px;
  white-space: pre-wrap;
}

.patient-section {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.patient-heading {
  align-items: center;
}

.month-stats {
  display: flex;
  align-items: stretch;
}

.month-stats div {
  min-width: 93px;
  padding: 3px 14px;
  border-left: 1px solid var(--line-soft);
}

.month-stats strong,
.month-stats span {
  display: block;
}

.month-stats strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 500;
}

.month-stats span {
  color: var(--muted);
  font-size: 11px;
}

.toolbar {
  margin-top: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.search-field {
  flex: 1;
  max-width: 440px;
}

.search-field input {
  width: 100%;
  padding: 9px 11px;
}

.filter-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}

.filter-tab {
  padding: 8px 11px;
  color: #3366cc;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
}

.filter-tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  padding: 10px 12px;
  color: var(--muted);
  background: var(--paper-warm);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  letter-spacing: .04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #f8fbfa;
}

.patient-name {
  min-width: 210px;
  font-weight: 700;
  text-transform: capitalize;
}

.phone-cell {
  white-space: nowrap;
}

.phone-note {
  display: block;
  color: var(--warning);
  font-size: 11px;
}

.status {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}

.status-pending {
  color: #664900;
  background: #fff3cd;
}

.status-contacted {
  color: #145a3b;
  background: #dff3e9;
}

.whatsapp-button {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
  white-space: nowrap;
}

.undo-button {
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  font-size: 12px;
  font-weight: 400;
  text-decoration: underline;
}

.empty-state {
  padding: 45px 20px;
  text-align: center;
}

.empty-state p {
  margin: 3px 0 0;
  color: var(--muted);
}

.result-count {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: 330px;
  padding: 11px 15px;
  color: white;
  background: var(--ink);
  border-radius: 2px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    min-height: 0;
    padding: 18px 24px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-heading,
  .sidebar-note {
    display: none;
  }

  .month-nav {
    margin: 0;
    display: flex;
    gap: 4px;
    overflow-x: auto;
  }

  .month-link {
    min-width: 92px;
    justify-content: center;
    gap: 7px;
    border-left: 0;
    border-bottom: 3px solid transparent;
  }

  .month-link.is-active {
    border-bottom-color: var(--accent);
  }

  .workspace {
    padding-top: 30px;
  }

  .patient-heading {
    display: block;
  }

  .month-stats {
    margin-top: 18px;
  }

  .month-stats div:first-child {
    padding-left: 0;
    border-left: 0;
  }
}

@media (max-width: 680px) {
  .site-header {
    min-height: 70px;
    padding: 11px 16px;
  }

  .brand small,
  .anniversary p {
    display: none;
  }

  .logout-button {
    min-height: 32px;
    margin-left: 2px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .anniversary span {
    font-size: 31px;
  }

  .privacy-banner {
    padding-inline: 16px;
  }

  .sidebar {
    padding-inline: 12px;
  }

  .workspace {
    padding: 25px 16px 50px;
  }

  .intro {
    display: block;
  }

  .intro-date {
    margin-top: 16px;
    text-align: left;
  }

  .section-heading,
  .editor-footer,
  .toolbar {
    display: block;
  }

  .template-picker,
  .search-field {
    max-width: none;
    margin-top: 15px;
  }

  select {
    width: 100%;
  }

  .button-row {
    margin-top: 12px;
    justify-content: flex-end;
  }

  .month-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    border-top: 1px solid var(--line-soft);
  }

  .month-stats div,
  .month-stats div:first-child {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line-soft);
    border-left: 0;
  }

  .filter-tabs {
    margin-top: 12px;
    overflow-x: auto;
  }

  .table-wrap {
    border-top: 0;
    overflow: visible;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tbody tr {
    position: relative;
    padding: 14px 0;
    border-top: 1px solid var(--line);
  }

  td {
    padding: 3px 0;
    border: 0;
  }

  td:last-child {
    margin-top: 9px;
  }

  .patient-name {
    padding-right: 90px;
  }

  .status-cell {
    position: absolute;
    top: 14px;
    right: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
