:root {
  color-scheme: light;
  --bg: #fff8db;
  --surface: #fffef8;
  --surface-2: #fff0b8;
  --line: #e6d996;
  --line-strong: #c7b85b;
  --text: #263118;
  --muted: #6e7244;
  --blue: #2f8a3c;
  --blue-2: #e3f7cf;
  --teal: #2f8a3c;
  --mint: #e3f7cf;
  --red: #c92d1f;
  --red-2: #ffe2d8;
  --amber: #c77a00;
  --amber-2: #ffeaa1;
  --green: #2f8a3c;
  --green-2: #e3f7cf;
  --sun: #ffd84a;
  --sprout: #2f8a3c;
  --fruit: #c92d1f;
  --shadow: 0 12px 30px rgba(79, 88, 28, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.is-hidden {
  display: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(33, 61, 31, 0.92);
}

.login-card {
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-logo {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  margin: 0 auto 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #b6b6b6;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 850;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #213d1f;
  color: #ffffff;
}

.brand {
  display: block;
}

.brand-logo {
  display: block;
  width: 100%;
  max-width: 212px;
  height: auto;
  border: 1px solid rgba(255, 216, 74, 0.3);
  border-radius: 8px;
  background: #b6b6b6;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  word-break: keep-all;
}

.brand p {
  margin: 3px 0 0;
  color: #f7edb6;
  font-size: 12px;
  font-weight: 700;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item,
.ghost-btn,
.primary-btn,
.danger-btn,
.mini-btn,
.tab-btn {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
}

.nav-item {
  padding: 0 12px;
  background: transparent;
  color: #f6f1c9;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: #3d642f;
  color: #ffffff;
}

.role-box {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 216, 74, 0.24);
}

.role-box label {
  color: #f7edb6;
  font-size: 12px;
  font-weight: 800;
}

.role-box select {
  width: 100%;
  height: 40px;
  border: 1px solid #5c7f3f;
  border-radius: 8px;
  background: #294b25;
  color: #fff;
  padding: 0 10px;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

#crumb {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

#pageTitle {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

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

.status-pill,
.badge,
.state-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-pill {
  padding: 0 10px;
  background: var(--mint);
  color: var(--teal);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

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

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

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

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

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h3 {
  margin: 0;
  font-size: 18px;
}

.panel-body {
  padding: 16px;
}

.metric {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.metric strong {
  font-size: 28px;
  line-height: 1;
}

.metric.is-alert strong {
  color: var(--red);
}

.metric.is-warn strong {
  color: var(--amber);
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

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

.row-title {
  display: block;
  font-weight: 900;
}

.row-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.list {
  display: grid;
  gap: 8px;
}

.item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.client-profile {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.client-photo {
  display: grid;
  width: 96px;
  min-height: 116px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--sprout);
  font-size: 34px;
  font-weight: 900;
  place-items: center;
}

.client-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.upload-box strong {
  font-size: 14px;
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.file-chip {
  display: inline-flex;
  max-width: 100%;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--mint);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
}

.file-chip span {
  overflow: hidden;
  max-width: 210px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip small {
  color: var(--teal);
  font-size: 11px;
  white-space: nowrap;
}

.pipe {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(9, minmax(120px, 1fr));
  overflow-x: auto;
  padding-bottom: 4px;
}

.pipe-col {
  min-height: 110px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.pipe-col h4 {
  display: flex;
  margin: 0 0 8px;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  padding: 0 8px;
  background: var(--surface-2);
  color: var(--muted);
}

.state-badge {
  padding: 0 9px;
  background: var(--blue-2);
  color: var(--blue);
}

.state-badge.warn {
  background: var(--amber-2);
  color: var(--amber);
}

.state-badge.danger {
  background: var(--red-2);
  color: var(--red);
}

.state-badge.ok {
  background: var(--green-2);
  color: var(--green);
}

form {
  display: grid;
  gap: 12px;
}

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

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

.field {
  display: grid;
  gap: 6px;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: 0;
  padding: 0 10px;
}

textarea {
  min-height: 92px;
  padding: 10px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 138, 60, 0.16);
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.symptom-box {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffbea;
}

.symptom-box > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

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

.panel-head .actions {
  align-items: center;
  justify-content: flex-end;
}

.panel-head .actions select {
  width: auto;
  min-width: 180px;
}

.doc-button-row {
  display: flex;
  min-width: 220px;
  flex-wrap: wrap;
  gap: 6px;
}

.primary-btn {
  padding: 0 14px;
  background: var(--blue);
  color: #fff;
}

.ghost-btn,
.mini-btn,
.tab-btn {
  padding: 0 12px;
  border-color: var(--line-strong);
  background: #fff;
  color: var(--text);
}

.danger-btn {
  padding: 0 14px;
  background: var(--red);
  color: #fff;
}

.mini-btn {
  min-height: 30px;
  font-size: 12px;
}

.danger-mini {
  border-color: var(--red-2);
  color: var(--red);
}

.tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.tab-btn.is-active {
  border-color: var(--blue);
  background: var(--blue-2);
  color: var(--blue);
}

.calendar-head {
  align-items: flex-start;
}

.calendar-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.calendar-controls input {
  width: 150px;
  min-height: 30px;
}

.calendar-board {
  display: grid;
  gap: 6px;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.calendar-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.calendar-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.month-board {
  grid-template-columns: repeat(7, minmax(96px, 1fr));
}

.week-board {
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  overflow-x: auto;
}

.calendar-weekday {
  padding: 0 8px 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.calendar-cell {
  display: grid;
  min-height: 118px;
  align-content: start;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.calendar-cell.is-drop-target {
  border-color: var(--sprout);
  background: var(--mint);
  box-shadow: inset 0 0 0 2px rgba(47, 138, 60, 0.22);
}

.calendar-cell.is-wide {
  min-height: 280px;
}

.calendar-cell.is-muted {
  background: #fffbea;
  color: #a59a54;
}

.calendar-cell.is-closed {
  background: #f8f4df;
}

.calendar-cell.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(47, 138, 60, 0.16);
}

.calendar-cell.is-today .calendar-date {
  background: var(--blue);
  color: #fff;
}

.calendar-date {
  display: inline-grid;
  width: fit-content;
  min-width: 28px;
  min-height: 28px;
  align-items: center;
  justify-items: center;
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.closed-label {
  width: fit-content;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.calendar-events {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.calendar-event,
.calendar-more {
  display: block;
  min-width: 0;
  overflow: hidden;
  padding: 5px 6px;
  border-radius: 6px;
  background: var(--event-bg, var(--mint));
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-event {
  width: 100%;
  border: 0;
  border-left: 4px solid var(--event-color, var(--teal));
  cursor: grab;
  text-align: left;
}

.calendar-event:active,
.calendar-event.is-dragging {
  cursor: grabbing;
  opacity: 0.72;
}

.calendar-event:focus-visible {
  outline: 2px solid var(--sprout);
  outline-offset: 2px;
}

.calendar-more {
  background: var(--surface-2);
  color: var(--muted);
}

.calendar-grid {
  display: grid;
  gap: 10px;
}

.appointment {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: #fff;
}

.appointment time {
  color: var(--teal);
  font-weight: 900;
}

.note {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.note h4 {
  margin: 0 0 8px;
}

.note p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.45;
}

.permission-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 180px repeat(5, minmax(90px, 1fr));
  overflow-x: auto;
}

.perm-cell {
  min-height: 42px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.perm-head {
  background: #213d1f;
  color: #fff;
}

.audit {
  max-height: 460px;
  overflow: auto;
}

.note-files {
  margin-top: 12px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  max-width: 420px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #213d1f;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
}

.toast.is-hidden {
  display: none;
}

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.empty.compact {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffbea;
  text-align: left;
}

.danger-text {
  color: var(--red);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .nav-item {
    text-align: center;
  }

  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4,
  .form-grid,
  .form-grid.cols-3 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 14px;
  }

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

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

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

  .client-profile {
    grid-template-columns: 1fr;
  }

  .client-photo {
    width: 100%;
    min-height: 180px;
  }
}
