.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: var(--accent);
}

.sidebar-title {
  margin: 10px 10px 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 900;
}

.phase-nav {
  display: grid;
  gap: 10px;
}

.phase-group {
  border: 2px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
  box-shadow: var(--shadow-neo);
  overflow: hidden;
}

.phase-group > summary {
  list-style: none;
}

.phase-group > summary::-webkit-details-marker {
  display: none;
}

.phase-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text);
  font-weight: 800;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.phase-group-toggle::after {
  content: "▾";
  margin-left: auto;
  font-size: 14px;
  color: var(--muted);
  transition: transform 0.2s ease, color 0.2s ease;
}

.phase-group[open] .phase-group-toggle::after {
  transform: rotate(180deg);
  color: var(--text);
}

.phase-group-toggle:hover {
  background: rgba(240, 66, 51, 0.1);
}

.phase-group-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

.phase-group-items {
  display: grid;
  gap: 6px;
  padding: 0 10px;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.2s ease;
}

.phase-group[open] .phase-group-items {
  max-height: 520px;
  opacity: 1;
  padding: 0 10px 10px;
}

.phase-pill {
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  text-align: left;
  width: 100%;
  margin-bottom: 0;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.phase-pill:hover {
  color: var(--text);
  background: rgba(240, 66, 51, 0.12);
}

.phase-pill.active {
  border-color: var(--accent);
  border-width: 2.5px;
  color: #fff;
  background: var(--accent);
}

.phase-panel.is-hidden {
  display: none;
}

.small-muted {
  color: var(--muted);
  font-size: 12px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.auth-banner {
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-neo);
}

.auth-banner.error {
  border-color: var(--accent);
  background: rgba(240, 66, 51, 0.12);
  color: var(--text);
}

.ui-hint {
  margin-bottom: 14px;
  border-left: 4px solid var(--accent);
  background: rgba(240, 66, 51, 0.08);
}

.hint-title {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.hint-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.hint-step {
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface-soft);
}

.hint-context {
  margin-top: 8px;
  color: var(--muted);
}

body.crm-guide-lock {
  overflow: hidden;
}

.crm-guide-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: none;
  pointer-events: none;
}

.crm-guide-overlay.active {
  display: block;
  background: rgba(0, 0, 0, 0.18);
}

.crm-guide-focus {
  position: fixed;
  border: 2.5px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(4, 11, 25, 0.44);
  animation: crm-guide-pulse 1.4s ease-in-out infinite;
}

.crm-guide-panel {
  position: fixed;
  width: min(430px, calc(100vw - 24px));
  border: 3px solid var(--accent);
  border-radius: 16px;
  background: #f5f5f5;
  color: #0f172a;
  box-shadow: 14px 14px 0 rgba(0, 0, 0, 0.42);
  padding: 16px;
  pointer-events: auto;
}

.crm-guide-kicker {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 900;
  color: #334155;
}

.crm-guide-title {
  margin-top: 6px;
  font-size: 1.08rem;
  font-weight: 900;
}

.crm-guide-text {
  margin-top: 8px;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.45;
}

.crm-guide-controls {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.crm-guide-counter {
  font-size: 0.8rem;
  font-weight: 900;
  color: #334155;
}

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

.crm-guide-btn {
  border: 2px solid #334155;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.84rem;
  font-weight: 800;
  background: #ffffff;
  color: #0f172a;
  box-shadow: 3px 3px 0 rgba(15, 23, 42, 0.22);
}

.crm-guide-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: #1f2937;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
}

.crm-guide-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@keyframes crm-guide-pulse {
  0%, 100% {
    box-shadow: 0 0 0 9999px rgba(4, 11, 25, 0.44), 0 0 0 3px rgba(240, 66, 51, 0.22);
  }
  50% {
    box-shadow: 0 0 0 9999px rgba(4, 11, 25, 0.44), 0 0 0 7px rgba(240, 66, 51, 0.42);
  }
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  background: var(--panel-soft);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow-neo);
}

.metric h3 {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.metric p {
  margin: 6px 0 0;
  font-size: 22px;
  font-weight: 800;
}

.panel {
  background: var(--panel);
  border: 2.5px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-neo);
}

.panel h2,
.panel h3 {
  margin: 0;
}

.placeholder {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 12px;
  color: var(--muted);
}

.panel h3 {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

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

.search-box {
  margin-top: 10px;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-soft);
  box-shadow: var(--shadow-neo);
}

#panel-phase-note {
  margin-bottom: 14px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.settings-card {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  box-shadow: var(--shadow-neo);
  padding: 12px;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

button[data-theme-mode].active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline-form.compact input,
.inline-form.compact select {
  min-width: 130px;
}

input,
select,
button {
  width: auto;
  max-width: 100%;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--field-bg);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

textarea {
  background: var(--field-bg);
  color: var(--text);
}

input,
select,
textarea {
  min-height: 40px;
}

textarea {
  min-height: 96px;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.95;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(240, 66, 51, 0.24);
}

input[type="datetime-local"] {
  font-variant-numeric: tabular-nums;
}

.inline-form label,
.stack-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 3px), calc(100% - 10px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

select:hover {
  border-color: var(--accent);
  background-color: rgba(240, 66, 51, 0.08);
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(240, 66, 51, 0.24);
}

.row-link {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  text-align: left;
  font-weight: 700;
  cursor: pointer;
}

.row-link.active-row {
  color: var(--accent);
  text-decoration: underline;
}

.inline-action {
  padding: 4px 8px;
  font-size: 12px;
}

button {
  cursor: pointer;
  border: 2px solid var(--line);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 100px;
  padding: 12px 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-neo);
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-hover);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

.phase-pill {
  border-radius: 16px;
  padding: 14px 20px;
  box-shadow: none;
  justify-content: flex-start;
}

.inline-action {
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 12px;
  box-shadow: none;
}

.table-wrap {
  border: 2px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  box-shadow: var(--shadow-neo);
}

.thread-head {
  margin-bottom: 10px;
}

.thread-split {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.stack-form {
  display: grid;
  gap: 8px;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-soft);
  box-shadow: var(--shadow-neo);
}

.stack-form h4 {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.stack-form textarea {
  min-height: 110px;
  resize: vertical;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 8px;
}

.context-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.timeline {
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow: auto;
}

.timeline-item {
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface-soft);
  box-shadow: var(--shadow-neo);
}

.toast-stack {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 8px;
  z-index: 9999;
}

.toast {
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  min-width: 220px;
  max-width: 360px;
  animation: toast-in 0.2s ease;
}

.toast.error {
  border-color: var(--accent);
  color: var(--text);
}

.crm-modal {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: grid;
  place-items: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.crm-modal.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.crm-modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.crm-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.crm-modal.is-open .crm-modal-backdrop {
  opacity: 1;
}

.crm-modal-card {
  position: relative;
  width: min(1100px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 2.5px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  padding: 14px;
  box-shadow: var(--shadow-neo);
  transform: translateY(10px) scale(0.985);
  opacity: 0.6;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.crm-modal.is-open .crm-modal-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.crm-modal-close {
  position: sticky;
  top: 0;
  float: right;
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 999px;
  line-height: 1;
  font-size: 22px;
  padding: 0;
}

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

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0s !important;
    transition-duration: 0s !important;
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 2px solid var(--line);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
}

.status {
  display: inline-block;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  padding: 2px 8px;
  font-size: 12px;
}

.status.open {
  color: var(--accent);
  background: rgba(240, 66, 51, 0.08);
}

.status.in_progress {
  color: #fff;
  background: rgba(240, 66, 51, 0.3);
}

.status.waiting {
  color: var(--accent);
  background: rgba(240, 66, 51, 0.12);
  border-style: dashed;
}

.status.closed,
.status.done {
  color: #fff;
  background: var(--accent);
}

@media (max-width: 1180px) {
  .metrics {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

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

  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form {
    width: 100%;
  }

  .thread-split {
    grid-template-columns: 1fr;
  }

  .inline-form input,
  .inline-form select,
  .inline-form button {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .crm-guide-panel {
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: 8px !important;
    width: auto !important;
  }

  .crm-guide-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .crm-guide-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .crm-guide-btn {
    width: 100%;
    justify-content: center;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .main-shell {
    padding: 12px;
  }

  th,
  td {
    font-size: 12px;
    white-space: nowrap;
  }
}
