:root {
  --bg: #f6f1e8;
  --ink: #1b2631;
  --ink-soft: #425466;
  --primary: #0f766e;
  --primary-2: #14b8a6;
  --accent: #f97316;
  --card: #fffdf8;
  --line: #e8dcc7;
  --danger: #dc2626;
  --shadow: 0 12px 28px rgba(23, 42, 59, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Outfit", sans-serif;
  font-size: 13px;
  background: radial-gradient(circle at 0% 0%, #fff3dc 0, transparent 46%),
              radial-gradient(circle at 100% 100%, #d5f5f0 0, transparent 52%),
              var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow: hidden;
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(2px);
  z-index: -1;
  opacity: 0.16;
}

.shape-1 {
  width: 280px;
  height: 280px;
  top: -60px;
  right: -70px;
  background: #f8c28e;
}

.shape-2 {
  width: 360px;
  height: 360px;
  bottom: -120px;
  left: -90px;
  background: #7ce7d9;
}

.shape-3 {
  width: 180px;
  height: 180px;
  top: 40%;
  right: 4%;
  background: #ffd8b5;
}

.page {
  width: 100%;
  height: 100dvh;
  margin: 0;
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-view {
  width: 100%;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 14px;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid #dbcbb3;
  border-radius: 12px;
  background: #fffdf9;
  box-shadow: var(--shadow);
  padding: 14px;
}

.login-card h1 {
  margin: 8px 0 4px;
  font-size: 1.12rem;
}

.login-card p {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.login-form {
  display: grid;
  gap: 8px;
}

.login-btn {
  margin-top: 4px;
}

.login-error {
  min-height: 16px;
  margin: 0;
  font-size: 0.7rem;
  color: #b91c1c;
}

.hero {
  background: linear-gradient(135deg, #0f766e, #0ea5a1);
  border-radius: 12px;
  padding: 10px 14px;
  color: #fff;
  box-shadow: var(--shadow);
}

.hero h1 {
  margin: 4px 0 2px;
  font: 600 clamp(1rem, 1.8vw, 1.22rem) "Outfit", sans-serif;
  letter-spacing: 0.2px;
}

.hero p {
  margin: 0;
  font-size: 0.76rem;
  color: #defcf9;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.hero-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fde68a;
}

.panel {
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid rgba(232, 220, 199, 0.68);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  padding: 10px;
  box-shadow: var(--shadow);
  flex: 1;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 8px;
}

.panel > * {
  min-height: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-left h2 {
  margin: 0;
}

h2,
h3 {
  margin: 0 0 6px;
}

h2 {
  font-size: 0.98rem;
  font-weight: 600;
}

h3 {
  font-size: 0.84rem;
  color: var(--ink-soft);
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  background: #f4faf9;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid #d6ece7;
}

.grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
  min-height: 168px;
  align-items: stretch;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  min-height: 0;
  overflow: hidden;
}

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

.patient-card {
  display: flex;
  flex-direction: column;
}

.patient-card .form-grid {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  max-height: 140px;
  overflow: auto;
  padding-right: 2px;
}

.search-card {
  display: flex;
  flex-direction: column;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink-soft);
  font-size: 0.74rem;
}

.patient-card .form-grid > label {
  grid-column: span 6;
}

.patient-card .form-grid > label.span-2 {
  grid-column: span 2;
}

.patient-card .form-grid > label.span-3 {
  grid-column: span 3;
}

.patient-card .form-grid > label.span-4 {
  grid-column: span 4;
}

.patient-card .form-grid > label.span-5 {
  grid-column: span 5;
}

.patient-card .form-grid > label.span-12 {
  grid-column: 1 / -1;
}

input,
select {
  width: 100%;
  border: 1px solid #d8ccb8;
  border-radius: 7px;
  padding: 6px 8px;
  font: inherit;
  color: var(--ink);
  background: #fffdf9;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary-2);
  box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.18);
}

.results {
  margin-top: 4px;
  max-height: 132px;
  overflow: auto;
  display: grid;
  gap: 6px;
}

.result-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid #e7dbca;
  background: #fffdfa;
}

.result-meta {
  margin-top: 4px;
  font-size: 0.7rem;
  color: #5e6a74;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 8px;
  padding: 6px 10px;
  font: 600 0.76rem "Outfit", sans-serif;
  cursor: pointer;
}

.btn.add {
  background: #0f766e;
  color: #fff;
}

.btn.add:hover {
  background: #0c5f58;
}

.selected-card {
  display: flex;
  flex-direction: column;
}

.table-wrap {
  overflow: auto;
  flex: 1;
  min-height: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid #eee1d0;
  padding: 6px;
  text-align: left;
  font-size: 0.7rem;
  vertical-align: middle;
  white-space: nowrap;
}

th:nth-child(2),
td:nth-child(2) {
  white-space: normal;
  width: 30%;
  min-width: 180px;
}

th {
  font-size: 0.66rem;
  letter-spacing: 0.2px;
  color: #566676;
  text-transform: uppercase;
  font-weight: 600;
}

.qty-input {
  width: 52px;
  padding: 3px 5px;
}

.remove {
  color: var(--danger);
  background: #fff1f1;
  border: 1px solid #ffd1d1;
  border-radius: 6px;
  padding: 4px 6px;
  cursor: pointer;
  font-size: 0.66rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.totals {
  display: grid;
  gap: 4px;
}

.totals div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
  min-height: 24px;
  border-radius: 7px;
  background: #fff9f1;
  border: 1px solid #efdeca;
  font-size: 0.72rem;
}

.totals strong {
  color: #0b4f4b;
}

.actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.edit-tag {
  margin-right: auto;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid #f3cfa6;
  background: #fff6eb;
  color: #8a4b08;
  font-size: 0.68rem;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.history-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(21, 33, 44, 0.35);
  z-index: 50;
}

.history-panel {
  position: fixed;
  top: 12px;
  right: 12px;
  width: min(680px, calc(100vw - 24px));
  height: calc(100dvh - 24px);
  border: 1px solid #dbcbb3;
  border-radius: 12px;
  background: #fffdf9;
  box-shadow: var(--shadow);
  z-index: 60;
  padding: 10px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
}

.settings-panel {
  width: min(420px, calc(100vw - 24px));
  height: auto;
  max-height: calc(100dvh - 24px);
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-head-actions {
  display: flex;
  gap: 6px;
}

.history-table-wrap {
  overflow: auto;
  min-height: 0;
}

.settings-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
}

.history-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn.tiny {
  padding: 3px 7px;
  font-size: 0.64rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.62rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.status-badge.unpaid {
  color: #9a3412;
  background: #fff7ed;
  border-color: #fed7aa;
}

.status-badge.partial {
  color: #854d0e;
  background: #fefce8;
  border-color: #fde68a;
}

.status-badge.paid {
  color: #065f46;
  background: #ecfdf5;
  border-color: #86efac;
}

.toast-root {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 8px;
  z-index: 120;
  width: min(360px, calc(100vw - 28px));
}

.toast {
  border-radius: 10px;
  border: 1px solid #d6e8ff;
  background: #f8fbff;
  color: #0f2235;
  padding: 9px 10px;
  box-shadow: var(--shadow);
  font-size: 0.72rem;
  line-height: 1.35;
  animation: toast-in 0.16s ease-out;
}

.toast.success {
  border-color: #9ae6b4;
  background: #f0fff4;
  color: #14532d;
}

.toast.error {
  border-color: #fecaca;
  background: #fff1f2;
  color: #7f1d1d;
}

.toast.warning {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.btn.loading {
  opacity: 0.78;
  cursor: wait;
}

.btn.primary {
  background: linear-gradient(135deg, #f97316, #fb923c);
  color: #fff;
}

.btn.ghost {
  background: #f3faf9;
  color: #185c57;
  border: 1px solid #cfe9e5;
}

.reveal {
  animation: reveal 0.3s ease-out both;
}

.hide-prices .price-col,
.hide-prices [data-amount="price"] {
  display: none;
}

.hide-lab .lab-col,
.hide-lab [data-amount="lab"] {
  display: none;
}

.hide-prices .totals [data-total-kind="price"] {
  display: none;
}

.hide-lab .totals [data-total-kind="lab"] {
  display: none;
}

body:not(.hide-prices):not(.hide-lab) table {
  min-width: 980px;
}

body.hide-prices:not(.hide-lab) table,
body.hide-lab:not(.hide-prices) table {
  min-width: 760px;
}

body.hide-prices.hide-lab table {
  min-width: 520px;
}

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

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .page {
    height: auto;
    min-height: 100vh;
  }

  .panel {
    overflow: auto;
    display: flex;
    flex-direction: column;
  }

  .grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .patient-card .form-grid,
  .results,
  .table-wrap {
    max-height: unset;
  }

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

  .patient-card .form-grid > label,
  .patient-card .form-grid > label.span-2,
  .patient-card .form-grid > label.span-3,
  .patient-card .form-grid > label.span-4,
  .patient-card .form-grid > label.span-5 {
    grid-column: span 1;
  }

  .patient-card .form-grid > label.span-12 {
    grid-column: 1 / -1;
  }
}
