:root {
  --header: #5a3f86;
  --header-dark: #493170;
  --line: #d9dee8;
  --soft-line: #edf0f5;
  --text: #172033;
  --muted: #5f6877;
  --surface: #ffffff;
  --surface-alt: #f6f7f9;
  --yellow: #ffe49a;
  --yellow-text: #614600;
  --red: #ffc2bd;
  --red-text: #8a1008;
  --green: #ccebd2;
  --green-text: #155f29;
  --blue: #cbdcfb;
  --blue-text: #173f87;
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #eef1f5;
  color: var(--text);
}

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

.app {
  min-height: 100vh;
  padding: 20px;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-screen[hidden],
.app[hidden] {
  display: none;
}

.login-card {
  display: grid;
  width: min(380px, 100%);
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 22px;
  box-shadow: 0 16px 45px rgba(16, 24, 40, 0.16);
}

.login-card h1 {
  font-size: 24px;
}

.form-error {
  border-radius: 6px;
  background: #fff0f0;
  color: var(--red-text);
  padding: 9px 10px;
  font-size: 13px;
}

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

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

.current-user {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

h1,
h2,
p {
  margin: 0;
}

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

.topbar p {
  color: var(--muted);
  margin-top: 6px;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 0;
  cursor: pointer;
}

.primary-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--header);
  color: #ffffff;
  font-weight: 700;
}

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

.ghost-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 12px;
  background: #e7eaf0;
  color: #20293a;
}

.icon-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #edf0f5;
  color: #384155;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 190px;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

legend {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

.table-shell {
  position: relative;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  max-height: calc(100vh - 150px);
}

table {
  width: 100%;
  min-width: 1220px;
  border-collapse: collapse;
  table-layout: fixed;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

th {
  background: var(--header);
  color: #ffffff;
  font-size: 13px;
  line-height: 1.15;
  text-align: left;
  padding: 10px 8px;
  height: 54px;
  border-right: 1px solid rgba(255, 255, 255, 0.18);
}

td {
  min-height: 33px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--soft-line);
  font-size: 13px;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody tr:nth-child(odd) {
  background: var(--surface-alt);
}

tbody tr.row-overdue {
  background: #fff0f0;
}

tbody tr.row-today {
  background: #fff8df;
}

tbody tr.row-overdue:nth-child(odd) {
  background: #ffe8e8;
}

tbody tr.row-today:nth-child(odd) {
  background: #fff3ca;
}

tbody tr:hover {
  background: #eaf2ff;
}

th:nth-child(1),
td:nth-child(1) {
  width: 76px;
}

th:nth-child(2),
td:nth-child(2),
th:nth-child(7),
td:nth-child(7) {
  width: 92px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 180px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 130px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 132px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 176px;
}

th:nth-child(8),
td:nth-child(8) {
  width: 380px;
  white-space: normal;
}

th:nth-child(9),
td:nth-child(9) {
  width: 250px;
}

th:nth-child(10),
td:nth-child(10) {
  width: 72px;
}

.pill,
.select-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 19px;
  border-radius: 999px;
  padding: 2px 24px 2px 9px;
  background: #e5e8ed;
  color: #263143;
  line-height: 1.1;
  position: relative;
}

.select-pill::after {
  content: "";
  position: absolute;
  right: 9px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transform: translateY(-30%);
}

.assignee-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.assignee-pill {
  display: inline-flex;
  align-items: center;
  min-height: 19px;
  border-radius: 999px;
  padding: 2px 9px;
  background: #e5e8ed;
  color: #263143;
  line-height: 1.1;
}

.status-work {
  background: var(--yellow);
  color: var(--yellow-text);
}

.status-wait {
  background: var(--blue);
  color: var(--blue-text);
}

.status-won {
  background: var(--green);
  color: var(--green-text);
}

.status-lost {
  background: var(--red);
  color: var(--red-text);
}

.next-action-overdue,
.next-action-today {
  font-weight: 700;
}

.next-action-overdue {
  color: var(--red-text);
}

.next-action-today {
  color: var(--yellow-text);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.small-button {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #ffffff;
  color: #263143;
  min-width: 28px;
  height: 26px;
  cursor: pointer;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
}

dialog {
  width: min(1040px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 0;
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(16, 24, 40, 0.28);
}

dialog::backdrop {
  background: rgba(18, 25, 38, 0.42);
}

#task-form {
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 22px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header {
  margin-bottom: 18px;
}

.dialog-header h2 {
  font-size: 20px;
}

.dialog-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.task-identity-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f8fb;
  padding: 14px;
}

.task-identity-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.5fr) minmax(210px, 1fr) 170px;
  gap: 12px;
}

.identity-hint {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.task-identity-card input[readonly] {
  border-color: transparent;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  padding-left: 0;
  cursor: default;
}

.task-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

.task-primary-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

.next-action-card,
.task-settings-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  padding: 16px;
}

.next-action-card {
  border-top: 4px solid var(--header);
  box-shadow: 0 8px 24px rgba(49, 36, 77, 0.07);
}

.task-settings-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  background: #f9fafc;
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading h3 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
}

.section-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.next-action-date-field {
  max-width: 270px;
  margin-bottom: 14px;
  color: var(--header-dark);
  font-weight: 700;
}

.next-action-date-field input {
  min-height: 48px;
  border: 2px solid #9278b7;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 700;
}

.next-action-card textarea {
  min-height: 104px;
  line-height: 1.4;
}

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

.assignee-field {
  align-self: start;
}

.assignee-options {
  display: grid;
  max-height: 168px;
  gap: 4px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 7px 9px;
}

.assignee-option {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  color: var(--text);
}

.assignee-option input {
  width: auto;
  margin: 0;
}

.assignee-option.is-inactive {
  color: var(--muted);
}

.assignee-field small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.work-log-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f9fafc;
  padding: 14px;
}

.work-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.work-log-header h3 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
}

.work-log-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.work-log-header span,
.work-log-empty {
  color: var(--muted);
  font-size: 13px;
}

.work-log-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.work-log-item {
  border-left: 3px solid var(--header);
  border-radius: 4px;
  background: #ffffff;
  padding: 9px 10px;
}

.work-log-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.work-log-legacy {
  border-radius: 999px;
  background: #edf0f5;
  color: #384155;
  padding: 1px 7px;
}

.work-log-item p {
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.work-log-empty[hidden] {
  display: none;
}

.dialog-actions {
  position: sticky;
  bottom: -22px;
  justify-content: flex-end;
  margin: 18px -22px -22px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  padding: 14px 22px;
  backdrop-filter: blur(6px);
}

.users-dialog-content {
  width: min(760px, calc(100vw - 40px));
  padding: 18px;
}

.user-create-form {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr auto;
  align-items: end;
  gap: 12px;
  margin: 18px 0;
}

.user-create-form .primary-button {
  min-height: 38px;
}

.users-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.user-list-item {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.user-identity {
  display: grid;
  gap: 3px;
}

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

.user-status {
  min-width: 78px;
  font-size: 13px;
  font-weight: 600;
}

.user-status.is-active {
  color: #087443;
}

.user-status.is-inactive {
  color: var(--red-text);
}

@media (max-width: 760px) {
  .app {
    padding: 12px;
  }

  .topbar,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .task-identity-grid,
  .task-workspace {
    grid-template-columns: 1fr;
  }

  #task-form {
    padding: 16px;
  }

  .dialog-actions {
    bottom: -16px;
    margin: 16px -16px -16px;
    padding: 12px 16px;
  }

  .next-action-date-field {
    max-width: none;
  }

  .user-create-form,
  .user-list-item {
    grid-template-columns: 1fr;
  }
}
