/* Bitrix24-like STO planning calendar */
:root {
  --bx-bg: #f5f7f8;
  --bx-border: #e0e4e8;
  --bx-text: #333;
  --bx-muted: #828b95;
  --bx-btn-bg: #f0f2f4;
  --bx-btn-hover: #e4e8eb;
  --bx-accent: #2fc6f6;
  --bx-record-border: #3bc8f5;
  --bx-record-bg: #f3f5f6;
  --bx-past-bg: #eef0f2;
  --bx-now-line: #e53935;
  --bx-current-client: #1e88e5;
  --bx-overlap: #ff9800;
  --slot-width: 48px;
  --row-height: 44px;
  --sidebar-width: 200px;
  --header-height: 72px;
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  color: var(--bx-text);
  background: #fff;
}

.sto-calendar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sto-toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bx-bg);
  border-bottom: 1px solid var(--bx-border);
}

.sto-toolbar__nav,
.sto-toolbar__right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.sto-btn {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border: none;
  border-radius: 20px;
  background: var(--bx-btn-bg);
  color: var(--bx-text);
  cursor: pointer;
  white-space: nowrap;
}

.sto-btn:hover { background: var(--bx-btn-hover); }
.sto-btn--primary { background: var(--bx-accent); color: #fff; }
.sto-btn--primary:hover { filter: brightness(0.95); }
.sto-btn--danger { color: #c62828; }
.sto-btn--ghost { background: transparent; }
.sto-btn--calendar { display: flex; align-items: center; gap: 6px; }

.sto-mini-cal-popup {
  position: absolute;
  right: 16px;
  top: 56px;
  z-index: 100;
  background: #fff;
  border: 1px solid var(--bx-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 12px;
}

.sto-mini-cal__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 600;
}

.sto-mini-cal__grid {
  display: grid;
  grid-template-columns: repeat(7, 32px);
  gap: 2px;
  text-align: center;
  font-size: 12px;
}

.sto-mini-cal__dow { color: var(--bx-muted); font-size: 11px; padding: 4px 0; }
.sto-mini-cal__day {
  padding: 6px 0;
  border-radius: 4px;
  cursor: pointer;
  border: none;
  background: transparent;
  font: inherit;
}

.sto-mini-cal__day:hover { background: var(--bx-btn-bg); }
.sto-mini-cal__day--selected { background: #fff3cd; font-weight: 600; }
.sto-mini-cal__day--today { outline: 1px solid var(--bx-accent); }

.sto-grid-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
}

.sto-loading {
  padding: 40px;
  text-align: center;
  color: var(--bx-muted);
}

.sto-grid {
  display: flex;
  width: 100%;
  min-width: 100%;
}

.sto-grid__sidebar {
  position: sticky;
  left: 0;
  z-index: 20;
  background: #fff;
  border-right: 1px solid var(--bx-border);
  flex-shrink: 0;
}

.sto-grid__corner {
  height: var(--header-height);
  border-bottom: 1px solid var(--bx-border);
  background: var(--bx-bg);
}

.sto-grid__post {
  height: var(--row-height);
  width: var(--sidebar-width);
  padding: 0 10px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--bx-border);
  font-size: 12px;
  line-height: 1.2;
  background: #fff;
}

/* Responsive tweaks (keep look, just scale) */
@media (max-width: 900px) {
  :root { --sidebar-width: 160px; --slot-width: 42px; --row-height: 40px; }
  .sto-btn { padding: 8px 12px; }
}

@media (max-width: 600px) {
  :root { --sidebar-width: 130px; --slot-width: 36px; --row-height: 38px; }
  .sto-toolbar { padding: 8px 10px; }
  .sto-btn { padding: 7px 10px; font-size: 12px; }
  .sto-btn__icon { display: none; }
}

.sto-grid__timeline {
  flex: 1;
  position: relative;
}

.sto-grid__header {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 15;
  background: var(--bx-bg);
  border-bottom: 1px solid var(--bx-border);
  height: var(--header-height);
}

.sto-day-header {
  border-right: 1px solid var(--bx-border);
  flex-shrink: 0;
}

.sto-day-header__date {
  text-align: center;
  padding: 6px;
  font-weight: 600;
  border-bottom: 1px solid var(--bx-border);
}

.sto-day-header__date--active {
  background: #fff8e1;
}

.sto-day-header__hours {
  display: flex;
}

.sto-hour-col {
  border-right: 1px solid var(--bx-border);
  flex-shrink: 0;
}

.sto-hour-col__label {
  text-align: center;
  padding: 4px;
  font-weight: 500;
  border-bottom: 1px solid var(--bx-border);
}

.sto-hour-col__slots {
  display: flex;
}

.sto-slot-label {
  width: var(--slot-width);
  text-align: center;
  font-size: 11px;
  color: var(--bx-muted);
  padding: 2px 0;
  border-right: 1px solid var(--bx-border);
}

.sto-grid__body {
  position: relative;
}

.sto-post-row {
  display: flex;
  height: var(--row-height);
  border-bottom: 1px solid var(--bx-border);
  position: relative;
}

.sto-day-cells {
  display: flex;
  position: relative;
  flex-shrink: 0;
}

.sto-slot {
  width: var(--slot-width);
  height: 100%;
  border-right: 1px solid var(--bx-border);
  flex-shrink: 0;
}

.sto-slot--past { background: var(--bx-past-bg); }
.sto-slot--off-hours { background: repeating-linear-gradient(
  -45deg,
  #f8f9fa,
  #f8f9fa 4px,
  #eef0f2 4px,
  #eef0f2 8px
); }

.sto-now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--bx-now-line);
  z-index: 12;
  pointer-events: none;
}

.sto-record {
  position: absolute;
  top: 4px;
  bottom: 4px;
  background: var(--bx-record-bg);
  border-top: 3px solid var(--bx-record-border);
  border-radius: 2px;
  padding: 2px 6px;
  font-size: 11px;
  overflow: hidden;
  cursor: grab;
  z-index: 10;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  user-select: none;
}

.sto-record:active { cursor: grabbing; }
.sto-record--current-client {
  outline: 2px solid var(--bx-current-client);
  outline-offset: -1px;
}
.sto-record--overlap {
  border-top-color: var(--bx-overlap);
}
.sto-record--drag-invalid {
  background: #ffebee !important;
  border-top-color: #e53935;
}

.sto-record__resize {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
}

.sto-readonly-banner {
  padding: 8px 12px;
  background: #fff3e0;
  color: #e65100;
  text-align: center;
  font-size: 12px;
}

.sto-dialog {
  --sto-dlg-radius: 14px;
  --sto-dlg-accent: linear-gradient(135deg, #21a6e6 0%, #2fc6f6 55%, #4dd4ff 100%);
  border: none;
  padding: 0;
  max-width: min(440px, calc(100vw - 32px));
  width: 100%;
  background: transparent;
  color: var(--bx-text);
}

.sto-dialog:focus { outline: none; }

.sto-dialog::backdrop {
  background: rgba(15, 25, 38, 0.45);
  backdrop-filter: saturate(120%) blur(4px);
  -webkit-backdrop-filter: saturate(120%) blur(4px);
  animation: sto-backdrop-in 0.28s ease-out both;
}

@keyframes sto-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sto-dialog__inner {
  position: relative;
  background: #fff;
  border-radius: var(--sto-dlg-radius);
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.04),
    0 24px 48px rgba(27, 53, 73, 0.18);
  overflow: hidden;
  animation: sto-dialog-in 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.sto-dialog--open .sto-dialog__head,
.sto-dialog--open .sto-dialog__fieldset,
.sto-dialog--open .sto-dialog__footer {
  animation: sto-dialog-section-in 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.sto-dialog--open .sto-dialog__fieldset:nth-of-type(1) { animation-delay: 0.04s; }
.sto-dialog--open .sto-dialog__fieldset:nth-of-type(2) { animation-delay: 0.08s; }
.sto-dialog--open .sto-dialog__footer { animation-delay: 0.12s; }

@keyframes sto-dialog-section-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sto-dialog-in {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sto-dialog::backdrop {
    animation: none;
  }
  .sto-dialog__inner {
    animation: none;
  }
}

.sto-dialog__close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--bx-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.sto-dialog__close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--bx-text);
}

.sto-dialog__head {
  padding: 22px 48px 16px 20px;
  background: linear-gradient(180deg, #f8fbfd 0%, #fff 100%);
  border-bottom: 1px solid rgba(224, 228, 232, 0.9);
}

.sto-dialog__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sto-dialog__subtitle {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--bx-muted);
  line-height: 1.35;
}

.sto-form {
  padding: 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}

.sto-dialog__fieldset {
  padding: 16px 20px;
  border-bottom: 1px solid var(--bx-border);
}

.sto-dialog__fieldset:last-of-type {
  border-bottom: none;
}

.sto-dialog__legend {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bx-muted);
  margin-bottom: 12px;
}

.sto-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.sto-field:last-child {
  margin-bottom: 0;
}

.sto-field__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--bx-text);
}

.sto-field-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.sto-field--grow {
  flex: 1;
  margin-bottom: 0;
}

.sto-field--narrow {
  flex: 0 0 88px;
  margin-bottom: 0;
}

.sto-field--full {
  margin-bottom: 12px;
}

.sto-field__control {
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--bx-border);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sto-field__control:focus {
  outline: none;
  border-color: #2fc6f6;
  box-shadow: 0 0 0 3px rgba(47, 198, 246, 0.22);
}

.sto-field__control--readonly {
  background: var(--bx-bg);
  color: var(--bx-muted);
  cursor: default;
}

.sto-field__control--textarea {
  min-height: 64px;
  resize: vertical;
}

.sto-dialog__error {
  margin: 0 20px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff8e6;
  border: 1px solid #ffe0b2;
  color: #b45309;
  font-size: 13px;
  line-height: 1.4;
}

.sto-dialog__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  margin-top: 4px;
  background: linear-gradient(0deg, #fafbfc 0%, transparent 60%);
}

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

.sto-btn--sm {
  padding: 7px 12px;
  font-size: 12px;
  border-radius: 10px;
}

.sto-btn--lg {
  padding: 10px 20px;
  font-weight: 600;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(47, 198, 246, 0.35);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  justify-content: center;
}

.sto-btn--danger-outline {
  color: #c62828;
}

.sto-btn--danger-outline:hover {
  background: rgba(198, 40, 40, 0.08);
}

.sto-dialog--busy #btn-dialog-save {
  opacity: 0.85;
  pointer-events: none;
}

.sto-dialog--busy .sto-btn__spinner {
  display: inline-block;
}

.sto-dialog--busy .sto-btn__label {
  opacity: 0.75;
}

.sto-btn__spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: sto-spin 0.65s linear infinite;
}

@keyframes sto-spin {
  to { transform: rotate(360deg); }
}

.sto-dialog--busy .sto-form {
  pointer-events: none;
}

.sto-dialog__saving-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  /* Лёгкое затемнение — форма остаётся читаемой */
  background: rgba(255, 255, 255, 0.55);
}

.sto-dialog--busy .sto-dialog__saving-overlay:not([hidden]) {
  display: flex;
  animation: sto-saving-fade 0.22s ease both;
}

.sto-dialog__saving-overlay[hidden] {
  display: none !important;
}

@keyframes sto-saving-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sto-dialog__saving-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 28px 36px 24px;
  min-width: 240px;
  max-width: 90%;
  background: #fff;
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(47, 198, 246, 0.15),
    0 16px 40px rgba(27, 53, 73, 0.14);
  animation: sto-saving-card-in 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes sto-saving-card-in {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.sto-saving-glow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(
    circle at 50% 40%,
    rgba(47, 198, 246, 0.22) 0%,
    transparent 65%
  );
  pointer-events: none;
  animation: sto-glow-pulse 2s ease-in-out infinite;
}

@keyframes sto-glow-pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

.sto-dialog__saving-card[data-busy-variant="delete"] .sto-saving-glow {
  background: radial-gradient(
    circle at 50% 40%,
    rgba(229, 57, 53, 0.18) 0%,
    transparent 65%
  );
}

.sto-dialog__saving-card[data-busy-variant="delete"] .sto-spinner__ring {
  border-color: rgba(229, 57, 53, 0.2);
  border-top-color: #e53935;
}

.sto-dialog__saving-card[data-busy-variant="copy"] .sto-saving-glow {
  background: radial-gradient(
    circle at 50% 40%,
    rgba(76, 175, 80, 0.2) 0%,
    transparent 65%
  );
}

.sto-dialog__saving-card[data-busy-variant="copy"] .sto-spinner__ring {
  border-color: rgba(76, 175, 80, 0.2);
  border-top-color: #43a047;
}

.sto-dialog__saving-card[data-busy-variant="copy"] .sto-spinner__dot {
  background: #43a047;
  box-shadow: 0 0 12px rgba(76, 175, 80, 0.45);
}

.sto-dialog__saving-card[data-busy-variant="delete"] .sto-spinner__dot {
  background: #e53935;
  box-shadow: 0 0 12px rgba(229, 57, 53, 0.45);
}

.sto-spinner,
.sto-dialog__saving-copy {
  position: relative;
  z-index: 1;
}

.sto-spinner {
  width: 52px;
  height: 52px;
  position: relative;
  flex-shrink: 0;
}

.sto-spinner__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(47, 198, 246, 0.18);
  border-top-color: #2fc6f6;
  border-right-color: rgba(47, 198, 246, 0.45);
  animation: sto-spin 0.75s cubic-bezier(0.5, 0.15, 0.5, 0.85) infinite;
}

.sto-spinner__dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: #2fc6f6;
  box-shadow: 0 0 12px rgba(47, 198, 246, 0.5);
  animation: sto-dot-pulse 1.2s ease-in-out infinite;
}

@keyframes sto-dot-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.85); opacity: 0.7; }
}

.sto-dialog__saving-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.sto-dialog__saving-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--bx-text);
  letter-spacing: -0.01em;
}

.sto-dialog__saving-hint {
  font-size: 12px;
  color: var(--bx-muted);
  line-height: 1.35;
  max-width: 220px;
}

@media (prefers-reduced-motion: reduce) {
  .sto-dialog__saving-overlay {
    animation: none;
  }
  .sto-dialog__saving-card {
    animation: none;
  }
  .sto-saving-glow,
  .sto-spinner__ring,
  .sto-spinner__dot,
  .sto-btn__spinner {
    animation-duration: 1.6s;
  }
  .sto-dialog--open .sto-dialog__head,
  .sto-dialog--open .sto-dialog__fieldset,
  .sto-dialog--open .sto-dialog__footer {
    animation: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sto-dialog__close,
  .sto-field__control,
  .sto-btn--primary {
    transition: none;
  }
}

.sto-select-ghost { opacity: 0.6; pointer-events: none; }

.sto-copy-suggest {
  margin: 10px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #ffe0b2;
  background: #fff8e6;
  color: #6b4a00;
}

.sto-copy-suggest__row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sto-copy-suggest__label {
  font-size: 12px;
  color: #8a5b00;
  font-weight: 600;
}

.sto-copy-suggest__select {
  width: 100%;
}

.sto-copy-suggest__actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
