:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-muted: #f0f4f7;
  --line: #d7e0e7;
  --text: #1d2733;
  --muted: #647386;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --danger: #b42318;
  --warning: #a16207;
  --block: #6d5dfc;
  --radius: 8px;
  --slot-height: 19px;
  font-family: "Segoe UI", Arial, sans-serif;
}

:root[data-density="2"] {
  --slot-height: 23px;
}

:root[data-density="3"] {
  --slot-height: 28px;
}

:root[data-density="4"] {
  --slot-height: 34px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.content-shell {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-nav {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.topbar {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  min-width: 0;
}

.brand h1,
.side-head h2,
.panel-head h2,
.dialog h2,
.brand p,
.side-head p,
.panel-head p,
.dialog p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.side-head p,
.panel-head p,
.dialog p,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.display-controls,
.date-nav,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
}

.display-controls {
  grid-column: 1;
  grid-row: 1;
  justify-content: flex-start;
  justify-self: start;
  flex-wrap: wrap;
}

.date-nav {
  grid-column: 1;
  grid-row: 1;
  justify-content: center;
  justify-self: center;
  transform: translateX(var(--calendar-date-nav-shift, 0px));
}

.topbar-right {
  grid-column: 2;
  grid-row: 1;
  justify-content: flex-end;
  justify-self: end;
}

.module-tabs {
  display: grid;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.module-tabs button {
  min-height: 42px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border-radius: 6px;
  padding: 0 10px;
  color: var(--muted);
  text-align: left;
  background: var(--surface-muted);
}

.module-tabs button span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-tabs button.is-active {
  color: #ffffff;
  background: var(--primary);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.42);
  font-size: 12px;
  font-weight: 700;
}

.account-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: 0;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.account-box span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button,
.text-button,
.primary-button,
.secondary-button,
.segmented button {
  min-height: 36px;
  border-radius: 6px;
  padding: 0 12px;
}

.icon-button {
  width: 36px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  color: var(--text);
  background: var(--surface-muted);
}

.text-button,
.secondary-button {
  color: var(--text);
  background: var(--surface-muted);
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
}

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

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.segmented button {
  min-width: 36px;
  color: var(--muted);
  background: transparent;
}

.segmented button.is-active {
  color: #ffffff;
  background: var(--primary);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  padding: 14px;
}

.calendar-pane,
.workspace-panel,
.side-pane {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.calendar-pane {
  padding: 10px;
  overflow: hidden;
}

#calendar {
  min-height: calc(100vh - 112px);
}

.workspace-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 112px);
  overflow: hidden;
}

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

.panel-head h2 {
  font-size: 18px;
}

.main-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 38px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 13px;
}

.audit-filter-bar,
.list-filter-bar {
  justify-content: flex-start;
}

.audit-filter-bar label,
.list-filter-bar label {
  display: grid;
  gap: 4px;
  flex: 1 1 160px;
  min-width: 150px;
  max-width: 100%;
  color: var(--muted);
  font-size: 12px;
}

.audit-filter-bar select,
.list-filter-bar select,
.list-filter-bar input {
  min-height: 32px;
  padding: 5px 8px;
  font-size: 13px;
}

.list-filter-bar .search-field {
  min-width: min(240px, 100%);
}

.filter-summary {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.audit-sort-button,
.list-sort-button,
.list-reset-button {
  min-height: 32px;
  align-self: end;
  white-space: nowrap;
}

.side-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

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

.side-head h2 {
  font-size: 17px;
}

.appointment-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.appointment-card,
.client-card,
.audit-card {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
}

.appointment-card + .appointment-card,
.client-card + .client-card,
.audit-card + .audit-card,
.list-command + .client-card {
  margin-top: 8px;
}

.appointment-card:hover,
.appointment-card:focus-visible,
.client-card:hover,
.client-card:focus-visible {
  border-color: #9ab0c2;
  outline: 0;
}

.appointment-card.is-block {
  border-left-color: var(--block);
}

.appointment-time {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
  font-size: 13px;
}

.appointment-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.appointment-title.with-status-icon {
  display: flex;
  align-items: center;
  gap: 6px;
}

.appointment-title.with-status-icon span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.status-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #ffffff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.status-icon.status-scheduled {
  border-color: #99f6e4;
  color: var(--primary);
  background: #ecfdf5;
}

.status-icon.status-completed {
  border-color: #86efac;
  color: #166534;
  background: #f0fdf4;
}

.status-icon.status-cancelled,
.status-icon.status-no-show {
  border-color: #fecaca;
  color: var(--danger);
  background: #fef2f2;
}

.status-icon.status-needs-review {
  border-color: #fde68a;
  color: var(--warning);
  background: #fffbeb;
}

.status-icon.status-block {
  border-color: #c4b5fd;
  color: var(--block);
  background: #f5f3ff;
}

.appointment-meta {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.audit-action {
  justify-self: start;
  min-height: 30px;
  margin-top: 2px;
  padding: 0 10px;
  font-size: 13px;
}

.notice {
  margin: 10px 10px 0;
  padding: 10px;
  border: 1px solid #fde68a;
  border-radius: 6px;
  color: #713f12;
  background: #fffbeb;
  font-size: 13px;
}

.side-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 10px 0;
}

.side-tabs button {
  min-height: 34px;
  flex: 1;
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-muted);
}

.side-tabs button.is-active {
  color: #ffffff;
  background: var(--primary);
}

.request-card {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--warning);
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
}

.request-card + .request-card {
  margin-top: 8px;
}

.request-card:hover,
.request-card:focus-visible {
  border-color: #9ab0c2;
  outline: 0;
}

.request-card.is-review {
  border-left-color: var(--danger);
}

.request-card.is-scheduled {
  border-left-color: #2563eb;
}

.client-card {
  border-left-color: #0f766e;
}

.audit-card {
  border-left-color: #647386;
  cursor: default;
}

.list-command {
  width: 100%;
  margin-bottom: 8px;
}

.integration-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.integration-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}

.integration-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
  min-height: 0;
}

.log-section {
  min-width: 0;
  min-height: 0;
}

.log-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.log-list {
  max-height: calc(100vh - 290px);
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
}

.dialog {
  width: min(720px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
}

.client-dialog {
  width: min(1120px, calc(100vw - 24px));
}

.dialog::backdrop {
  background: rgba(29, 39, 51, 0.32);
}

.dialog form {
  margin: 0;
}

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

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.form-grid > .wide {
  grid-column: 1 / -1;
}

.history-panel {
  display: grid;
  gap: 8px;
  max-height: min(52vh, 520px);
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}

.history-panel h3 {
  margin: 0;
  color: var(--text);
  font-size: 14px;
}

.history-grid {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(230px, 1fr) minmax(190px, 0.8fr);
  gap: 6px;
  min-width: 740px;
}

.history-grid-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.history-row {
  display: contents;
}

.history-cell {
  display: grid;
  gap: 3px;
  min-height: 76px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.history-cell.is-empty {
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
}

textarea {
  resize: vertical;
}

.dialog-actions {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.dialog-actions div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.form-message {
  color: var(--danger);
  font-size: 13px;
}

.fc {
  font-size: 13px;
}

.fc .fc-toolbar-title {
  font-size: 18px;
}

.fc .fc-timegrid-slot {
  height: var(--slot-height);
}

.fc-event {
  border: 0;
  border-radius: 5px;
  padding: 2px 4px;
}

.calendar-event-content {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.calendar-event-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-status-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.24);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
}

.calendar-status-icon.status-scheduled {
  background: rgba(255, 255, 255, 0.28);
}

.calendar-status-icon.status-completed {
  background: #15803d;
}

.calendar-status-icon.status-cancelled,
.calendar-status-icon.status-no-show {
  background: #991b1b;
}

.calendar-status-icon.status-needs-review {
  background: #92400e;
}

.calendar-status-icon.status-block {
  background: rgba(255, 255, 255, 0.32);
}

.fc-event.service-event {
  background: var(--primary);
}

.fc-event.block-event {
  background: var(--block);
}

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

  .main-nav {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

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

  .account-box {
    margin-left: 0;
  }

  .date-nav,
  .topbar-right {
    justify-content: flex-start;
  }

  .topbar-right {
    width: 100%;
  }

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

  .workspace-panel {
    min-height: 54vh;
  }

  .side-pane {
    max-height: 42vh;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 8px;
  }

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

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

  .audit-filter-bar label,
  .list-filter-bar label {
    width: 100%;
  }

  .filter-summary {
    margin-left: 0;
  }

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

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

  .log-list {
    max-height: 260px;
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-actions div {
    justify-content: flex-end;
  }
}
