:root {
  --bg-page: #FAF8F5;
  --bg-surface: #FFFFFF;
  --bg-card: var(--bg-surface);
  --bg-muted: #F0EDE8;
  --text-primary: #1A1A1A;
  --text-secondary: #6B7280;
  --accent-primary: #00A86B;
  --accent-secondary: #1E3A4A;
  --border: #E8E4DE;
  --radius-card: 14px;
  --radius-btn: 999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --spacing-compact: 8px;
  --sidebar-width: 220px;
  --topbar-height: 56px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-page);
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}

.sidebar-brand {
  font-weight: 700;
  font-size: 1.1rem;
  padding: 8px 12px 20px;
  color: var(--accent-secondary);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-secondary);
  transition: background 0.15s;
}

.nav-item:hover,
.nav-item.active {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.nav-item.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: relative;
  z-index: 120;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow-sm);
}

.topbar-title {
  font-weight: 600;
}

.search-input {
  width: 280px;
  max-width: 40vw;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--bg-page);
  font: inherit;
}

.content {
  padding: 20px;
  flex: 1;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.text-secondary {
  color: var(--text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-btn);
  padding: 10px 18px;
  font: inherit;
  cursor: pointer;
  transition: filter 0.15s;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
}

.login-card {
  width: min(400px, 92vw);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 32px;
  box-shadow: var(--shadow-sm);
}

.login-title {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.login-subtitle {
  margin: 0 0 24px;
  color: var(--text-secondary);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.field input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: var(--bg-page);
}

.alert {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 0.875rem;
}

.alert-error {
  background: #FEF2F2;
  color: #B91C1C;
  border: 1px solid #FECACA;
}

.calendar-placeholder {
  min-height: 400px;
}

.nav-group {
  margin-top: 12px;
}

.nav-group-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 4px 12px 6px;
}

.nav-group--collapsible .nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  color: inherit;
  padding: 4px 12px 6px;
}

.nav-group--collapsible .nav-group-toggle:hover,
.nav-group--collapsible .nav-group-toggle:focus-visible {
  color: var(--text-primary);
  background: var(--bg-muted);
  border-radius: 6px;
}

.nav-group-chevron {
  display: inline-block;
  width: 0.75rem;
  transition: transform 0.15s ease;
  transform: rotate(90deg);
}

.nav-group--collapsed .nav-group-chevron {
  transform: rotate(0deg);
}

.nav-group--collapsed .nav-group-items {
  display: none;
}

.crud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.crud-filters {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table tbody tr:hover {
  background: var(--bg-muted);
}

.row-actions {
  white-space: nowrap;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: var(--bg-page);
  resize: vertical;
}

.field select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: var(--bg-page);
}

.field-readonly {
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.field-hint {
  margin: 4px 0 8px;
  font-size: 0.875rem;
}

.crud-company-form .combo-picker {
  position: relative;
}

.crud-company-form .combo-picker-input {
  width: 100%;
}

.crud-company-form .combo-picker:has(.combo-picker-dropdown:not(.hidden)) {
  z-index: 100;
}

.crud-company-form .combo-picker-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.crud-company-form .combo-picker-dropdown.hidden {
  display: none;
}

.crud-company-form .combo-picker-option {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.crud-company-form .combo-picker-option:hover,
.crud-company-form .combo-picker-option.is-active {
  background: var(--bg-muted);
}

.crud-company-form .combo-picker-empty {
  padding: 8px 12px;
  color: var(--text-secondary);
}

.company-contacts-block {
  padding-top: 4px;
  position: relative;
  z-index: 0;
}

.crud-company-form .field-inline:has(.company-link-contact-picker) {
  position: relative;
  z-index: 2;
}

.crud-form-modal .field-inline:has(.company-link-contact-picker) {
  position: relative;
  z-index: 2;
}

.company-contacts-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
  width: 100%;
}

.company-link-contact-picker {
  flex: 1;
  min-width: 0;
}

.company-contacts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.company-contact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.company-contact-main {
  flex: 1;
  min-width: 0;
}

.company-contact-unlink {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.company-contact-unlink:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.company-contact-unlink-icon {
  width: 14px;
  height: 14px;
  display: block;
}

.company-contact-item:last-child {
  border-bottom: 0;
}

.company-contact-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.company-contacts-empty {
  margin: 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: min(480px, 92vw);
  max-height: 90vh;
  overflow: auto;
}

.crud-form-modal.modal-content,
#booking-form-modal.modal-content {
  width: min(720px, 94vw);
}

.crud-form-modal .crud-form-compact,
#booking-form-modal .booking-form-compact {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.crud-form-modal .crud-form-compact .field-inline,
#booking-form-modal .booking-form-compact .field-inline {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  min-width: 0;
}

.crud-form-modal .crud-form-compact .field-inline-top,
#booking-form-modal .booking-form-compact .field-inline-top {
  align-items: start;
}

.crud-form-modal .crud-form-compact .field-inline-top .field-label,
#booking-form-modal .booking-form-compact .field-inline-top .field-label {
  padding-top: 7px;
}

.crud-form-modal .crud-form-compact .field-label,
#booking-form-modal .booking-form-compact .field-label {
  font-size: 0.82rem;
  margin-bottom: 0;
}

.crud-form-modal .crud-form-compact input:not([type="hidden"]),
.crud-form-modal .crud-form-compact select,
.crud-form-modal .crud-form-compact textarea,
#booking-form-modal .booking-form-compact input:not([type="hidden"]),
#booking-form-modal .booking-form-compact select,
#booking-form-modal .booking-form-compact textarea {
  width: 100%;
  box-sizing: border-box;
  font-size: 0.82rem;
  padding: 6px 8px;
  border-radius: 8px;
}

.crud-form-modal .crud-form-compact textarea,
#booking-form-modal .booking-form-compact textarea {
  min-height: 52px;
  resize: vertical;
}

.crud-form-modal .crud-form-compact .form-actions,
#booking-form-modal .booking-form-compact .form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

#booking-form-modal .booking-form-hidden {
  display: none;
}

.booking-schedule-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 0;
}

.booking-datetime-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.booking-datetime-row .field-datetime .field-label {
  font-size: 0.82rem;
}

#booking-form-modal .booking-form-compact .field-datetime {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 0;
  min-width: 0;
}

.booking-duration-value {
  font-size: 0.82rem;
}

.booking-form-summary {
  margin: 0 0 12px;
  font-size: 0.9rem;
}

.crud-form-modal .combo-picker,
#booking-form-modal .combo-picker {
  position: relative;
}

.crud-form-modal .combo-picker-input,
#booking-form-modal .combo-picker-input {
  width: 100%;
}

.crud-form-modal .combo-picker:has(.combo-picker-dropdown:not(.hidden)),
#booking-form-modal .combo-picker:has(.combo-picker-dropdown:not(.hidden)) {
  z-index: 100;
}

.crud-form-modal .combo-picker-dropdown,
#booking-form-modal .combo-picker-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.crud-form-modal .combo-picker-dropdown.hidden,
#booking-form-modal .combo-picker-dropdown.hidden {
  display: none;
}

.crud-form-modal .combo-picker-option,
#booking-form-modal .combo-picker-option {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 0.82rem;
}

.crud-form-modal .combo-picker-option:hover,
.crud-form-modal .combo-picker-option.is-active,
#booking-form-modal .combo-picker-option:hover,
#booking-form-modal .combo-picker-option.is-active {
  background: var(--bg-muted);
}

.crud-form-modal .combo-picker-empty,
#booking-form-modal .combo-picker-empty {
  padding: 8px 12px;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent, #2563eb);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.topbar-search-wrap {
  position: relative;
}

.topbar-search-wrap .search-dropdown {
  z-index: 130;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-menu-wrap,
.profile-menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.topbar-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-page);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.topbar-menu-trigger:hover,
.topbar-menu-trigger:focus-visible,
.topbar-menu-trigger[aria-expanded="true"] {
  background: var(--bg-muted);
  border-color: var(--accent-primary);
  outline: none;
}

.topbar-menu-icon {
  font-size: 1.05rem;
  line-height: 1;
}

.topbar-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  max-height: min(70vh, 420px);
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  padding: 8px 0;
  z-index: 60;
}

.topbar-menu.hidden {
  display: none;
}

.topbar-menu-title {
  padding: 6px 14px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.topbar-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
}

.topbar-menu-item:hover,
.topbar-menu-item.active {
  background: var(--bg-muted);
}

.topbar-menu-item.active {
  font-weight: 600;
}

.topbar-menu-item-icon {
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.profile-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-page);
  color: var(--accent-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.profile-menu-trigger:hover,
.profile-menu-trigger:focus-visible,
.profile-menu-trigger[aria-expanded="true"] {
  background: var(--bg-muted);
  border-color: var(--accent-primary);
  outline: none;
}

.profile-avatar {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
}

.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  padding: 8px 0;
  z-index: 60;
}

.profile-menu.hidden {
  display: none;
}

.profile-menu-header {
  padding: 8px 14px 10px;
}

.profile-menu-name {
  font-weight: 600;
  color: var(--text-primary);
}

.profile-menu-meta,
.profile-menu-role {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.profile-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.profile-menu-logout {
  margin: 0;
}

.profile-menu-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  color: var(--text-primary);
  cursor: pointer;
}

.profile-menu-item:hover,
.profile-menu-item:focus-visible {
  background: var(--bg-muted);
  outline: none;
}

.profile-menu-item--logout {
  color: #B42318;
}

.search-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  min-width: 320px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  padding: 12px;
  z-index: 50;
}

.search-dropdown:empty {
  display: none;
}

.search-group-title {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 8px 0 4px;
}

.search-item {
  display: block;
  padding: 6px 4px;
  border-radius: 6px;
}

.search-item:hover {
  background: var(--bg-muted);
}

.filter-check {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.crud-total {
  margin-top: 12px;
  font-size: 0.875rem;
}

#call-toast-container {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: min(460px, calc(100vw - 48px));
  pointer-events: none;
}

.call-toast {
  pointer-events: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 6px solid #EA580C;
  border-radius: var(--radius-card);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
  padding: 22px 24px;
  cursor: pointer;
  animation: call-toast-in 0.25s ease-out;
}

@keyframes call-toast-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.call-toast-status {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.call-toast-phone {
  font-weight: 700;
  font-size: 1.65rem;
  line-height: 1.2;
  margin: 10px 0 8px;
}

.call-toast-contact {
  font-size: 1.15rem;
  font-weight: 600;
}

.call-toast-org {
  font-size: 0.95rem;
  margin-top: 4px;
}

.call-toast-hint {
  margin-top: 14px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .sidebar {
    width: 64px;
  }

  .nav-label,
  .sidebar-brand {
    display: none;
  }

  .search-input {
    width: 160px;
  }
}
