:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #697586;
  --line: #dce3ea;
  --primary: #16665f;
  --primary-dark: #0f4d48;
  --shadow: 0 18px 45px rgba(24, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px;
  background: #101820;
  color: #f7fafc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-box {
  width: 100%;
  padding: 18px 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #050608;
  color: #f2994a;
  font-size: 1.45rem;
  font-weight: 900;
  text-align: center;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #f2c94c;
  color: #101820;
  font-weight: 800;
}

.brand p,
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand p {
  color: #9fb1bf;
}

.brand h1,
.topbar h2,
.dialog-head h2 {
  margin: 0;
}

.brand h1 {
  font-size: 1.2rem;
}

.nav {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.nav-button {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: transparent;
  color: #d8e0e7;
  text-align: left;
  font-weight: 700;
}

.nav-button.active,
.nav-button:hover {
  background: #ffffff;
  color: #101820;
}

.content {
  min-width: 0;
  padding: 34px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

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

.topbar h2 {
  font-size: clamp(1.8rem, 3vw, 2.8rem);
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.text-button,
.switch-button {
  min-height: 42px;
  border-radius: 8px;
  border: 0;
  font-weight: 800;
}

.primary-button {
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
}

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

.secondary-button {
  padding: 0 16px;
  background: #e7edf2;
  color: var(--ink);
}

.danger-button {
  margin-right: auto;
  padding: 0 16px;
  background: #fee4e2;
  color: #b42318;
}

.text-button {
  padding: 0;
  background: transparent;
  color: var(--primary);
}

.icon-button {
  width: 44px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 1.7rem;
  line-height: 1;
}

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.calendar-toolbar h3 {
  width: min(380px, 58vw);
  margin: 0;
  text-align: center;
  font-size: 1.35rem;
}

.view-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e7edf2;
}

.switch-button {
  min-height: 34px;
  padding: 0 12px;
  background: transparent;
  color: #425466;
}

.switch-button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(24, 32, 42, 0.08);
}

#todayButton {
  min-height: 42px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: 58px repeat(7, minmax(0, 1fr));
}

.weekdays {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.weekdays div {
  padding: 0 10px;
}

.week-jump {
  display: grid;
  min-height: 132px;
  place-items: center;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #edf2f5;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 900;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.week-jump:hover {
  background: #dcebe9;
}

.days {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  gap: 1px;
}

.day {
  min-height: 132px;
  padding: 10px;
  background: var(--panel);
}

.day.muted {
  background: #f0f3f6;
  color: #97a4b3;
}

.day.past,
.week-day-column.past {
  background: #eceff3;
  color: #8a96a6;
}

.week-day-head.past {
  background: #e7ebef;
  color: #7a8797;
}

.day.today,
.week-day-column.today {
  background: #ecf8f1;
  box-shadow: inset 0 0 0 2px #27ae60;
}

.week-day-head.today {
  background: #dff3e7;
  color: #17643a;
}

.day.today .day-header span {
  display: inline-grid;
  min-width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 999px;
  background: #27ae60;
  color: #fff;
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 800;
}

.add-day {
  width: 26px;
  height: 26px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  font-weight: 900;
}

.event-list {
  display: grid;
  gap: 6px;
}

.event-pill {
  position: relative;
  display: grid;
  gap: 2px;
  min-height: 52px;
  padding: 7px 34px 22px 8px;
  border-radius: 7px;
  color: #101820;
  font-size: 0.78rem;
  font-weight: 800;
  border-left: 4px solid currentColor;
  background: color-mix(in srgb, currentColor 15%, white);
  cursor: pointer;
}

.event-pill strong,
.event-pill span,
.event-pill small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-pill span {
  color: #334155;
  font-size: 0.72rem;
  font-weight: 700;
}

.event-pill small {
  color: #101820;
  font-size: 0.72rem;
  font-weight: 900;
}

.event-location {
  color: #526273;
  font-size: 0.72rem;
  font-weight: 700;
}

.group-step {
  position: absolute;
  right: 6px;
  bottom: 5px;
  display: grid;
  width: 24px;
  height: 24px;
  min-height: 0;
  place-items: center;
  border: 1px solid rgba(16, 24, 32, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: #101820;
  font-weight: 900;
}

.group-step:hover {
  background: #fff;
  transform: translateY(-1px);
}

.table-step {
  position: static;
  flex: 0 0 auto;
}

.week-calendar {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.week-head,
.week-body {
  display: grid;
  grid-template-columns: 72px repeat(7, minmax(130px, 1fr));
  min-width: 1040px;
}

.week-head {
  position: sticky;
  top: 0;
  z-index: 3;
  border-bottom: 1px solid var(--line);
  background: #edf2f5;
}

.time-head,
.week-day-head {
  padding: 12px;
  border-right: 1px solid var(--line);
}

.week-day-head {
  display: grid;
  gap: 2px;
}

.week-day-head span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.week-body {
  height: 1008px;
}

.time-scale {
  display: grid;
  grid-template-rows: repeat(14, 72px);
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.time-scale div {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.week-day-column {
  position: relative;
  display: grid;
  grid-template-rows: repeat(14, 72px);
  border-right: 1px solid var(--line);
  background: #fff;
}

.hour-line {
  border-bottom: 1px solid #edf2f5;
}

.week-add {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 26px;
  height: 26px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  font-weight: 900;
}

.week-event {
  position: absolute;
  left: 7px;
  right: 7px;
  z-index: 1;
  display: grid;
  align-content: start;
  gap: 2px;
  overflow: hidden;
  padding: 7px 34px 26px 8px;
  border: 0;
  border-radius: 7px;
  color: #101820;
  text-align: left;
  box-shadow: 0 6px 14px rgba(24, 32, 42, 0.14);
}

.week-event strong,
.week-event span,
.week-event small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-event span,
.week-event small {
  font-size: 0.72rem;
  font-weight: 800;
}

.week-event.compact {
  padding-top: 6px;
  padding-bottom: 24px;
}

.week-event.compact strong {
  white-space: normal;
  line-height: 1.1;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.week-event.call-event {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 30px 3px 8px;
  overflow: visible;
}

.week-event.call-event strong {
  display: block;
  position: relative;
  z-index: 2;
  margin-right: 18px;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
  line-height: 1.15;
}

.panel,
dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.customer-form {
  margin-bottom: 18px;
  padding: 20px;
}

.hidden {
  display: none;
}

.sync-status {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 30;
  display: flex;
  align-items: center;
  padding: 0;
  background: transparent;
}

.sync-status[data-sync-status="ready"] {
  border-color: rgba(24, 119, 83, 0.32);
}

.sync-status[data-sync-status="error"] {
  border-color: rgba(190, 64, 48, 0.45);
}

.sync-status button {
  flex: 0 0 auto;
  border: 0;
  border-radius: 6px;
  background: #187753;
  color: #fff;
  font: inherit;
  font-weight: 700;
  padding: 7px 10px;
  cursor: pointer;
}

.sync-status button:hover {
  background: #126244;
}

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

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

#eventForm .form-grid.two,
#moveForm .form-grid.two {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.9fr);
}

#eventForm .form-grid.two > label:first-child,
#moveForm label:has(.date-inputs) {
  grid-column: 1 / -1;
}

.wide {
  grid-column: span 2;
}

label {
  display: grid;
  gap: 7px;
  color: #425466;
  font-size: 0.86rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

input[type="date"],
input[type="time"] {
  min-height: 64px;
  font-size: 1.12rem;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.date-inputs {
  display: grid;
  grid-template-columns: minmax(86px, 0.7fr) minmax(120px, 1fr) minmax(120px, 1fr);
  gap: 8px;
}

.date-inputs input {
  min-height: 58px;
  font-size: 1rem;
  font-weight: 800;
}

.date-hint {
  display: block;
  min-height: 20px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.time-inputs,
.duration-inputs {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) auto minmax(70px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.time-inputs {
  grid-template-columns: minmax(70px, 1fr) auto minmax(70px, 1fr);
}

.time-inputs input,
.duration-inputs input {
  min-height: 54px;
  font-size: 1.06rem;
  font-weight: 800;
}

.time-inputs span,
.duration-inputs span {
  color: var(--muted);
  font-weight: 800;
}

textarea {
  resize: vertical;
}

.check-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 45px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.check-option input {
  width: 18px;
  height: 18px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.customer-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.customer-search {
  display: grid;
  gap: 7px;
  max-width: 420px;
  margin-bottom: 16px;
}

.customer-search input {
  min-height: 46px;
}

.customer-tab {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.customer-tab.active {
  border-color: var(--primary);
  background: #edf7f6;
  color: var(--primary-dark);
}

.customer-tab.won.active {
  border-color: #27ae60;
  background: #ecf8f1;
  color: #17643a;
}

.customer-tab.lost.active {
  border-color: #eb5757;
  background: #fff3f2;
  color: #b42318;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

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

th {
  background: #edf2f5;
  color: #526273;
  font-size: 0.78rem;
  text-transform: uppercase;
}

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

.customer-row {
  cursor: pointer;
}

.customer-row:hover td {
  background: #f7fafc;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #edf2f5;
  font-weight: 800;
  white-space: nowrap;
}

.appointment-type-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.restore-button,
.status-button {
  min-height: 30px;
  border: 0;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 900;
}

.restore-button {
  width: 32px;
  background: #edf2f5;
  color: #425466;
}

.status-button {
  padding: 0 10px;
}

.status-button.won {
  background: #dcf5e6;
  color: #17643a;
}

.status-button.lost {
  background: #fee4e2;
  color: #b42318;
}

.delete-button {
  border: 0;
  background: transparent;
  color: #b42318;
  font-weight: 800;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.edit-button,
.trash-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 8px;
}

.edit-button {
  background: #edf2f5;
  color: #425466;
}

.trash-button {
  background: #fee4e2;
  color: #b42318;
}

.edit-button svg,
.trash-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.muted-text {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  padding: 0;
}

dialog::backdrop {
  background: rgba(16, 24, 32, 0.45);
}

.dialog-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

.customer-picker {
  position: relative;
}

.customer-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.customer-result {
  display: grid;
  gap: 2px;
  padding: 11px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.customer-result:hover,
.customer-result.create {
  background: #edf7f6;
}

.customer-result span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.customer-info {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #c8e1df;
  border-radius: 8px;
  background: #edf7f6;
  color: #244441;
  font-size: 0.86rem;
  font-weight: 700;
}

.free-slot-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfc;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.panel-head span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.free-slot-list {
  display: grid;
  gap: 8px;
}

.free-slot-group {
  display: grid;
  gap: 8px;
}

.free-slot-group-title {
  color: #526273;
  font-size: 0.78rem;
  font-weight: 900;
}

.free-slot-option {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  font-weight: 800;
}

.free-slot-option.active {
  border-color: var(--primary);
  background: #edf7f6;
}

.free-slot-option span,
.empty-slot-note {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.planning-warning {
  padding: 12px;
  border: 1px solid #f4d47c;
  border-radius: 8px;
  background: #fff8e6;
  color: #8a5a00;
  font-weight: 800;
}

.conflict-warning {
  padding: 12px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fff3f2;
  color: #b42318;
  font-weight: 800;
}

.conflict-warning.soft-warning {
  border-color: #f4d47c;
  background: #fff8e6;
  color: #8a5a00;
}

.week-calendar.hidden,
.customer-results.hidden,
.customer-info.hidden,
.planning-warning.hidden,
.conflict-warning.hidden,
.hidden {
  display: none;
}

#moveDialog .customer-info {
  display: grid;
}

.empty-state {
  padding: 36px 16px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

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

  .sidebar {
    position: static;
    padding: 18px;
  }

  .legend {
    margin-top: 0;
  }

  .content {
    padding: 20px;
  }

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

@media (max-width: 640px) {
  .topbar,
  .dialog-head {
    align-items: stretch;
    flex-direction: column;
  }

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

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

  .date-inputs {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .day,
  .week-jump {
    min-height: 108px;
  }

  .day {
    padding: 7px;
  }

  .event-pill {
    padding: 6px;
    font-size: 0.7rem;
  }
}
