:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-soft: #eef4f7;
  --text: #1f2933;
  --muted: #687682;
  --line: #d9e2e8;
  --accent: #0b83c9;
  --accent-dark: #086aa3;
  --danger: #c7383f;
  --shadow: 0 16px 40px rgba(31, 41, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

.topbar p,
.subsection p,
.template-form header p,
.empty-state p,
.selected-template p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
}

.templates-panel,
.create-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 560px;
}

.templates-panel {
  padding: 16px;
}

.create-panel {
  padding: 24px;
}

.panel-title,
.subsection-head,
.template-form header,
.dialog-actions,
.avatar-row,
.selected-template {
  display: flex;
  align-items: center;
  gap: 14px;
}

.panel-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-title h2,
.create-panel h2,
.template-form h2 {
  font-size: 20px;
}

.panel-title span {
  min-width: 30px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-soft);
  border-radius: 6px;
}

.templates-list {
  display: grid;
  gap: 10px;
}

.template-card {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.template-card:hover,
.template-card.active {
  border-color: var(--accent);
}

.template-card strong {
  display: block;
  font-size: 15px;
  margin-bottom: 6px;
}

.template-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

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

.card-actions button {
  min-height: 30px;
  padding: 0 10px;
}

.empty-state {
  min-height: 500px;
  display: grid;
  place-content: center;
  text-align: center;
}

.project-form {
  display: grid;
  gap: 22px;
}

.selected-template {
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.selected-template span {
  color: var(--muted);
  font-size: 13px;
}

.avatar-preview {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: linear-gradient(135deg, #0b83c9, #31b57f);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--line);
}

.avatar-preview.large {
  width: 74px;
  height: 74px;
}

.avatar-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.avatar-preset {
  width: 58px;
  height: 58px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #f7fbfd;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 9px;
}

.avatar-preset.active {
  border-color: var(--accent);
}

.avatar-preset img {
  max-width: 100%;
  max-height: 100%;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(11, 131, 201, 0.2);
  border-color: var(--accent);
}

.primary-button,
.secondary-button,
.icon-button,
.file-picker {
  border: 0;
  border-radius: 6px;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
}

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

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

.secondary-button,
.file-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
}

.secondary-button:hover,
.file-picker:hover {
  border-color: var(--accent);
}

.secondary-button.danger {
  color: var(--danger);
}

.icon-button {
  width: 38px;
  padding: 0;
  margin-left: auto;
  font-size: 26px;
  line-height: 1;
  background: var(--surface-soft);
}

.wide {
  width: 100%;
}

.kanban-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.kanban-stage {
  min-height: 88px;
  border: 1px solid var(--line);
  border-top: 6px solid var(--accent);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.kanban-stage strong {
  display: block;
  word-break: break-word;
}

.kanban-stage span {
  color: var(--muted);
  font-size: 12px;
}

.template-dialog {
  width: min(920px, calc(100% - 24px));
  max-height: calc(100vh - 32px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.template-dialog::backdrop {
  background: rgba(24, 35, 45, 0.45);
}

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

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

.subsection {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.subsection-head {
  justify-content: space-between;
  align-items: flex-start;
}

.subsection h3 {
  font-size: 16px;
}

.manual-users {
  display: grid;
}

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

.role-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.role-head strong {
  font-size: 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 26px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 0 9px;
  font-size: 13px;
}

.chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 18px;
}

.file-picker input {
  display: none;
}

.stages-editor {
  display: grid;
  gap: 10px;
}

.tasks-editor {
  display: grid;
  gap: 12px;
}

.task-row {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.task-row-head {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 10px;
  align-items: end;
}

.task-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 120px 120px;
  gap: 10px;
}

.task-fields textarea,
.checklist-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  resize: vertical;
}

.task-checklist {
  display: grid;
  gap: 8px;
}

.checklist-row {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 8px;
}

.stage-row {
  display: grid;
  grid-template-columns: 1fr 100px 76px 40px;
  gap: 10px;
  align-items: end;
}

.stage-row input[type="color"] {
  padding: 4px;
}

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

.spacer {
  flex: 1;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #1f2933;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .topbar,
  .workspace,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .workspace {
    display: grid;
  }

  .templates-panel,
  .create-panel {
    min-height: auto;
  }

  .stage-row {
    grid-template-columns: 1fr 74px 64px 38px;
  }

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

  .task-fields {
    grid-template-columns: 1fr;
  }
}
